[gimp] app: Remember column width in multi-column dock windows



commit bed298be13109d880113691230d0609a7913616c
Author: Martin Nordholts <martinn src gnome org>
Date:   Tue May 31 17:40:10 2011 +0200

    app: Remember column width in multi-column dock windows

 NEWS                                 |    1 +
 app/tests/gimpdir/sessionrc          |    3 ++-
 app/tests/gimpdir/sessionrc-2-8      |    3 ++-
 app/tests/gimpdir/sessionrc-expected |    3 ++-
 app/widgets/gimpsessioninfo-book.c   |   20 +++-----------------
 app/widgets/gimpsessioninfo-dock.c   |   29 +++++++++++++++++++++++++++--
 app/widgets/gimpsessioninfo-dock.h   |    3 +++
 app/widgets/gimpsessioninfo.c        |   27 +++++++++++++++++++++++----
 app/widgets/gimpwidgets-utils.c      |   22 ++++++++++++++++++++++
 app/widgets/gimpwidgets-utils.h      |    2 ++
 10 files changed, 87 insertions(+), 26 deletions(-)
---
diff --git a/NEWS b/NEWS
index 961a9b5..79110f1 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,7 @@ UI:
    create new images from them
  - Cage tool: allow to add handle to the cage when clicking on an edge
  - Cage tool: allow to remove selected handles from the cage by hitting delete
+ - Remember column widths in multi-column dock windows
 
 
 Core:
