gimp r27135 - in trunk: . app/actions app/dialogs app/widgets



Author: mitch
Date: Sun Oct  5 15:21:02 2008
New Revision: 27135
URL: http://svn.gnome.org/viewvc/gimp?rev=27135&view=rev

Log:
2008-10-05  Michael Natterer  <mitch gimp org>

	Allow to "Open as Layers" in the empty display:

	* app/widgets/gimpfiledialog.[ch]: add member
	"gboolean open_as_layers". Rename gimp_file_dialog_set_image() to
	gimp_file_dialog_set_save_image() and add
	gimp_file_dialog_set_open_image() which sets both the image to
	load layers into and the "open_as_layers" boolean.

	* app/dialogs/file-open-dialog.c (file_open_dialog_response): look
	at dialog->open_as_layers instead of dialog->image to decide whether
	to open as layers (that's much more obvious). Enable open as layers
	without existing image by creating the image if it doesn't exist.

	* app/actions/file-commands.c (file_open_dialog_show): add "title"
	parameter and take the uri from the image if none was passed. Use the
	new gimp_file_dialog_set_open_image() instead of poking into the
	dialog struct. Change callers to pass the title and not get the
	uri from the image; instead always pass the image.

	* app/actions/file-actions.c (file_actions_update): keep
	"Open as Layers" sensitive even without image.



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

Modified: trunk/app/actions/file-actions.c
==============================================================================
--- trunk/app/actions/file-actions.c	(original)
+++ trunk/app/actions/file-actions.c	Sun Oct  5 15:21:02 2008
@@ -235,7 +235,6 @@
 #define SET_SENSITIVE(action,condition) \
         gimp_action_group_set_action_sensitive (group, action, (condition) != 0)
 
-  SET_SENSITIVE ("file-open-as-layers",   image);
   SET_SENSITIVE ("file-save",             image && drawable);
   SET_SENSITIVE ("file-save-as",          image && drawable);
   SET_SENSITIVE ("file-save-a-copy",      image && drawable);

Modified: trunk/app/actions/file-commands.c
==============================================================================
--- trunk/app/actions/file-commands.c	(original)
+++ trunk/app/actions/file-commands.c	Sun Oct  5 15:21:02 2008
@@ -64,8 +64,9 @@
 
 /*  local function prototypes  */
 
-static void   file_open_dialog_show        (GtkWidget   *parent,
-                                            Gimp        *gimp,
+static void   file_open_dialog_show        (Gimp        *gimp,
+                                            GtkWidget   *parent,
+                                            const gchar *title,
                                             GimpImage   *image,
                                             const gchar *uri,
                                             gboolean     open_as_layers);
@@ -92,18 +93,16 @@
                         gpointer   data)
 {
   Gimp        *gimp;
-  GimpImage   *image;
   GtkWidget   *widget;
-  const gchar *uri = NULL;
+  GimpImage   *image;
   return_if_no_gimp (gimp, data);
   return_if_no_widget (widget, data);
 
   image = action_data_get_image (data);
 
-  if (image)
-    uri = gimp_object_get_name (GIMP_OBJECT (image));
-
-  file_open_dialog_show (widget, gimp, NULL, uri, FALSE);
+  file_open_dialog_show (gimp, widget,
+                         _("Open Image"),
+                         image, NULL, FALSE);
 }
 
 void
@@ -111,18 +110,20 @@
                                   gpointer   data)
 {
   Gimp        *gimp;
-  GimpDisplay *display;
   GtkWidget   *widget;
-  GimpImage   *image;
-  const gchar *uri;
+  GimpDisplay *display;
+  GimpImage   *image = NULL;
   return_if_no_gimp (gimp, data);
-  return_if_no_display (display, data);
   return_if_no_widget (widget, data);
 
-  image = display->image;
-  uri = gimp_object_get_name (GIMP_OBJECT (image));
+  display = action_data_get_display (data);
+
+  if (display)
+    image = display->image;
 
-  file_open_dialog_show (widget, gimp, image, uri, TRUE);
+  file_open_dialog_show (gimp, widget,
+                         _("Open Image as Layers"),
+                         image, NULL, TRUE);
 }
 
 void
@@ -445,15 +446,18 @@
                        const gchar *uri,
                        GtkWidget   *parent)
 {
-  file_open_dialog_show (parent, gimp, NULL, uri, FALSE);
+  file_open_dialog_show (gimp, parent,
+                         _("Open Image"),
+                         NULL, uri, FALSE);
 }
 
 
 /*  private functions  */
 
 static void
