[gimp] app: Session manage multi-column dock windows



commit 34ad9dad1a06b67ab2b2383606318ea8f457a653
Author: Martin Nordholts <martinn src gnome org>
Date:   Sun Dec 6 14:49:13 2009 +0100

    app: Session manage multi-column dock windows
    
    Introduce GimpSessionInfoDock and session manage multi-column dock
    windows. We are still backwards compatible with sessionrc, the only
    difference is that a "session-info" entry now can have multiple "dock"
    entries.
    
    Also make ond dock window multi-column in the regression test
    app/tests/test-session-management.c and adjust positions and image
    selection menus a bit.

 app/tests/gimpdir/sessionrc           |   34 ++++++++------
 app/widgets/gimpsessioninfo-dock.c    |   72 +++++++++++++++++++++--------
 app/widgets/gimpsessioninfo-dock.h    |   33 +++++++++-----
 app/widgets/gimpsessioninfo-private.h |    4 +-
 app/widgets/gimpsessioninfo.c         |   81 ++++++++++++++++++++++-----------
 app/widgets/widgets-types.h           |    1 +
 6 files changed, 153 insertions(+), 72 deletions(-)
---
diff --git a/app/tests/gimpdir/sessionrc b/app/tests/gimpdir/sessionrc
index dd40bf4..8b9f202 100644
--- a/app/tests/gimpdir/sessionrc
+++ b/app/tests/gimpdir/sessionrc
@@ -6,11 +6,11 @@
 # you quit GIMP.  If this file isn't found, defaults are used.
 
 (session-info "dock" "dock"
-    (position 428 198)
-    (size 210 523)
+    (position 566 171)
+    (size 210 535)
     (open-on-exit)
     (aux-info
-        (show-image-menu "true")
+        (show-image-menu "false")
         (follow-active-image "true"))
     (dock
         (book
@@ -21,13 +21,13 @@
             (dockable "gimp-undo-history"
                 (tab-style icon)))
         (book
-            (position 259)
+            (position 289)
             (current-page 0)
             (dockable "gimp-brush-grid"
                 (tab-style preview)))))
 (session-info "dock" "dock"
-    (position 184 358)
-    (size 200 300)
+    (position 141 291)
+    (size 406 300)
     (open-on-exit)
     (aux-info
         (show-image-menu "false")
@@ -36,9 +36,14 @@
         (book
             (current-page 0)
             (dockable "gimp-tool-options"
+                (tab-style icon))))
+    (dock
+        (book
+            (current-page 0)
+            (dockable "gimp-device-status"
                 (tab-style icon)))))
 (session-info "dock" "dock"
-    (position 769 64)
+    (position 795 43)
     (size 200 265)
     (open-on-exit)
     (aux-info
@@ -52,8 +57,8 @@
             (dockable "gimp-gradient-list"
                 (tab-style preview)))))
 (session-info "dock" "dock"
-    (position 714 320)
-    (size 200 401)
+    (position 803 344)
+    (size 200 404)
     (open-on-exit)
     (aux-info
         (show-image-menu "true")
@@ -74,15 +79,16 @@
                     (current-data "Standard")
                     (zoom-factor "2.80"))))))
 (session-info "toolbox" "dock"
-    (position 44 104)
-    (size 102 526)
-    (open-on-exit))
+    (position 13 37)
+    (size 102 520)
+    (open-on-exit)
+    (dock))
 (session-info "toplevel" "gimp-file-open-dialog"
     (position 392 140)
     (size 902 816))
 (session-info "display" "gimp-empty-image-window"
-    (position 178 35)
-    (size 563 190))
+    (position 140 32)
+    (size 610 190))
 
 (last-tip-shown 0)
 
diff --git a/app/widgets/gimpsessioninfo-dock.c b/app/widgets/gimpsessioninfo-dock.c
index 10a1a9e..931bddd 100644
--- a/app/widgets/gimpsessioninfo-dock.c
+++ b/app/widgets/gimpsessioninfo-dock.c
@@ -44,36 +44,61 @@ enum
 
 /*  public functions  */
 
+GimpSessionInfoDock *
+gimp_session_info_dock_new (void)
+{
+  return g_slice_new0 (GimpSessionInfoDock);
+}
+
 void
