[gimp] app: Have only one GimpDialogFactoryEntry member in GimpSessionInfo



commit 4ab58d2e7722f52818422b61ddf2da46554e8f58
Author: Martin Nordholts <martinn src gnome org>
Date:   Sun Sep 20 12:17:22 2009 +0200

    app: Have only one GimpDialogFactoryEntry member in GimpSessionInfo
    
    Simplify the code a bit by replacing the 'toplevel_entry' and
    'dockable_entry' members in GimpSessionInfo with a single
    'factory_entry'. We compensate for this by adding a 'dockable'
    gboolean to GimpDialogFactoryEntry.

 app/dialogs/dialogs.c           |   10 ++++----
 app/gui/session.c               |    6 ++--
 app/widgets/gimpdialogfactory.c |   45 ++++++++++++++------------------------
 app/widgets/gimpdialogfactory.h |    5 ++++
 app/widgets/gimpsessioninfo.c   |   31 +++++++++++++-------------
 app/widgets/gimpsessioninfo.h   |    7 +++--
 6 files changed, 50 insertions(+), 54 deletions(-)
---
diff --git a/app/dialogs/dialogs.c b/app/dialogs/dialogs.c
index 942d0d3..dcd9900 100644
--- a/app/dialogs/dialogs.c
+++ b/app/dialogs/dialogs.c
@@ -50,11 +50,11 @@ GimpContainer     *global_recent_docks    = NULL;
 
 #define FOREIGN(id, singleton, remember_size) \
   { id, NULL, NULL, NULL, NULL, \
-    NULL, 0, singleton,  TRUE, remember_size, FALSE }
+    NULL, 0, singleton,  TRUE, remember_size, FALSE, FALSE }
 
 #define TOPLEVEL(id, new_func, singleton, session_managed, remember_size) \
   { id, NULL, NULL, NULL, NULL, \
-    new_func, 0, singleton, session_managed, remember_size, FALSE }
+    new_func, 0, singleton, session_managed, remember_size, FALSE, FALSE }
 
 
 static const GimpDialogFactoryEntry toplevel_entries[] =