-file_open_dialog_show (GtkWidget   *parent,
-                       Gimp        *gimp,
+file_open_dialog_show (Gimp        *gimp,
+                       GtkWidget   *parent,
+                       const gchar *title,
                        GimpImage   *image,
                        const gchar *uri,
                        gboolean     open_as_layers)
@@ -466,27 +470,23 @@
 
   if (dialog)
     {
+      if (! uri && image)
+        uri = gimp_object_get_name (GIMP_OBJECT (image));
+
       if (! uri)
         uri = g_object_get_data (G_OBJECT (gimp), "gimp-file-open-last-uri");
 
       if (uri)
         gtk_file_chooser_set_uri (GTK_FILE_CHOOSER (dialog), uri);
 
-      if (open_as_layers)
-        {
-          gtk_window_set_title (GTK_WINDOW (dialog), _("Open Image as Layers"));
-          GIMP_FILE_DIALOG (dialog)->image = image;
-        }
-      else
-        {
-          gtk_window_set_title (GTK_WINDOW (dialog), _("Open Image"));
-          GIMP_FILE_DIALOG (dialog)->image = NULL;
-        }
+      gimp_file_dialog_set_open_image (GIMP_FILE_DIALOG (dialog),
+                                       image, open_as_layers);
 
       parent = gtk_widget_get_toplevel (parent);
 
       if (GTK_IS_WINDOW (parent))
-        gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (parent));
+        gtk_window_set_transient_for (GTK_WINDOW (dialog),
+                                      GTK_WINDOW (parent));
 
       gtk_window_present (GTK_WINDOW (dialog));
     }
@@ -528,8 +528,8 @@
     {
       gtk_window_set_title (GTK_WINDOW (dialog), title);
 
-      gimp_file_dialog_set_image (GIMP_FILE_DIALOG (dialog),
-                                  image, save_a_copy, close_after_saving);
+      gimp_file_dialog_set_save_image (GIMP_FILE_DIALOG (dialog),
+                                       image, save_a_copy, close_after_saving);
 
       gtk_window_present (GTK_WINDOW (dialog));
     }

Modified: trunk/app/dialogs/file-open-dialog.c
==============================================================================
--- trunk/app/dialogs/file-open-dialog.c	(original)
+++ trunk/app/dialogs/file-open-dialog.c	Sun Oct  5 15:21:02 2008
@@ -49,7 +49,7 @@
 static void       file_open_dialog_response    (GtkWidget           *open_dialog,
                                                 gint                 response_id,
                                                 Gimp                *gimp);
-static gboolean   file_open_dialog_open_image  (GtkWidget           *open_dialog,
+static GimpImage *file_open_dialog_open_image  (GtkWidget           *open_dialog,
                                                 Gimp                *gimp,
                                                 const gchar         *uri,
                                                 const gchar         *entered_filename,
@@ -138,13 +138,24 @@
             continue;
         }
 
-      if (dialog->image)
+      if (dialog->open_as_layers)
         {
-          if (file_open_dialog_open_layers (open_dialog,
-                                            dialog->image,
-                                            list->data,
-                                            list->data,
-                                            dialog->file_proc))
+          if (! dialog->image)
+            {
+              dialog->image = file_open_dialog_open_image (open_dialog,
+                                                           gimp,
+                                                           list->data,
+                                                           list->data,
+                                                           dialog->file_proc);
+
+              if (dialog->image)
+                success = TRUE;
+            }
+          else if (file_open_dialog_open_layers (open_dialog,
+                                                 dialog->image,
+                                                 list->data,
+                                                 list->data,
+                                                 dialog->file_proc))
             {
               success = TRUE;
             }
@@ -169,7 +180,7 @@
 
   if (success)
     {
-      if (dialog->image)
+      if (dialog->open_as_layers && dialog->image)
         gimp_image_flush (dialog->image);
 
       gtk_widget_destroy (open_dialog);
@@ -183,7 +194,7 @@
   g_slist_free (uris);
 }
 
-static gboolean
+static GimpImage *
 file_open_dialog_open_image (GtkWidget           *open_dialog,
                              Gimp                *gimp,
                              const gchar         *uri,
@@ -201,11 +212,7 @@
                                            load_proc,
                                            &status, &error);
 
-  if (image)
-    {
-      return TRUE;
-    }
-  else if (status != GIMP_PDB_CANCEL)
+  if (! image && status != GIMP_PDB_CANCEL)
     {
       gchar *filename = file_utils_uri_display_name (uri);
 
@@ -216,7 +223,7 @@
       g_free (filename);
     }
 
-  return FALSE;
+  return image;
 }
 
 static gboolean
@@ -247,8 +254,6 @@
 
       g_list_free (new_layers);
 
-      gimp_image_flush (image);
-
       return TRUE;
     }
   else if (status != GIMP_PDB_CANCEL)

