gimp r25586 - in trunk: . app/dialogs app/widgets



Author: neo
Date: Thu May  8 11:30:54 2008
New Revision: 25586
URL: http://svn.gnome.org/viewvc/gimp?rev=25586&view=rev

Log:
2008-05-08  Sven Neumann  <sven gimp org>

	* app/widgets/gimpfiledialog.[ch]: added infrastructure to 
access
	and set some state information of the GtkFileChooser.

	* app/dialogs/file-open-dialog.c
	* app/dialogs/file-save-dialog.c: don't keep the file-chooser
	dialogs around. Instead keep the state attached to the Gimp 
object
	(one state for load, one for save dialogs). Closes bug #528811.



Modified:
   trunk/ChangeLog
   trunk/app/dialogs/file-open-dialog.c
   trunk/app/dialogs/file-save-dialog.c
   trunk/app/widgets/gimpfiledialog.c
   trunk/app/widgets/gimpfiledialog.h

Modified: trunk/app/dialogs/file-open-dialog.c
==============================================================================
--- trunk/app/dialogs/file-open-dialog.c	(original)
+++ trunk/app/dialogs/file-open-dialog.c	Thu May  8 11:30:54 2008
@@ -66,7 +66,8 @@
 GtkWidget *
 file_open_dialog_new (Gimp *gimp)
 {
-  GtkWidget *dialog;
+  GtkWidget           *dialog;
+  GimpFileDialogState *state;
 
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
@@ -78,6 +79,11 @@
 
   gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), TRUE);
 
+  state = g_object_get_data (G_OBJECT (gimp), "gimp-file-open-dialog-state");
+
+  if (state)
+    gimp_file_dialog_set_state (GIMP_FILE_DIALOG (dialog), state);
+
   g_signal_connect (dialog, "response",
                     G_CALLBACK (file_open_dialog_response),
                     gimp);
@@ -98,10 +104,14 @@
   GSList         *list;
   gboolean        success = FALSE;
 
+  g_object_set_data_full (G_OBJECT (gimp), "gimp-file-open-dialog-state",
+                          gimp_file_dialog_get_state (dialog),
+                          (GDestroyNotify) gimp_file_dialog_state_destroy);
+
   if (response_id != GTK_RESPONSE_OK)
     {
       if (! dialog->busy)
-        gtk_widget_hide (open_dialog);
+        gtk_widget_destroy (open_dialog);
 
       return;
     }
@@ -155,13 +165,11 @@
 
   if (success)
     {
-      gtk_widget_hide (open_dialog);
-
       if (dialog->image)
         gimp_image_flush (dialog->image);
-    }
 
-  gimp_file_dialog_set_sensitive (dialog, TRUE);
+      gtk_widget_destroy (open_dialog);
+    }
 
   g_slist_foreach (uris, (GFunc) g_free, NULL);
   g_slist_free (uris);

Modified: trunk/app/dialogs/file-save-dialog.c
==============================================================================
--- trunk/app/dialogs/file-save-dialog.c	(original)
+++ trunk/app/dialogs/file-save-dialog.c	Thu May  8 11:30:54 2008
@@ -77,8 +77,9 @@
 GtkWidget *
 file_save_dialog_new (Gimp *gimp)
 {
-  GtkWidget   *dialog;
-  const gchar *uri;
+  GtkWidget           *dialog;
+  GimpFileDialogState *state;
+  const gchar         *uri;
 
   g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
 
@@ -88,6 +89,11 @@
                                  GTK_STOCK_SAVE,
                                  GIMP_HELP_FILE_SAVE);
 
+  state = g_object_get_data (G_OBJECT (gimp), "gimp-file-save-dialog-state");
+
+  if (state)
+    gimp_file_dialog_set_state (GIMP_FILE_DIALOG (dialog), state);
+
   uri = g_object_get_data (G_OBJECT (gimp), "gimp-file-save-last-uri");
 
   if (uri)
@@ -115,20 +121,20 @@
   gchar               *uri;
   gchar               *basename;
   GimpPlugInProcedure *save_proc;
-  gulong               handler_id;
+
+  g_object_set_data_full (G_OBJECT (gimp), "gimp-file-save-dialog-state",
+                          gimp_file_dialog_get_state (dialog),
+                          (GDestroyNotify) gimp_file_dialog_state_destroy);
 
   if (response_id != GTK_RESPONSE_OK)
     {
       if (! dialog->busy)
-        gtk_widget_hide (save_dialog);
+        gtk_widget_destroy (save_dialog);
 
       return;
     }
 
   gimp_file_dialog_set_sensitive (dialog, FALSE);