@@ -123,14 +123,14 @@ static const GimpDialogFactoryEntry toplevel_entries[] =
 #define DOCKABLE(id,name,blurb,stock_id,help_id,\
                  new_func,view_size,singleton) \
   { id, name, blurb, stock_id, help_id, \
-    new_func, view_size, singleton, FALSE, FALSE, TRUE }
+    new_func, view_size, singleton, FALSE, FALSE, TRUE, TRUE }
 
 #define LISTGRID(id,name,blurb,stock_id,help_id,\
                  view_size) \
   { "gimp-"#id"-list", name, blurb, stock_id, help_id, \
-    dialogs_##id##_list_view_new, view_size, FALSE, FALSE, FALSE, TRUE }, \
+    dialogs_##id##_list_view_new, view_size, FALSE, FALSE, FALSE, TRUE, TRUE }, \
   { "gimp-"#id"-grid", name, blurb, stock_id, help_id, \
-    dialogs_##id##_grid_view_new, view_size, FALSE, FALSE, FALSE, TRUE }
+    dialogs_##id##_grid_view_new, view_size, FALSE, FALSE, FALSE, TRUE, TRUE }
 
 static const GimpDialogFactoryEntry dock_entries[] =
 {
diff --git a/app/gui/session.c b/app/gui/session.c
index eecbb22..710dcee 100644
--- a/app/gui/session.c
+++ b/app/gui/session.c
@@ -153,13 +153,13 @@ session_init (Gimp *gimp)
                */
               if (!g_str_equal (entry_name, "dock"))
                 {
-                  info->toplevel_entry = gimp_dialog_factory_find_entry (factory,
-                                                                         entry_name);
+                  info->factory_entry = gimp_dialog_factory_find_entry (factory,
+                                                                        entry_name);
 
                   /* If we expected a dialog factory entry but failed
                    * to find one, skip to add this session info object
                    */
-                  skip = (info->toplevel_entry == NULL);
+                  skip = (info->factory_entry == NULL);
                 }
 
               g_free (entry_name);
diff --git a/app/widgets/gimpdialogfactory.c b/app/widgets/gimpdialogfactory.c
index b9b6b98..3c0e72a 100644
--- a/app/widgets/gimpdialogfactory.c
+++ b/app/widgets/gimpdialogfactory.c
@@ -387,10 +387,8 @@ gimp_dialog_factory_find_session_info (GimpDialogFactory *factory,
     {
       GimpSessionInfo *info = list->data;
 
-      if ((info->toplevel_entry &&
-           ! strcmp (identifier, info->toplevel_entry->identifier)) ||
-          (info->dockable_entry &&
-           ! strcmp (identifier, info->dockable_entry->identifier)))
+      if (info->factory_entry &&
+          g_str_equal (identifier, info->factory_entry->identifier))
         {
           return info;
         }
@@ -823,8 +821,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
         {
           GimpSessionInfo *current_info = list->data;
 
-          if ((current_info->toplevel_entry == entry) ||
-              (current_info->dockable_entry == entry))
+          if (current_info->factory_entry == entry)
             {
               if (current_info->widget)
                 {
@@ -875,24 +872,17 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
                     toplevel ? "toplevel" : "dockable",
                     entry->identifier);
 
-          if (toplevel)
-            {
-              info->toplevel_entry = entry;
+          info->factory_entry = entry;
 
-              /*  if we create a new session info, we never call
-               *  gimp_session_info_set_geometry(), but still the
-               *  dialog needs GDK_HINT_USER_POS so it keeps its
-               *  position when hidden/shown within this(!) session.
-               */
-              if (gimp_session_info_is_session_managed (info))
-                g_signal_connect (dialog, "configure-event",
-                                  G_CALLBACK (gimp_dialog_factory_set_user_pos),
-                                  NULL);
-            }
-          else
-            {
-              info->dockable_entry = entry;
-            }
+          /*  if we create a new session info, we never call
+           *  gimp_session_info_set_geometry(), but still the
+           *  dialog needs GDK_HINT_USER_POS so it keeps its
+           *  position when hidden/shown within this(!) session.
+           */
+          if (gimp_session_info_is_session_managed (info))
+            g_signal_connect (dialog, "configure-event",
+                              G_CALLBACK (gimp_dialog_factory_set_user_pos),
+                              NULL);
 
           factory->session_infos = g_list_append (factory->session_infos, info);
         }
@@ -906,8 +896,7 @@ gimp_dialog_factory_add_dialog (GimpDialogFactory *factory,
           GimpSessionInfo *current_info = list->data;
 
           /*  take the first empty slot  */
-          if (! current_info->toplevel_entry &&
-              ! current_info->dockable_entry &&
+          if (! current_info->factory_entry &&
               ! current_info->widget)
             {
               current_info->widget = dialog;
@@ -1429,8 +1418,8 @@ gimp_dialog_factories_save_foreach (gconstpointer      key,
       gimp_config_writer_string (writer,
                                  gimp_object_get_name (factory));
       gimp_config_writer_string (writer,
-                                 info->toplevel_entry ?
-                                 info->toplevel_entry->identifier :
+                                 info->factory_entry ?
+                                 info->factory_entry->identifier :
                                  "dock");
 
       GIMP_CONFIG_GET_INTERFACE (info)->serialize (GIMP_CONFIG (info),
diff --git a/app/widgets/gimpdialogfactory.h b/app/widgets/gimpdialogfactory.h
index 1b15799..d0cc335 100644
--- a/app/widgets/gimpdialogfactory.h
+++ b/app/widgets/gimpdialogfactory.h
@@ -58,6 +58,11 @@ struct _GimpDialogFactoryEntry
   gboolean           session_managed;
   gboolean           remember_size;
   gboolean           remember_if_open;
+
+  /* If TRUE the entry is for a dockable, otherwise it is for a
+   * toplevel
+   */
+  gboolean           dockable;
 };
 
 
diff --git a/app/widgets/gimpsessioninfo.c b/app/widgets/gimpsessioninfo.c
index 61212b6..abf5e57 100644
--- a/app/widgets/gimpsessioninfo.c
+++ b/app/widgets/gimpsessioninfo.c
@@ -268,7 +268,7 @@ gimp_session_info_deserialize (GimpConfig *config,
               break;
 
             case SESSION_INFO_DOCK:
-              if (info->toplevel_entry)
+              if (info->factory_entry)
                 goto error;
 
               g_scanner_set_scope (scanner, scope_id + 1);
@@ -323,8 +323,7 @@ gimp_session_info_deserialize (GimpConfig *config,
 static gboolean
 gimp_session_info_is_for_dock (GimpSessionInfo *info)
 {
-  gboolean entry_state_for_dock  = (! info->toplevel_entry &&
-                                    ! info->dockable_entry);
+  gboolean entry_state_for_dock  =  info->factory_entry == NULL;
   gboolean widget_state_for_dock = (info->widget == NULL ||
                                     GIMP_IS_DOCK (info->widget));
 
@@ -361,14 +360,14 @@ gimp_session_info_restore (GimpSessionInfo   *info,
   info->open   = FALSE;
   info->screen = DEFAULT_SCREEN;
 
-  if (info->toplevel_entry)
+  if (info->factory_entry && ! info->factory_entry->dockable)
     {
       GtkWidget *dialog;
 
       dialog =
         gimp_dialog_factory_dialog_new (factory, screen,
-                                        info->toplevel_entry->identifier,
-                                        info->toplevel_entry->view_size,
+                                        info->factory_entry->identifier,
+                                        info->factory_entry->view_size,
                                         TRUE);
 
       if (dialog && info->aux_info)
@@ -574,7 +573,9 @@ gimp_session_info_get_info (GimpSessionInfo *info)
 
   info->aux_info = gimp_session_info_aux_get_list (info->widget);
 
-  if (! info->toplevel_entry)
+  if (info->factory_entry == NULL ||
+      (info->factory_entry &&
+       info->factory_entry->dockable))
     info->books = gimp_session_info_dock_from_widget (GIMP_DOCK (info->widget));
 }
 
@@ -606,8 +607,8 @@ gimp_session_info_is_singleton (GimpSessionInfo *info)
   g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
 
   return (! gimp_session_info_is_for_dock (info) &&
-          info->toplevel_entry &&
-          info->toplevel_entry->singleton);
+          info->factory_entry &&
+          info->factory_entry->singleton);
 }
 
 gboolean
@@ -616,8 +617,8 @@ gimp_session_info_is_session_managed (GimpSessionInfo *info)
   g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
 
   return (gimp_session_info_is_for_dock (info) ||
-          (info->toplevel_entry &&
-           info->toplevel_entry->session_managed));
+          (info->factory_entry &&
+           info->factory_entry->session_managed));
 }
 
 
@@ -627,8 +628,8 @@ gimp_session_info_get_remember_size (GimpSessionInfo *info)
   g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
 
   return (gimp_session_info_is_for_dock (info) ||
-          (info->toplevel_entry &&
-           info->toplevel_entry->remember_size));
+          (info->factory_entry &&
+           info->factory_entry->remember_size));
 }
 
 gboolean
@@ -637,6 +638,6 @@ gimp_session_info_get_remember_if_open (GimpSessionInfo *info)
   g_return_val_if_fail (GIMP_IS_SESSION_INFO (info), FALSE);
 
   return (gimp_session_info_is_for_dock (info) ||
-          (info->toplevel_entry &&
-           info->toplevel_entry->remember_if_open));
+          (info->factory_entry &&
+           info->factory_entry->remember_if_open));
 }
diff --git a/app/widgets/gimpsessioninfo.h b/app/widgets/gimpsessioninfo.h
index ef27f9d..5fb977c 100644
--- a/app/widgets/gimpsessioninfo.h
+++ b/app/widgets/gimpsessioninfo.h
@@ -59,9 +59,10 @@ struct _GimpSessionInfo
 
   GtkWidget              *widget;
 
-  /*  only one of these is valid  */
-  GimpDialogFactoryEntry *toplevel_entry;
-  GimpDialogFactoryEntry *dockable_entry;
+  /*  the dialog factory entry for object we have session info for
+   *  note that pure "dock" entries don't have any factory entry
+   */
+  GimpDialogFactoryEntry *factory_entry;
 
   /*  list of GimpSessionInfoBook  */
   GList                  *books;



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