From af961e945ed0c20eebd6df50be9461ae97b404ff Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 2 Jul 2015 11:50:35 -0400 Subject: [PATCH] Implemented uiOpenFile() and uiSaveFile() on GTK+. --- redo/unix/stddialogs.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/redo/unix/stddialogs.c b/redo/unix/stddialogs.c index 25f48b97..99d4fa35 100644 --- a/redo/unix/stddialogs.c +++ b/redo/unix/stddialogs.c @@ -1,14 +1,41 @@ // 26 june 2015 #include "uipriv_unix.h" +static char *filedialog(GtkFileChooserAction mode, const gchar *stock) +{ + GtkWidget *fcd; + GtkFileChooser *fc; + gint response; + char *filename; + + fcd = gtk_file_chooser_dialog_new(NULL, NULL, mode, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + stock, GTK_RESPONSE_ACCEPT, + 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; +} + char *uiOpenFile(void) { - return NULL; + return filedialog(GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_OPEN); } char *uiSaveFile(void) { - return NULL; + return filedialog(GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_SAVE); } void uiMsgBox(const char *title, const char *description)