[gimp] app: only add supported image files to the document history



commit c885af6c3efe227347b21184c1c39b97584a9a22
Author: Michael Natterer <mitch gimp org>
Date:   Fri Jul 4 20:01:08 2014 +0200

    app: only add supported image files to the document history
    
    Initialize the history after plug-ins, and check each item listed by
    GtkRecentManager against the mime-types supported by our load
    plug-ins.

 app/file/file-procedure.c |   19 +++++++++++++++++++
 app/file/file-procedure.h |    4 ++++
 app/gui/gui-vtable.c      |   24 +++++++++++++++++-------
 app/gui/gui.c             |   10 ++++++----
 4 files changed, 46 insertions(+), 11 deletions(-)
---
diff --git a/app/file/file-procedure.c b/app/file/file-procedure.c
index 31c4e43..7a86b62 100644
--- a/app/file/file-procedure.c
+++ b/app/file/file-procedure.c
@@ -231,6 +231,25 @@ file_procedure_find_by_extension (GSList      *procs,
   return file_proc_find_by_extension (procs, uri, FALSE, FALSE);
 }
 
+GimpPlugInProcedure *
+file_procedure_find_by_mime_type (GSList      *procs,
+                                  const gchar *mime_type)
+{
+  GSList *list;
+
+  g_return_val_if_fail (mime_type != NULL, NULL);
+
+  for (list = procs; list; list = g_slist_next (list))
+    {
+      GimpPlugInProcedure *proc = list->data;
+
+      if (proc->mime_type && ! strcmp (mime_type, proc->mime_type))
+        return proc;
+    }
+
+  return NULL;
+}
+
 gboolean
 file_procedure_in_group (GimpPlugInProcedure *file_proc,
                          FileProcedureGroup   group)
diff --git a/app/file/file-procedure.h b/app/file/file-procedure.h
index 7df1c2e..6f4dd8a 100644
--- a/app/file/file-procedure.h
+++ b/app/file/file-procedure.h
@@ -37,6 +37,10 @@ GimpPlugInProcedure *file_procedure_find_by_prefix    (GSList               *pro
                                                        const gchar          *uri);
 GimpPlugInProcedure *file_procedure_find_by_extension (GSList               *procs,
                                                        const gchar          *uri);
+
+GimpPlugInProcedure *file_procedure_find_by_mime_type (GSList               *procs,
+                                                       const gchar          *mime_type);
+
 gboolean             file_procedure_in_group          (GimpPlugInProcedure  *file_proc,
                                                        FileProcedureGroup    group);
 
diff --git a/app/gui/gui-vtable.c b/app/gui/gui-vtable.c
index 426e94b..b6580a4 100644
--- a/app/gui/gui-vtable.c
+++ b/app/gui/gui-vtable.c
@@ -47,6 +47,10 @@
 
 #include "text/gimpfont.h"
 
+#include "plug-in/gimppluginmanager.h"
+
+#include "file/file-procedure.h"
+
 #include "widgets/gimpactiongroup.h"
 #include "widgets/gimpbrushselect.h"
 #include "widgets/gimpdialogfactory.h"
@@ -693,16 +697,22 @@ gui_recent_list_load (Gimp *gimp)
       if (gtk_recent_info_has_application (info,
                                            "GNU Image Manipulation Program"))
         {
-          GimpImagefile *imagefile;
+          const gchar *mime_type = gtk_recent_info_get_mime_type (info);
 
-          imagefile = gimp_imagefile_new (gimp,
-                                          gtk_recent_info_get_uri (info));
+          if (mime_type &&
+              file_procedure_find_by_mime_type (gimp->plug_in_manager->load_procs,
+                                                mime_type))
+            {
+              GimpImagefile *imagefile;
 
-          gimp_imagefile_set_mime_type (imagefile,
-                                        gtk_recent_info_get_mime_type (info));
+              imagefile = gimp_imagefile_new (gimp,
+                                              gtk_recent_info_get_uri (info));
 
-          gimp_container_add (gimp->documents, GIMP_OBJECT (imagefile));
-          g_object_unref (imagefile);
+              gimp_imagefile_set_mime_type (imagefile, mime_type);
+
+              gimp_container_add (gimp->documents, GIMP_OBJECT (imagefile));
+              g_object_unref (imagefile);
+            }
         }
 
       gtk_recent_info_unref (info);
diff --git a/app/gui/gui.c b/app/gui/gui.c
index 4894478..017fa17 100644
--- a/app/gui/gui.c
+++ b/app/gui/gui.c
@@ -450,10 +450,6 @@ gui_restore_callback (Gimp               *gimp,
 
   g_type_class_unref (g_type_class_ref (GIMP_TYPE_COLOR_SELECTOR_PALETTE));
 
-  /*  initialize the document history  */
-  status_callback (NULL, _("Documents"), 0.9);
-  gimp_recent_list_load (gimp);
-
   status_callback (NULL, _("Tool Options"), 1.0);
   gimp_tools_restore (gimp);
 }
@@ -495,6 +491,12 @@ gui_restore_after_callback (Gimp               *gimp,
 
   gimp->message_handler = GIMP_MESSAGE_BOX;
 
+  /*  load the recent documents after gimp_real_restore() because we
+   *  need the mime-types implemented by plug-ins
+   */
+  status_callback (NULL, _("Documents"), 0.9);
+  gimp_recent_list_load (gimp);
+
   /*  enable this to always have icons everywhere  */
   if (g_getenv ("GIMP_ICONS_LIKE_A_BOSS"))
     {


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