summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann Pedersen <sandmann@redhat.com>2008-06-24 13:58:21 -0400
committerSøren Sandmann Pedersen <sandmann@redhat.com>2008-06-24 13:58:21 -0400
commitd41b015061d2119b17af4323cabacf67fc36d070 (patch)
treea3c01c2f147edf05a5cd6e04eb9083c7cea06223
parent5e097eb4c24e6337f9efcc591c44682b5150deb2 (diff)
Cache the file chooser dialog
-rw-r--r--siv.c21
-rw-r--r--siv.h1
-rw-r--r--window.c28
3 files changed, 32 insertions, 18 deletions
diff --git a/siv.c b/siv.c
index 7820ca3..e992732 100644
--- a/siv.c
+++ b/siv.c
@@ -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)
{
diff --git a/siv.h b/siv.h
index 6c5905a..0ec92c6 100644
--- a/siv.h
+++ b/siv.h
@@ -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,
diff --git a/window.c b/window.c
index 43e15d0..60f1b0d 100644
--- a/window.c
+++ b/window.c
@@ -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