[gimp] app: Add the concept of 'side' of a dock



commit 2d5ffd4f2e317e72c23a9e11d291eba32d609321
Author: Martin Nordholts <martinn src gnome org>
Date:   Sat May 14 16:00:00 2011 +0200

    app: Add the concept of 'side' of a dock
    
    Add GimpDockContainer::get_dock_side() and write that info in the
    sessionrc file. In single-window mode, a dock can be either on the
    left or right side of the image window. In a dock window however, the
    side concept doesn't apply ('side' has nothing to do with what column
    a dock is in in a GimpDockColumns)

 app/widgets/gimpdockcontainer.c    |   25 +++++++++++++++++
 app/widgets/gimpdockcontainer.h    |   26 ++++++++++--------
 app/widgets/gimpdockwindow.c       |   17 ++++++++++++
 app/widgets/gimpsessioninfo-dock.c |   51 ++++++++++++++++++++++++++++++++++++
 app/widgets/gimpsessioninfo-dock.h |    9 +++++-
 5 files changed, 115 insertions(+), 13 deletions(-)
---
diff --git a/app/widgets/gimpdockcontainer.c b/app/widgets/gimpdockcontainer.c
index 9540495..15c18dd 100644
--- a/app/widgets/gimpdockcontainer.c
+++ b/app/widgets/gimpdockcontainer.c
@@ -135,3 +135,28 @@ gimp_dock_container_add_dock (GimpDockContainer   *container,
                      dock,
                      dock_info);
 }
+
+/**
+ * gimp_dock_container_get_dock_side:
+ * @container: A #GimpDockContainer
+ * @dock:      A #GimpDock
+ *
+ * Returns: What side @dock is in in @container, either
+ *          GIMP_ALIGN_LEFT or GIMP_ALIGN_RIGHT, or -1 if the side
+ *          concept is not applicable.
+ **/
+GimpAlignmentType
+gimp_dock_container_get_dock_side (GimpDockContainer   *container,
+                                   GimpDock            *dock)
+{
+  GimpDockContainerInterface *iface;
+
+  g_return_val_if_fail (GIMP_IS_DOCK_CONTAINER (container), -1);
+
+  iface = GIMP_DOCK_CONTAINER_GET_INTERFACE (container);
+
+  if (iface->get_dock_side)
+    return iface->get_dock_side (container, dock);
+
+  return -1;
+}
diff --git a/app/widgets/gimpdockcontainer.h b/app/widgets/gimpdockcontainer.h
index 86ffa6e..4535fd3 100644
--- a/app/widgets/gimpdockcontainer.h
+++ b/app/widgets/gimpdockcontainer.h
@@ -35,20 +35,24 @@ struct _GimpDockContainerInterface
   GTypeInterface base_iface;
 
   /*  virtual functions  */
-  GList         * (* get_docks)         (GimpDockContainer   *container);
-  GimpUIManager * (* get_ui_manager)    (GimpDockContainer   *container);
-  void            (* add_dock)          (GimpDockContainer   *container,
-                                         GimpDock            *dock,
-                                         GimpSessionInfoDock *dock_info);
+  GList           * (* get_docks)         (GimpDockContainer   *container);
+  GimpUIManager   * (* get_ui_manager)    (GimpDockContainer   *container);
+  void              (* add_dock)          (GimpDockContainer   *container,
+                                           GimpDock            *dock,
+                                           GimpSessionInfoDock *dock_info);
+  GimpAlignmentType (* get_dock_side)     (GimpDockContainer   *container,
+                                           GimpDock            *dock);
 };
 
 
