2015-06-26 17:45:00 -05:00
|
|
|
// 26 june 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2016-05-28 20:17:54 -05:00
|
|
|
// LONGTERM figure out why, and describe, that this is the desired behavior
|
|
|
|
// LONGTERM also point out that font and color buttons also work like this
|
2015-11-28 10:02:58 -06:00
|
|
|
|
|
|
|
#define windowWindow(w) (GTK_WINDOW(uiControlHandle(uiControl(w))))
|
|
|
|
|
2016-05-28 12:06:16 -05:00
|
|
|
static char *filedialog(GtkWindow *parent, GtkFileChooserAction mode, const gchar *confirm)
|
2015-07-02 10:50:35 -05:00
|
|
|
{
|
|
|
|
GtkWidget *fcd;
|
|
|
|
GtkFileChooser *fc;
|
|
|
|
gint response;
|
|
|
|
char *filename;
|
|
|
|
|
2015-11-28 10:02:58 -06:00
|
|
|
fcd = gtk_file_chooser_dialog_new(NULL, parent, mode,
|
2016-05-28 12:06:16 -05:00
|
|
|
"_Cancel", GTK_RESPONSE_CANCEL,
|
|
|
|
confirm, GTK_RESPONSE_ACCEPT,
|
2015-07-02 10:50:35 -05:00
|
|
|
NULL);
|
|
|
|
fc = GTK_FILE_CHOOSER(fcd);
|
|
|
|
gtk_file_chooser_set_local_only(fc, FALSE);
|
|
|
|
gtk_file_chooser_set_select_multiple(fc, FALSE);
|
|
|
|
gtk_file_chooser_set_show_hidden(fc, TRUE);
|
|
|
|
gtk_file_chooser_set_do_overwrite_confirmation(fc, TRUE);
|
|
|
|
gtk_file_chooser_set_create_folders(fc, TRUE);
|
|
|
|
response = gtk_dialog_run(GTK_DIALOG(fcd));
|
|
|
|
if (response != GTK_RESPONSE_ACCEPT) {
|
|
|
|
gtk_widget_destroy(fcd);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
filename = uiUnixStrdupText(gtk_file_chooser_get_filename(fc));
|
|
|
|
gtk_widget_destroy(fcd);
|
|
|
|
return filename;
|
|
|
|
}
|
|
|
|
|
2015-11-28 10:02:58 -06:00
|
|
|
char *uiOpenFile(uiWindow *parent)
|
2015-06-26 17:45:00 -05:00
|
|
|
{
|
2016-05-28 12:06:16 -05:00
|
|
|
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_OPEN, "_Open");
|
2015-06-26 17:45:00 -05:00
|
|
|
}
|
|
|
|
|
2015-11-28 10:02:58 -06:00
|
|
|
char *uiSaveFile(uiWindow *parent)
|
2015-06-26 17:45:00 -05:00
|
|
|
{
|
2016-05-28 12:06:16 -05:00
|
|
|
return filedialog(windowWindow(parent), GTK_FILE_CHOOSER_ACTION_SAVE, "_Save");
|
2015-06-26 17:45:00 -05:00
|
|
|
}
|
|
|
|
|
2015-11-28 10:02:58 -06:00
|
|
|
static void msgbox(GtkWindow *parent, const char *title, const char *description, GtkMessageType type, GtkButtonsType buttons)
|
2015-07-02 11:57:37 -05:00
|
|
|
{
|
|
|
|
GtkWidget *md;
|
|
|
|
|
2015-11-28 10:02:58 -06:00
|
|
|
md = gtk_message_dialog_new(parent, GTK_DIALOG_MODAL,
|
2015-07-02 11:57:37 -05:00
|
|
|
type, buttons,
|
|
|
|
"%s", title);
|
|
|
|
gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(md), "%s", description);
|
|
|
|
gtk_dialog_run(GTK_DIALOG(md));
|
|
|
|
gtk_widget_destroy(md);
|
|
|
|
}
|
|
|
|
|
2015-11-28 10:02:58 -06:00
|
|
|
void uiMsgBox(uiWindow *parent, const char *title, const char *description)
|
2015-06-26 17:45:00 -05:00
|
|
|
{
|
2015-11-28 10:02:58 -06:00
|
|
|
msgbox(windowWindow(parent), title, description, GTK_MESSAGE_OTHER, GTK_BUTTONS_OK);
|
2015-06-26 17:45:00 -05:00
|
|
|
}
|
|
|
|
|
2015-11-28 10:02:58 -06:00
|
|
|
void uiMsgBoxError(uiWindow *parent, const char *title, const char *description)
|
2015-06-26 17:45:00 -05:00
|
|
|
{
|
2015-11-28 10:02:58 -06:00
|
|
|
msgbox(windowWindow(parent), title, description, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK);
|
2015-06-26 17:45:00 -05:00
|
|
|
}
|