[gimp: 2/27] app: When importing a file, setup image state properly



commit e8531ce9477f5e4959129b9beebcf8c4f471813a
Author: Martin Nordholts <martinn src gnome org>
Date:   Thu Apr 23 20:44:12 2009 +0200

    app: When importing a file, setup image state properly
    
    When an opened file is not an .xcf file it is considered an imported
    file. Adjust the state of the loaded image accordingly to reflect its
    imported state. Store the import source and set that as 'Export to'
    target.
---
 app/file/file-open.c |   41 ++++++++++++++++++++++++++++++++---------
 app/file/gimp-file.h |   10 +++++++---
 2 files changed, 39 insertions(+), 12 deletions(-)

diff --git a/app/file/file-open.c b/app/file/file-open.c
index 62fd779..78d1f9d 100644
--- a/app/file/file-open.c
+++ b/app/file/file-open.c
@@ -73,15 +73,16 @@
 #include "gimp-intl.h"
 
 
-static void  file_open_sanitize_image       (GimpImage    *image,
-                                             gboolean      as_new);
-static void  file_open_convert_items        (GimpImage    *dest_image,
-                                             const gchar  *basename,
-                                             GList        *items);
-static void  file_open_handle_color_profile (GimpImage    *image,
-                                             GimpContext  *context,
-                                             GimpProgress *progress,
-                                             GimpRunMode   run_mode);
+static void     file_open_sanitize_image       (GimpImage                 *image,
+                                                gboolean                   as_new);
+static void     file_open_convert_items        (GimpImage                 *dest_image,
+                                                const gchar               *basename,
+                                                GList                     *items);
+static void     file_open_handle_color_profile (GimpImage                 *image,
+                                                GimpContext               *context,
+                                                GimpProgress              *progress,
+                                                GimpRunMode                run_mode);
+static gboolean file_open_file_proc_is_import  (const GimpPlugInProcedure *file_proc);
 
 
 /*  public functions  */
@@ -203,6 +204,20 @@ file_open_image (Gimp                *gimp,
       file_open_handle_color_profile (image, context, progress, run_mode);
     }
 
+  if (file_open_file_proc_is_import (file_proc))
+    {
+      /* Remember the import source */
+      g_object_set_data_full (G_OBJECT (image), GIMP_FILE_IMPORT_SOURCE_URI_KEY,
+                              g_strdup (uri), (GDestroyNotify) g_free);
+
+      /* Set 'Export to' target to import source */
+      g_object_set_data_full (G_OBJECT (image), GIMP_FILE_EXPORT_TO_URI_KEY,
+                              g_strdup (uri), (GDestroyNotify) g_free);
+
+      /* We shall treat this file as an Untitled file */
+      gimp_object_set_name (GIMP_OBJECT (image), NULL);
+    }
+
   return image;
 }
 
@@ -709,3 +724,11 @@ file_open_handle_color_profile (GimpImage    *image,
       gimp_image_undo_enable (image);
     }
 }
+
+static gboolean
+file_open_file_proc_is_import (const GimpPlugInProcedure *file_proc)
+{
+  return !(file_proc &&
+           file_proc->mime_type &&
+           strcmp (file_proc->mime_type, "image/xcf") == 0);
+}
diff --git a/app/file/gimp-file.h b/app/file/gimp-file.h
index 3ce5e1f..4e826b9 100644
--- a/app/file/gimp-file.h
+++ b/app/file/gimp-file.h
@@ -21,10 +21,14 @@
 #ifndef __GIMP_FILE_H__
 #define __GIMP_FILE_H__
 
+/* Data keys for Gimp */
+#define GIMP_FILE_OPEN_LAST_URI_KEY     "gimp-file-open-last-uri"
+#define GIMP_FILE_SAVE_LAST_URI_KEY     "gimp-file-save-last-uri"
 
-#define GIMP_FILE_SAVE_LAST_URI_KEY   "gimp-file-save-last-uri"
-#define GIMP_FILE_OPEN_LAST_URI_KEY   "gimp-file-open-last-uri"
-#define GIMP_FILE_SAVE_A_COPY_URI_KEY "gimp-file-save-a-copy-uri"
+/* Data keys for GimpImage */
+#define GIMP_FILE_SAVE_A_COPY_URI_KEY   "gimp-file-save-a-copy-uri"
+#define GIMP_FILE_EXPORT_TO_URI_KEY     "gimp-file-export-to-uri"
+#define GIMP_FILE_IMPORT_SOURCE_URI_KEY "gimp-file-import-source-uri"
 
 
 #endif /* __GIMP_FILE_H__ */



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