-gimp_session_info_dock_serialize (GimpConfigWriter *writer,
-                                  GList            *books)
+gimp_session_info_dock_free (GimpSessionInfoDock *dock_info)
+{
+  g_return_if_fail (dock_info != NULL);
+
+  if (dock_info->books)
+    {
+      g_list_foreach (dock_info->books,
+                      (GFunc) gimp_session_info_book_free,
+                      NULL);
+      g_list_free (dock_info->books);
+      dock_info->books = NULL;
+    }
+
+  g_slice_free (GimpSessionInfoDock, dock_info);
+}
+
+void
+gimp_session_info_dock_serialize (GimpConfigWriter    *writer,
+                                  GimpSessionInfoDock *dock_info)
 {
   GList *list;
 
   g_return_if_fail (writer != NULL);
-  g_return_if_fail (books != NULL);
+  g_return_if_fail (dock_info != NULL);
 
   gimp_config_writer_open (writer, "dock");
 
-  for (list = books; list; list = g_list_next (list))
+  for (list = dock_info->books; list; list = g_list_next (list))
     gimp_session_info_book_serialize (writer, list->data);
 
   gimp_config_writer_close (writer);
 }
 
 GTokenType
-gimp_session_info_dock_deserialize (GScanner        *scanner,
-                                    gint             scope,
-                                    GimpSessionInfo *info)
+gimp_session_info_dock_deserialize (GScanner             *scanner,
+                                    gint                  scope,
+                                    GimpSessionInfoDock **dock_info)
 {
   GTokenType token;
 
   g_return_val_if_fail (scanner != NULL, G_TOKEN_LEFT_PAREN);
-  g_return_val_if_fail (info != NULL, G_TOKEN_LEFT_PAREN);
+  g_return_val_if_fail (dock_info != NULL, G_TOKEN_LEFT_PAREN);
 
   g_scanner_scope_add_symbol (scanner, scope, "book",
                               GINT_TO_POINTER (SESSION_INFO_BOOK));
 
+  *dock_info = gimp_session_info_dock_new ();
+
   token = G_TOKEN_LEFT_PAREN;
 
   while (g_scanner_peek_next_token (scanner) == token)
@@ -98,7 +123,7 @@ gimp_session_info_dock_deserialize (GScanner        *scanner,
 
               if (token == G_TOKEN_LEFT_PAREN)
                 {
-                  info->p->books = g_list_append (info->p->books, book);
+                  (*dock_info)->books = g_list_append ((*dock_info)->books, book);
                   g_scanner_set_scope (scanner, scope);
                 }
               else
@@ -126,24 +151,28 @@ gimp_session_info_dock_deserialize (GScanner        *scanner,
   return token;
 }
 
-GList *
+GimpSessionInfoDock *
 gimp_session_info_dock_from_widget (GimpDock *dock)
 {
-  GList *list;
-  GList *infos = NULL;
+  GimpSessionInfoDock *dock_info = NULL;
+  GList               *list      = NULL;
 
   g_return_val_if_fail (GIMP_IS_DOCK (dock), NULL);
 
+  dock_info = gimp_session_info_dock_new ();
+
   for (list = gimp_dock_get_dockbooks (dock); list; list = g_list_next (list))
     {
       GimpSessionInfoBook *book;
 
       book = gimp_session_info_book_from_widget (list->data);
 
-      infos = g_list_prepend (infos, book);
+      dock_info->books = g_list_prepend (dock_info->books, book);
     }
 
-  return g_list_reverse (infos);
+  dock_info->books = g_list_reverse (dock_info->books);
+  
+  return dock_info;
 }
 
 static void
@@ -172,10 +201,10 @@ gimp_session_info_dock_paned_map (GtkWidget *paned,
 }
 
 void
-gimp_session_info_dock_restore (GList             *books,
-                                GimpDialogFactory *factory,
-                                GdkScreen         *screen,
-                                GimpDockWindow    *dock_window)
+gimp_session_info_dock_restore (GimpSessionInfoDock *dock_info,
+                                GimpDialogFactory   *factory,
+                                GdkScreen           *screen,
+                                GimpDockWindow      *dock_window)
 {
   GtkWidget     *dock       = NULL;
   GList         *iter       = NULL;
@@ -196,7 +225,12 @@ gimp_session_info_dock_restore (GList             *books,
                              GIMP_DOCK (dock),
                              -1);
 
-  for (iter = books; iter; iter = g_list_next (iter))
+  /* Note that if it is a toolbox, we will get here even though we
+   * don't have any books
+   */
+  for (iter = dock_info ? dock_info->books : NULL;
+       iter;
+       iter = g_list_next (iter))
     {
       GimpSessionInfoBook *book_info = iter->data;
       GtkWidget           *dockbook;
diff --git a/app/widgets/gimpsessioninfo-dock.h b/app/widgets/gimpsessioninfo-dock.h
index 6933fa8..35abf42 100644
--- a/app/widgets/gimpsessioninfo-dock.h
+++ b/app/widgets/gimpsessioninfo-dock.h
@@ -22,18 +22,29 @@
 #define __GIMP_SESSION_INFO_DOCK_H__
 
 
-void         gimp_session_info_dock_serialize   (GimpConfigWriter  *writer,
-                                                 GList             *books);
-GTokenType   gimp_session_info_dock_deserialize (GScanner          *scanner,
-                                                 gint               scope,
-                                                 GimpSessionInfo   *info);
-
-GList      * gimp_session_info_dock_from_widget (GimpDock          *dock);
+/**
+ * GimpSessionInfoDock:
+ *
+ * Contains information about a dock in the interface.
+ */
+struct _GimpSessionInfoDock
+{
+  /*  list of GimpSessionInfoBook  */
+  GList *books;
+};
 
-void         gimp_session_info_dock_restore     (GList             *books,
-                                                 GimpDialogFactory *factory,
-                                                 GdkScreen         *screen,
-                                                 GimpDockWindow    *dock_window);
+GimpSessionInfoDock * gimp_session_info_dock_new         (void);
+void                  gimp_session_info_dock_free        (GimpSessionInfoDock  *dock_info);
+void                  gimp_session_info_dock_serialize   (GimpConfigWriter     *writer,
+                                                          GimpSessionInfoDock  *dock);
+GTokenType            gimp_session_info_dock_deserialize (GScanner             *scanner,
+                                                          gint                  scope,
+                                                          GimpSessionInfoDock **info);
+GimpSessionInfoDock * gimp_session_info_dock_from_widget (GimpDock             *dock);
+void                  gimp_session_info_dock_restore     (GimpSessionInfoDock  *dock_info,
+                                                          GimpDialogFactory    *factory,
+                                                          GdkScreen            *screen,
+                                                          GimpDockWindow       *dock_window);
 
 
 #endif  /* __GIMP_SESSION_INFO_DOCK_H__ */
diff --git a/app/widgets/gimpsessioninfo-private.h b/app/widgets/gimpsessioninfo-private.h
index 98d8a99..236de75 100644
--- a/app/widgets/gimpsessioninfo-private.h
+++ b/app/widgets/gimpsessioninfo-private.h
@@ -45,8 +45,8 @@ struct _GimpSessionInfoPrivate
    */
   GimpDialogFactoryEntry *factory_entry;
 
-  /*  list of GimpSessionInfoBook  */
-  GList                  *books;
+  /*  list of GimpSessionInfoDock  */
+  GList                  *docks;
 };
 
 
diff --git a/app/widgets/gimpsessioninfo.c b/app/widgets/gimpsessioninfo.c
index f877a95..dc641da 100644
--- a/app/widgets/gimpsessioninfo.c
+++ b/app/widgets/gimpsessioninfo.c
@@ -131,6 +131,7 @@ gimp_session_info_serialize (GimpConfig       *config,
                              gpointer          data)
 {
   GimpSessionInfo *info = GIMP_SESSION_INFO (config);
+  GList           *iter = NULL;
 
   gimp_config_writer_open (writer, "position");
   gimp_config_writer_printf (writer, "%d %d", info->p->x, info->p->y);
@@ -156,8 +157,8 @@ gimp_session_info_serialize (GimpConfig       *config,
   if (info->p->aux_info)
     gimp_session_info_aux_serialize (writer, info->p->aux_info);
 
-  if (info->p->books)
-    gimp_session_info_dock_serialize (writer, info->p->books);
+  for (iter = info->p->docks; iter; iter = g_list_next (iter))
+    gimp_session_info_dock_serialize (writer, iter->data);
 
   return TRUE;
 }
@@ -274,18 +275,24 @@ gimp_session_info_deserialize (GimpConfig *config,
               break;
 
             case SESSION_INFO_DOCK:
-              if (info->p->factory_entry)
-                goto error;
-
-              g_scanner_set_scope (scanner, scope_id + 1);
-              token = gimp_session_info_dock_deserialize (scanner, scope_id + 1,
-                                                          info);
-
-              if (token == G_TOKEN_LEFT_PAREN)
-                g_scanner_set_scope (scanner, scope_id);
-              else
-                goto error;
-
+              {
+                GimpSessionInfoDock *dock_info = NULL;
+
+                if (info->p->factory_entry)
+                  goto error;
+
+                g_scanner_set_scope (scanner, scope_id + 1);
+                token = gimp_session_info_dock_deserialize (scanner, scope_id + 1,
+                                                            &dock_info);
+
+                if (token == G_TOKEN_LEFT_PAREN)
+                  {
+                    g_scanner_set_scope (scanner, scope_id);
+                    info->p->docks = g_list_append (info->p->docks, dock_info);
+                  }
+                else
+                  goto error;
+              }
               break;
 
             default:
@@ -386,6 +393,7 @@ gimp_session_info_restore (GimpSessionInfo   *info,
   else
     {
       GtkWidget *dock_window = NULL;
+      GList     *iter        = NULL;
 
       GIMP_LOG (DIALOG_FACTORY, "restoring dock window (info %p)",
                 info);
@@ -395,10 +403,24 @@ gimp_session_info_restore (GimpSessionInfo   *info,
       if (dock_window && info->p->aux_info)
         gimp_session_info_aux_set_list (GTK_WIDGET (dock_window), info->p->aux_info);
 
-      gimp_session_info_dock_restore (info->p->books,
-                                      factory,
-                                      screen,
-                                      GIMP_DOCK_WINDOW (dock_window));
+      /* If we have docks, proceed as usual. If we don't have docks,
+       * assume it is the toolbox and restore the dock anyway
+       */
+      if (info->p->docks)
+        {
+          for (iter = info->p->docks; iter; iter = g_list_next (iter))
+            gimp_session_info_dock_restore ((GimpSessionInfoDock *)iter->data,
+                                            factory,
+                                            screen,
+                                            GIMP_DOCK_WINDOW (dock_window));
+        }
+      else
+        {
+          gimp_session_info_dock_restore (NULL,
+                                          factory,
+                                          screen,
+                                          GIMP_DOCK_WINDOW (dock_window));
+        }
 
       gtk_widget_show (GTK_WIDGET (dock_window));
     }
@@ -615,11 +637,18 @@ gimp_session_info_get_info (GimpSessionInfo *info)
       (info->p->factory_entry &&
        info->p->factory_entry->dockable))
     {
-      GimpDock *dock = NULL;
+      GList *iter = NULL;
 
-      dock = gimp_dock_window_get_dock (GIMP_DOCK_WINDOW (info->p->widget));
+      for (iter = gimp_dock_window_get_docks (GIMP_DOCK_WINDOW (info->p->widget));
+           iter;
+           iter = g_list_next (iter))
+        {
+          GimpDock *dock = GIMP_DOCK (iter->data);
 
-      info->p->books = gimp_session_info_dock_from_widget (dock);
+          info->p->docks =
+            g_list_append (info->p->docks,
+                           gimp_session_info_dock_from_widget (dock));
+        }
     }
 }
 
@@ -636,12 +665,12 @@ gimp_session_info_clear_info (GimpSessionInfo *info)
       info->p->aux_info = NULL;
     }
 
-   if (info->p->books)
+   if (info->p->docks)
      {
-       g_list_foreach (info->p->books,
-                       (GFunc) gimp_session_info_book_free, NULL);
-       g_list_free (info->p->books);
-       info->p->books = NULL;
+       g_list_foreach (info->p->docks,
+                       (GFunc) gimp_session_info_dock_free, NULL);
+       g_list_free (info->p->docks);
+       info->p->docks = NULL;
      }
 }
 
diff --git a/app/widgets/widgets-types.h b/app/widgets/widgets-types.h
index cf3fb20..5c9ddf5 100644
--- a/app/widgets/widgets-types.h
+++ b/app/widgets/widgets-types.h
@@ -229,6 +229,7 @@ typedef struct _GimpUIConfigurer             GimpUIConfigurer;
 
 typedef struct _GimpSessionInfo              GimpSessionInfo;
 typedef struct _GimpSessionInfoBook          GimpSessionInfoBook;
+typedef struct _GimpSessionInfoDock          GimpSessionInfoDock;
 typedef struct _GimpSessionInfoDockable      GimpSessionInfoDockable;
 typedef struct _GimpSessionInfoAux           GimpSessionInfoAux;
 



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