diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-11-18 11:20:52 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-11-18 11:21:21 +0100 |
commit | d7a25ad89452f1b2f80ec3b707061307dda0b1be (patch) | |
tree | cf4ea9b6bed7d38200f7debf07b08308996780bc | |
parent | 0433c1a027181028c1bd21a9370497a76e1fedb2 (diff) | |
download | fiv-d7a25ad89452f1b2f80ec3b707061307dda0b1be.tar.gz fiv-d7a25ad89452f1b2f80ec3b707061307dda0b1be.tar.xz fiv-d7a25ad89452f1b2f80ec3b707061307dda0b1be.zip |
Make the Open dialog useful
In the meantime.
-rw-r--r-- | fastiv.c | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -187,8 +187,8 @@ open(const gchar *path) g_free(dirname); } -static void -on_open(void) +static GtkWidget * +create_open_dialog(void) { GtkWidget *dialog = gtk_file_chooser_dialog_new("Open file", GTK_WINDOW(g.window), GTK_FILE_CHOOSER_ACTION_OPEN, @@ -208,15 +208,34 @@ on_open(void) gtk_file_filter_set_name(all_files, "All files"); gtk_file_filter_add_pattern(all_files, "*"); gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(dialog), all_files); + return dialog; +} + +static void +on_open(void) +{ + static GtkWidget *dialog; + if (!dialog) + dialog = create_open_dialog(); + + // Apparently, just keeping the dialog around doesn't mean + // that it will remember its last location. + gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), g.directory); // The default is local-only, single item. Paths are returned absolute. - if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { - gchar *path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + switch (gtk_dialog_run(GTK_DIALOG(dialog))) { + gchar *path; + case GTK_RESPONSE_ACCEPT: + path = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); open(path); g_free(path); + break; + case GTK_RESPONSE_NONE: + dialog = NULL; + return; } - gtk_widget_destroy(dialog); + gtk_widget_hide(dialog); } static void |