-  handler_id = g_signal_connect (dialog, "destroy",
-                                 G_CALLBACK (gtk_widget_destroyed),
-                                 &dialog);
 
   if (file_save_dialog_check_uri (save_dialog, gimp,
                                   &uri, &basename, &save_proc))
@@ -141,14 +147,14 @@
         {
           if (dialog)
             {
-              gtk_widget_hide (save_dialog);
+              GtkWindow *parent;
 
-              if (dialog->close_after_saving)
-                {
-                  GtkWindow *parent;
+              parent = gtk_window_get_transient_for (GTK_WINDOW (dialog));
 
-                  parent = gtk_window_get_transient_for (GTK_WINDOW (dialog));
+              gtk_widget_destroy (save_dialog);
 
+              if (dialog->close_after_saving)
+                {
                   if (GIMP_IS_DISPLAY_SHELL (parent))
                     {
                       GimpDisplay *display;
@@ -165,13 +171,6 @@
       g_free (uri);
       g_free (basename);
     }
-
-  /* dialog may have been destroyed while save plugin was running */
-  if (dialog)
-    {
-      gimp_file_dialog_set_sensitive (dialog, TRUE);
-      g_signal_handler_disconnect (dialog, handler_id);
-    }
 }
 
 static gboolean

Modified: trunk/app/widgets/gimpfiledialog.c
==============================================================================
--- trunk/app/widgets/gimpfiledialog.c	(original)
+++ trunk/app/widgets/gimpfiledialog.c	Thu May  8 11:30:54 2008
@@ -55,6 +55,12 @@
 #include "gimp-intl.h"
 
 
+struct _GimpFileDialogState
+{
+  gchar *filter_name;
+};
+
+
 static void     gimp_file_dialog_progress_iface_init (GimpProgressInterface *iface);
 static gboolean gimp_file_dialog_delete_event        (GtkWidget        *widget,
                                                       GdkEventAny      *event);
@@ -489,6 +495,63 @@
   g_free (basename);
 }
 
+GimpFileDialogState *
+gimp_file_dialog_get_state (GimpFileDialog *dialog)
+{
+  GimpFileDialogState *state;
+  GtkFileFilter       *filter;
+
+  g_return_val_if_fail (GIMP_IS_FILE_DIALOG (dialog), NULL);
+
+  state = g_slice_new0 (GimpFileDialogState);
+
+  filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog));
+
+  if (filter)
+    state->filter_name = g_strdup (gtk_file_filter_get_name (filter));
+
+  return state;
+}
+
+void
+gimp_file_dialog_set_state (GimpFileDialog      *dialog,
+                            GimpFileDialogState *state)
+{
+  g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
+  g_return_if_fail (state != NULL);
+
+  if (state->filter_name)
+    {
+      GSList *filters;
+      GSList *list;
+
+      filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (dialog));
+
+      for (list = filters; list; list = list->next)
+        {
+          GtkFileFilter *filter = GTK_FILE_FILTER (list->data);
+          const gchar   *name   = gtk_file_filter_get_name (filter);
+
+          if (name && strcmp (state->filter_name, name) == 0)
+            {
+              gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
+              break;
+            }
+        }
+
+      g_slist_free (filters);
+    }
+}
+
+void
+gimp_file_dialog_state_destroy (GimpFileDialogState *state)
+{
+  g_return_if_fail (state != NULL);
+
+  g_free (state->filter_name);
+  g_slice_free (GimpFileDialogState, state);
+}
+
 
 /*  private functions  */
 

Modified: trunk/app/widgets/gimpfiledialog.h
==============================================================================
--- trunk/app/widgets/gimpfiledialog.h	(original)
+++ trunk/app/widgets/gimpfiledialog.h	Thu May  8 11:30:54 2008
@@ -60,6 +60,9 @@
 };
 
 
+typedef struct _GimpFileDialogState GimpFileDialogState;
+
+
 GType       gimp_file_dialog_get_type      (void) G_GNUC_CONST;
 
 GtkWidget * gimp_file_dialog_new           (Gimp                 *gimp,
@@ -80,6 +83,12 @@
                                             gboolean              save_a_copy,
                                             gboolean              close_after_saving);
 
+GimpFileDialogState * gimp_file_dialog_get_state     (GimpFileDialog      *dialog);
+void                  gimp_file_dialog_set_state     (GimpFileDialog      *dialog,
+                                                      GimpFileDialogState *state);
+void                  gimp_file_dialog_state_destroy (GimpFileDialogState *state);
+
+
 G_END_DECLS
 
 #endif /* __GIMP_FILE_DIALOG_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]