-GType           gimp_dock_container_interface_get_type         (void) G_GNUC_CONST;
-GList         * gimp_dock_container_get_docks                  (GimpDockContainer   *container);
-GimpUIManager * gimp_dock_container_get_ui_manager             (GimpDockContainer   *container);
-void            gimp_dock_container_add_dock                   (GimpDockContainer   *container,
-                                                                GimpDock            *dock,
-                                                                GimpSessionInfoDock *dock_info);
+GType              gimp_dock_container_interface_get_type  (void) G_GNUC_CONST;
+GList            * gimp_dock_container_get_docks           (GimpDockContainer   *container);
+GimpUIManager    * gimp_dock_container_get_ui_manager      (GimpDockContainer   *container);
+void               gimp_dock_container_add_dock            (GimpDockContainer   *container,
+                                                            GimpDock            *dock,
+                                                            GimpSessionInfoDock *dock_info);
+GimpAlignmentType  gimp_dock_container_get_dock_side       (GimpDockContainer   *container,
+                                                            GimpDock            *dock);
 
 
 #endif  /*  __GIMP_DOCK_CONTAINER_H__  */
diff --git a/app/widgets/gimpdockwindow.c b/app/widgets/gimpdockwindow.c
index dca6bd3..dea0232 100644
--- a/app/widgets/gimpdockwindow.c
+++ b/app/widgets/gimpdockwindow.c
@@ -130,6 +130,9 @@ static GimpUIManager * gimp_dock_window_get_ui_manager            (GimpDockConta
 static void            gimp_dock_window_add_dock_from_session     (GimpDockContainer          *dock_container,
                                                                    GimpDock                   *dock,
                                                                    GimpSessionInfoDock        *dock_info);
+static GimpAlignmentType
+                       gimp_dock_window_get_dock_side             (GimpDockContainer          *dock_container,
+                                                                   GimpDock                   *dock);
 static gboolean        gimp_dock_window_should_add_to_recent      (GimpDockWindow             *dock_window);
 static void            gimp_dock_window_display_changed           (GimpDockWindow             *dock_window,
                                                                    GimpObject                 *display,
@@ -266,6 +269,7 @@ gimp_dock_window_dock_container_iface_init (GimpDockContainerInterface *iface)
   iface->get_docks      = gimp_dock_window_get_docks;
   iface->get_ui_manager = gimp_dock_window_get_ui_manager;
   iface->add_dock       = gimp_dock_window_add_dock_from_session;
+  iface->get_dock_side  = gimp_dock_window_get_dock_side;
 }
 
 static void
@@ -721,6 +725,19 @@ gimp_dock_window_add_dock_from_session (GimpDockContainer   *dock_container,
                              -1 /*index*/);
 }
 
+static GimpAlignmentType
+gimp_dock_window_get_dock_side (GimpDockContainer *dock_container,
+                                GimpDock          *dock)
+{
+  g_return_val_if_fail (GIMP_IS_DOCK_WINDOW (dock_container), -1);
+  g_return_val_if_fail (GIMP_IS_DOCK (dock), -1);
+
+  /* A GimpDockWindow don't have docks on different sides, it's just
+   * one set of columns
+   */
+  return -1;
+}
+
 /**
  * gimp_dock_window_should_add_to_recent:
  * @dock_window:
diff --git a/app/widgets/gimpsessioninfo-dock.c b/app/widgets/gimpsessioninfo-dock.c
index 3c97f0b..350e99a 100644
--- a/app/widgets/gimpsessioninfo-dock.c
+++ b/app/widgets/gimpsessioninfo-dock.c
@@ -20,6 +20,8 @@
 
 #include "config.h"
 
+#include <string.h>
+
 #include <gtk/gtk.h>
 
 #include "libgimpconfig/gimpconfig.h"
@@ -41,10 +43,31 @@
 
 enum
 {
+  SESSION_INFO_SIDE,
   SESSION_INFO_BOOK
 };
 
 
+static GimpAlignmentType gimp_session_info_dock_get_side (GimpDock *dock);
+
+
+static GimpAlignmentType
+gimp_session_info_dock_get_side (GimpDock *dock)
+{
+  GimpAlignmentType result   = -1;
+  GtkWidget        *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (dock));
+
+  if (GIMP_IS_DOCK_CONTAINER (toplevel))
+    {
+      GimpDockContainer *container = GIMP_DOCK_CONTAINER (toplevel);
+
+      result = gimp_dock_container_get_dock_side (container, dock);
+    }
+
+  return result;
+}
+
+
 /*  public functions  */
 
 GimpSessionInfoDock *
