diff options
author | Søren Sandmann Pedersen <sandmann@redhat.com> | 2008-06-24 13:58:21 -0400 |
---|---|---|
committer | Søren Sandmann Pedersen <sandmann@redhat.com> | 2008-06-24 13:58:21 -0400 |
commit | d41b015061d2119b17af4323cabacf67fc36d070 (patch) | |
tree | a3c01c2f147edf05a5cd6e04eb9083c7cea06223 | |
parent | 5e097eb4c24e6337f9efcc591c44682b5150deb2 (diff) |
Cache the file chooser dialog
-rw-r--r-- | siv.c | 21 | ||||
-rw-r--r-- | siv.h | 1 | ||||
-rw-r--r-- | window.c | 28 |
3 files changed, 32 insertions, 18 deletions
@@ -10,7 +10,9 @@ struct App { - int n_windows; + int n_windows; + + GtkWidget * chooser; }; void @@ -93,6 +95,23 @@ app_unregister_window (App *app, SivWindow *window) gtk_main_quit (); } +GtkWidget * +app_get_open_chooser (App *app) +{ + if (!app->chooser) + { + app->chooser = + gtk_file_chooser_dialog_new ("Open", + NULL, + GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, + NULL); + } + + return app->chooser; +} + static gchar * encode (const char *filename) { @@ -53,6 +53,7 @@ void app_set_meta_data (App *data, int zoom_level, int vadj, int hadj); +GtkWidget *app_get_open_chooser (App *app); /* Doesn't really belong in the app namespace */ void app_show_warning (GtkWidget *parent_window, @@ -729,9 +729,8 @@ set_busy (GtkWidget *widget, } static void -add_image_filters (GtkWidget *dialog) +add_image_filters (GtkFileChooser *chooser) { - GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog); GtkFileFilter *filter; filter = gtk_file_filter_new (); @@ -750,30 +749,25 @@ on_open (GtkWidget *widget, gpointer data) { SivWindow *window = data; gchar *filename = NULL; - GtkWidget *dialog; + GtkFileChooser *chooser; set_busy (get_widget (window, "main_window"), TRUE); - dialog = gtk_file_chooser_dialog_new ("Open", - get_widget (window, "main_window"), - GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, - NULL); - - add_image_filters (dialog); + chooser = GTK_FILE_CHOOSER (app_get_open_chooser (window->app)); + gtk_window_set_transient_for (GTK_WINDOW (chooser), + get_widget (window, "main_window")); + gtk_window_set_modal (GTK_WINDOW (chooser), TRUE); - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); + add_image_filters (chooser); set_busy (get_widget (window, "main_window"), FALSE); retry: - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + if (gtk_dialog_run (GTK_DIALOG (chooser)) == GTK_RESPONSE_ACCEPT) { GError *err = NULL; SivWindow *target; gboolean success; - GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog); if (window->original) target = window_new (window->app); @@ -796,11 +790,11 @@ retry: filename = tmp; } - set_busy (dialog, TRUE); + set_busy (GTK_WIDGET (chooser), TRUE); success = window_load_file (target, filename, &err); - set_busy (dialog, FALSE); + set_busy (GTK_WIDGET (chooser), FALSE); if (success) { @@ -824,7 +818,7 @@ retry: goto retry; } - gtk_widget_destroy (dialog); + gtk_widget_hide (GTK_WIDGET (chooser)); } static void |