diff --git a/app/tests/gimpdir/sessionrc b/app/tests/gimpdir/sessionrc
index 94c4703..fd5e23f 100644
--- a/app/tests/gimpdir/sessionrc
+++ b/app/tests/gimpdir/sessionrc
@@ -27,7 +27,7 @@
 (session-info "toplevel"
     (factory-entry "gimp-dock-window")
     (position 140 290)
-    (size 405 300)
+    (size 445 300)
     (open-on-exit)
     (aux-info
         (show-image-menu "false")
@@ -38,6 +38,7 @@
             (dockable "gimp-tool-options"
                 (tab-style icon))))
     (gimp-dock
+        (position 230)
         (book
             (current-page 0)
             (dockable "gimp-device-status"
diff --git a/app/tests/gimpdir/sessionrc-2-8 b/app/tests/gimpdir/sessionrc-2-8
index 2d9e437..c027de0 100644
--- a/app/tests/gimpdir/sessionrc-2-8
+++ b/app/tests/gimpdir/sessionrc-2-8
@@ -27,7 +27,7 @@
 (session-info "toplevel"
     (factory-entry "gimp-dock-window")
     (position 140 290)
-    (size 405 300)
+    (size 445 300)
     (open-on-exit)
     (aux-info
         (show-image-menu "false")
@@ -38,6 +38,7 @@
             (dockable "gimp-tool-options"
                 (tab-style icon))))
     (gimp-dock
+        (position 230)
         (book
             (current-page 0)
             (dockable "gimp-device-status"
diff --git a/app/tests/gimpdir/sessionrc-expected b/app/tests/gimpdir/sessionrc-expected
index 2d9e437..c027de0 100644
--- a/app/tests/gimpdir/sessionrc-expected
+++ b/app/tests/gimpdir/sessionrc-expected
@@ -27,7 +27,7 @@
 (session-info "toplevel"
     (factory-entry "gimp-dock-window")
     (position 140 290)
-    (size 405 300)
+    (size 445 300)
     (open-on-exit)
     (aux-info
         (show-image-menu "false")
@@ -38,6 +38,7 @@
             (dockable "gimp-tool-options"
                 (tab-style icon))))
     (gimp-dock
+        (position 230)
         (book
             (current-page 0)
             (dockable "gimp-device-status"
diff --git a/app/widgets/gimpsessioninfo-book.c b/app/widgets/gimpsessioninfo-book.c
index 6c87e36..b150aab 100644
--- a/app/widgets/gimpsessioninfo-book.c
+++ b/app/widgets/gimpsessioninfo-book.c
@@ -34,6 +34,7 @@
 #include "gimpsessioninfo.h" /* for gimp_session_info_class_apply_position_accuracy() */
 #include "gimpsessioninfo-book.h"
 #include "gimpsessioninfo-dockable.h"
+#include "gimpwidgets-utils.h"
 
 
 enum
@@ -79,22 +80,7 @@ gimp_session_info_book_serialize (GimpConfigWriter    *writer,
   gimp_config_writer_open (writer, "book");
 
   if (info->position != 0)
-    {
-      GimpSessionInfoClass *klass;
-      gint                  pos_to_write;
-
-      klass = g_type_class_ref (GIMP_TYPE_SESSION_INFO);
-
-      pos_to_write =
-        gimp_session_info_class_apply_position_accuracy (klass,
-                                                         info->position);
-
-      gimp_config_writer_open (writer, "position");
-      gimp_config_writer_printf (writer, "%d", pos_to_write);
-      gimp_config_writer_close (writer);
-
-      g_type_class_unref (klass);
-    }
+    gimp_session_write_position (writer, info->position);
 
   gimp_config_writer_open (writer, "current-page");
   gimp_config_writer_printf (writer, "%d", info->current_page);
@@ -216,7 +202,7 @@ gimp_session_info_book_from_widget (GimpDockbook *dockbook)
 
   parent = gtk_widget_get_parent (GTK_WIDGET (dockbook));
 
-  if (GTK_IS_VPANED (parent))
+  if (GTK_IS_PANED (parent))
     {
       GtkPaned *paned = GTK_PANED (parent);
 
diff --git a/app/widgets/gimpsessioninfo-dock.c b/app/widgets/gimpsessioninfo-dock.c
index 350e99a..618276b 100644
--- a/app/widgets/gimpsessioninfo-dock.c
+++ b/app/widgets/gimpsessioninfo-dock.c
@@ -39,11 +39,13 @@
 #include "gimpsessioninfo-dock.h"
 #include "gimpsessioninfo-private.h"
 #include "gimptoolbox.h"
+#include "gimpwidgets-utils.h"
 
 
 enum
 {
   SESSION_INFO_SIDE,
+  SESSION_INFO_POSITION,
   SESSION_INFO_BOOK
 };
 
@@ -124,6 +126,9 @@ gimp_session_info_dock_serialize (GimpConfigWriter    *writer,
       gimp_config_writer_close (writer);
     }
 
+  if (dock_info->position != 0)
+    gimp_session_write_position (writer, dock_info->position);
+
   for (list = dock_info->books; list; list = g_list_next (list))
     gimp_session_info_book_serialize (writer, list->data);
 
@@ -143,6 +148,8 @@ gimp_session_info_dock_deserialize (GScanner             *scanner,
 
   g_scanner_scope_add_symbol (scanner, scope, "side",
                               GINT_TO_POINTER (SESSION_INFO_SIDE));
+  g_scanner_scope_add_symbol (scanner, scope, "position",
+                              GINT_TO_POINTER (SESSION_INFO_POSITION));
   g_scanner_scope_add_symbol (scanner, scope, "book",
                               GINT_TO_POINTER (SESSION_INFO_BOOK));
 
@@ -178,6 +185,12 @@ gimp_session_info_dock_deserialize (GScanner             *scanner,
                 (*dock_info)->side = GIMP_ALIGN_RIGHT;
               break;
 
+            case SESSION_INFO_POSITION:
+              token = G_TOKEN_INT;
+              if (! gimp_scanner_parse_int (scanner, &((*dock_info)->position)))
+                (*dock_info)->position = 0;
+              break;
+
             case SESSION_INFO_BOOK:
               g_scanner_set_scope (scanner, scope + 1);
               token = gimp_session_info_book_deserialize (scanner, scope + 1,
@@ -209,6 +222,7 @@ gimp_session_info_dock_deserialize (GScanner             *scanner,
     }
 
   g_scanner_scope_remove_symbol (scanner, scope, "book");
+  g_scanner_scope_remove_symbol (scanner, scope, "position");
   g_scanner_scope_remove_symbol (scanner, scope, "side");
 
   return token;
@@ -217,8 +231,9 @@ gimp_session_info_dock_deserialize (GScanner             *scanner,
 GimpSessionInfoDock *
 gimp_session_info_dock_from_widget (GimpDock *dock)
 {
-  GimpSessionInfoDock *dock_info = NULL;
-  GList               *list      = NULL;
+  GimpSessionInfoDock *dock_info;
+  GList               *list;
+  GtkWidget           *parent;
 
   g_return_val_if_fail (GIMP_IS_DOCK (dock), NULL);
 
@@ -238,6 +253,16 @@ gimp_session_info_dock_from_widget (GimpDock *dock)
   dock_info->books = g_list_reverse (dock_info->books);
   dock_info->side  = gimp_session_info_dock_get_side (dock);
 
+  parent = gtk_widget_get_parent (GTK_WIDGET (dock));
+
+  if (GTK_IS_PANED (parent))
+    {
+      GtkPaned *paned = GTK_PANED (parent);
+
+      if (GTK_WIDGET (dock) == gtk_paned_get_child2 (paned))
+        dock_info->position = gtk_paned_get_position (paned);
+    }
+
   return dock_info;
 }
 
diff --git a/app/widgets/gimpsessioninfo-dock.h b/app/widgets/gimpsessioninfo-dock.h
index 45dae3d..f762ec7 100644
--- a/app/widgets/gimpsessioninfo-dock.h
+++ b/app/widgets/gimpsessioninfo-dock.h
@@ -39,6 +39,9 @@ struct _GimpSessionInfoDock
    */
   GimpAlignmentType  side;
 
+  /* GtkPaned position of this dock */
+  gint               position;
+
   /*  list of GimpSessionInfoBook  */
   GList             *books;
 };
diff --git a/app/widgets/gimpsessioninfo.c b/app/widgets/gimpsessioninfo.c
index 5d07d15..cd6f983 100644
--- a/app/widgets/gimpsessioninfo.c
+++ b/app/widgets/gimpsessioninfo.c
@@ -501,10 +501,29 @@ gimp_session_info_restore (GimpSessionInfo   *info,
        * take care of that during sessionrc parsing
        */
       for (iter = info->p->docks; iter; iter = g_list_next (iter))
-        gimp_session_info_dock_restore ((GimpSessionInfoDock *)iter->data,
-                                        factory,
-                                        screen,
-                                        GIMP_DOCK_CONTAINER (dialog));
+        {
+          GimpSessionInfoDock *dock_info = (GimpSessionInfoDock *) iter->data;
+          GtkWidget           *dock;
+
+          dock =
+            GTK_WIDGET (gimp_session_info_dock_restore (dock_info,
+                                                        factory,
+                                                        screen,
+                                                        GIMP_DOCK_CONTAINER (dialog)));
+
+          if (dock && dock_info->position != 0)
+            {
+              GtkWidget *parent = gtk_widget_get_parent (dock);
+
+              if (GTK_IS_PANED (parent))
+                {
+                  GtkPaned *paned = GTK_PANED (parent);
+
+                  if (dock == gtk_paned_get_child2 (paned))
+                    gtk_paned_set_position (paned, dock_info->position);
+                }
+            }
+        }
     }
 
   g_object_unref (info);
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index 0a8a708..10c92c9 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -33,6 +33,7 @@
 #endif
 
 #include "libgimpbase/gimpbase.h"
+#include "libgimpconfig/gimpconfig.h"
 #include "libgimpmath/gimpmath.h"
 #include "libgimpcolor/gimpcolor.h"
 #include "libgimpwidgets/gimpwidgets.h"
@@ -44,6 +45,7 @@
 #include "gimpdockcontainer.h"
 #include "gimpdockwindow.h"
 #include "gimperrordialog.h"
+#include "gimpsessioninfo.h"
 #include "gimpwidgets-utils.h"
 
 #include "gimp-intl.h"
@@ -1277,3 +1279,23 @@ gimp_print_event (const GdkEvent *event)
 
   return str;
 }
+
+void
+gimp_session_write_position (GimpConfigWriter *writer,
+                             gint              position)
+{
+  GimpSessionInfoClass *klass;
+  gint                  pos_to_write;
+
+  klass = g_type_class_ref (GIMP_TYPE_SESSION_INFO);
+
+  pos_to_write =
+    gimp_session_info_class_apply_position_accuracy (klass,
+                                                     position);
+
+  gimp_config_writer_open (writer, "position");
+  gimp_config_writer_printf (writer, "%d", pos_to_write);
+  gimp_config_writer_close (writer);
+
+  g_type_class_unref (klass);
+}
diff --git a/app/widgets/gimpwidgets-utils.h b/app/widgets/gimpwidgets-utils.h
index 0cde3ca..8a2769c 100644
--- a/app/widgets/gimpwidgets-utils.h
+++ b/app/widgets/gimpwidgets-utils.h
@@ -93,6 +93,8 @@ void              gimp_tools_set_tool_options_gui  (GimpToolOptions      *tool_o
 void              gimp_widget_flush_expose         (GtkWidget            *widget);
 
 const gchar     * gimp_print_event                 (const GdkEvent       *event);
+void              gimp_session_write_position      (GimpConfigWriter     *writer,
+                                                    gint                  position);
 
 
 #endif /* __GIMP_WIDGETS_UTILS_H__ */



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