@@ -54,6 +77,7 @@ gimp_session_info_dock_new (const gchar *dock_type)
 
   dock_info = g_slice_new0 (GimpSessionInfoDock);
   dock_info->dock_type = g_strdup (dock_type);
+  dock_info->side      = -1;
 
   return dock_info;
 }
@@ -90,6 +114,16 @@ gimp_session_info_dock_serialize (GimpConfigWriter    *writer,
 
   gimp_config_writer_open (writer, dock_info->dock_type);
 
+  if (dock_info->side != -1)
+    {
+      const char *side_text =
+        dock_info->side == GIMP_ALIGN_LEFT ? "left" : "right";
+      
+      gimp_config_writer_open (writer, "side");
+      gimp_config_writer_print (writer, side_text, strlen (side_text));
+      gimp_config_writer_close (writer);
+    }
+
   for (list = dock_info->books; list; list = g_list_next (list))
     gimp_session_info_book_serialize (writer, list->data);
 
@@ -107,6 +141,8 @@ gimp_session_info_dock_deserialize (GScanner             *scanner,
   g_return_val_if_fail (scanner != NULL, G_TOKEN_LEFT_PAREN);
   g_return_val_if_fail (dock_info != NULL, G_TOKEN_LEFT_PAREN);
 
+  g_scanner_scope_add_symbol (scanner, scope, "side",
+                              GINT_TO_POINTER (SESSION_INFO_SIDE));
   g_scanner_scope_add_symbol (scanner, scope, "book",
                               GINT_TO_POINTER (SESSION_INFO_BOOK));
 
@@ -129,6 +165,19 @@ gimp_session_info_dock_deserialize (GScanner             *scanner,
             {
               GimpSessionInfoBook *book;
 
+            case SESSION_INFO_SIDE:
+              token = G_TOKEN_IDENTIFIER;
+              if (g_scanner_peek_next_token (scanner) != token)
+                break;
+
+              g_scanner_get_next_token (scanner);
+
+              if (strcmp ("left", scanner->value.v_identifier) == 0)
+                (*dock_info)->side = GIMP_ALIGN_LEFT;
+              else
+                (*dock_info)->side = GIMP_ALIGN_RIGHT;
+              break;
+
             case SESSION_INFO_BOOK:
               g_scanner_set_scope (scanner, scope + 1);
               token = gimp_session_info_book_deserialize (scanner, scope + 1,
@@ -160,6 +209,7 @@ gimp_session_info_dock_deserialize (GScanner             *scanner,
     }
 
   g_scanner_scope_remove_symbol (scanner, scope, "book");
+  g_scanner_scope_remove_symbol (scanner, scope, "side");
 
   return token;
 }
@@ -186,6 +236,7 @@ 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);
 
   return dock_info;
 }
diff --git a/app/widgets/gimpsessioninfo-dock.h b/app/widgets/gimpsessioninfo-dock.h
index 3738c6f..45dae3d 100644
--- a/app/widgets/gimpsessioninfo-dock.h
+++ b/app/widgets/gimpsessioninfo-dock.h
@@ -32,10 +32,15 @@ struct _GimpSessionInfoDock
   /* Type of dock, written to/read from sessionrc. E.g. 'gimp-dock' or
    * 'gimp-toolbox'
    */
-  gchar *dock_type;
+  gchar             *dock_type;
+
+  /* What side this dock is in in single-window mode. Either
+   * GIMP_ARRANGE_LEFT, GIMP_ARRANGE_RIGHT or -1.
+   */
+  GimpAlignmentType  side;
 
   /*  list of GimpSessionInfoBook  */
-  GList *books;
+  GList             *books;
 };
 
 GimpSessionInfoDock * gimp_session_info_dock_new         (const gchar          *dock_type);



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