Modified: trunk/app/widgets/gimpfiledialog.c
==============================================================================
--- trunk/app/widgets/gimpfiledialog.c	(original)
+++ trunk/app/widgets/gimpfiledialog.c	Sun Oct  5 15:21:02 2008
@@ -403,10 +403,22 @@
 }
 
 void
-gimp_file_dialog_set_image (GimpFileDialog *dialog,
-                            GimpImage      *image,
-                            gboolean        save_a_copy,
-                            gboolean        close_after_saving)
+gimp_file_dialog_set_open_image (GimpFileDialog *dialog,
+                                 GimpImage      *image,
+                                 gboolean        open_as_layers)
+{
+  g_return_if_fail (GIMP_IS_FILE_DIALOG (dialog));
+  g_return_if_fail (image == NULL || GIMP_IS_IMAGE (image));
+
+  dialog->image          = image;
+  dialog->open_as_layers = open_as_layers;
+}
+
+void
+gimp_file_dialog_set_save_image (GimpFileDialog *dialog,
+                                 GimpImage      *image,
+                                 gboolean        save_a_copy,
+                                 gboolean        close_after_saving)
 {
   const gchar *uri = NULL;
   gchar       *dirname;

Modified: trunk/app/widgets/gimpfiledialog.h
==============================================================================
--- trunk/app/widgets/gimpfiledialog.h	(original)
+++ trunk/app/widgets/gimpfiledialog.h	Sun Oct  5 15:21:02 2008
@@ -42,6 +42,7 @@
   GimpPlugInProcedure  *file_proc;
 
   GimpImage            *image;
+  gboolean              open_as_layers;
   gboolean              save_a_copy;
   gboolean              close_after_saving;
 
@@ -63,25 +64,28 @@
 typedef struct _GimpFileDialogState GimpFileDialogState;
 
 
-GType       gimp_file_dialog_get_type      (void) G_GNUC_CONST;
+GType       gimp_file_dialog_get_type       (void) G_GNUC_CONST;
 
-GtkWidget * gimp_file_dialog_new           (Gimp                 *gimp,
-                                            GtkFileChooserAction  action,
-                                            const gchar          *title,
-                                            const gchar          *role,
-                                            const gchar          *stock_id,
-                                            const gchar          *help_id);
-
-void        gimp_file_dialog_set_sensitive (GimpFileDialog       *dialog,
-                                            gboolean              sensitive);
-
-void        gimp_file_dialog_set_file_proc (GimpFileDialog       *dialog,
-                                            GimpPlugInProcedure  *file_proc);
-
-void        gimp_file_dialog_set_image     (GimpFileDialog       *dialog,
-                                            GimpImage            *image,
-                                            gboolean              save_a_copy,
-                                            gboolean              close_after_saving);
+GtkWidget * gimp_file_dialog_new            (Gimp                 *gimp,
+                                             GtkFileChooserAction  action,
+                                             const gchar          *title,
+                                             const gchar          *role,
+                                             const gchar          *stock_id,
+                                             const gchar          *help_id);
+
+void        gimp_file_dialog_set_sensitive  (GimpFileDialog       *dialog,
+                                             gboolean              sensitive);
+
+void        gimp_file_dialog_set_file_proc  (GimpFileDialog       *dialog,
+                                             GimpPlugInProcedure  *file_proc);
+
+void        gimp_file_dialog_set_open_image (GimpFileDialog       *dialog,
+                                             GimpImage            *image,
+                                             gboolean              open_as_layers);
+void        gimp_file_dialog_set_save_image (GimpFileDialog       *dialog,
+                                             GimpImage            *image,
+                                             gboolean              save_a_copy,
+                                             gboolean              close_after_saving);
 
 GimpFileDialogState * gimp_file_dialog_get_state     (GimpFileDialog      *dialog);
 void                  gimp_file_dialog_set_state     (GimpFileDialog      *dialog,



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