[gimp] app: Only show active dockables in dock window titles



commit 520da707c11e05d156a9a090eb8821b09e9fcca0
Author: Martin Nordholts <martinn src gnome org>
Date:   Sat Mar 13 20:02:55 2010 +0100

    app: Only show active dockables in dock window titles
    
    Refactor stuff a bit so that the dock window description can be both
    short and long. The short version only have the active dockables, and
    the long version have all the dockables in the description string. We
    use the short version for the window title and the long version for
    the Recently Closed Docks menu items.

 app/widgets/gimpdock.c       |   42 ++++++++++++++++++++++++++++++++++++----
 app/widgets/gimpdock.h       |    6 +++-
 app/widgets/gimpdockwindow.c |   43 ++++++++++++++++++++++++++---------------
 app/widgets/gimptoolbox.c    |   15 +++++++++++--
 4 files changed, 80 insertions(+), 26 deletions(-)
---
diff --git a/app/widgets/gimpdock.c b/app/widgets/gimpdock.c
index c4fd026..26f940c 100644
--- a/app/widgets/gimpdock.c
+++ b/app/widgets/gimpdock.c
@@ -72,7 +72,8 @@ struct _GimpDockPrivate
 static void              gimp_dock_style_set              (GtkWidget    *widget,
                                                            GtkStyle     *prev_style);
 static void              gimp_dock_destroy                (GtkObject    *object);
-static gchar           * gimp_dock_real_get_description   (GimpDock     *dock);
+static gchar           * gimp_dock_real_get_description   (GimpDock     *dock,
+                                                           gboolean      complete);
 static void              gimp_dock_real_book_added        (GimpDock     *dock,
                                                            GimpDockbook *dockbook);
 static void              gimp_dock_real_book_removed      (GimpDock     *dock,
@@ -245,7 +246,8 @@ gimp_dock_destroy (GtkObject *object)
 }
 
 static gchar *
-gimp_dock_real_get_description (GimpDock *dock)
+gimp_dock_real_get_description (GimpDock *dock,
+                                gboolean  complete)
 {
   GString *desc;
   GList   *list;
@@ -260,7 +262,22 @@ gimp_dock_real_get_description (GimpDock *dock)
       GList        *children;
       GList        *child;
 
-      children = gtk_container_get_children (GTK_CONTAINER (dockbook));
+      if (complete)
+        {
+          /* Include all dockables */
+          children = gtk_container_get_children (GTK_CONTAINER (dockbook));
+        }
+      else
+        {
+          GtkWidget *dockable = NULL;
+          gint       page_num = 0;
+
+          page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (dockbook));
+          dockable = gtk_notebook_get_nth_page (GTK_NOTEBOOK (dockbook), page_num);
+
+          /* Only include active dockables */
+          children = g_list_append (NULL, dockable);
+        }
 
       for (child = children; child; child = g_list_next (child))
         {
@@ -285,12 +302,18 @@ static void
 gimp_dock_real_book_added (GimpDock     *dock,
                            GimpDockbook *dockbook)
 {
+  g_signal_connect_object (dockbook, "switch-page",
+                           G_CALLBACK (gimp_dock_invalidate_description),
+                           dock, G_CONNECT_SWAPPED);
 }
 
 static void
 gimp_dock_real_book_removed (GimpDock     *dock,
                              GimpDockbook *dockbook)
 {
+  g_signal_handlers_disconnect_by_func (dockbook,
+                                        gimp_dock_invalidate_description,
+                                        dock);
 }
 
 static void
@@ -367,13 +390,22 @@ gimp_dock_get_dock_columns (GimpDock *dock)
 
 /*  public functions  */
 
+/**
+ * gimp_dock_get_description:
+ * @dock:
+ * @complete: If %TRUE, only includes the active dockables, i.e. not the
+ *            dockables in a non-active GtkNotebook tab
+ *
+ * Returns: A string describing the contents of the dock.
+ **/
 gchar *
-gimp_dock_get_description (GimpDock *dock)
+gimp_dock_get_description (GimpDock *dock,
+                           gboolean  complete)
 {
   g_return_val_if_fail (GIMP_IS_DOCK (dock), NULL);
 
   if (GIMP_DOCK_GET_CLASS (dock)->get_description)
-    return GIMP_DOCK_GET_CLASS (dock)->get_description (dock);
+    return GIMP_DOCK_GET_CLASS (dock)->get_description (dock, complete);
 
   return NULL;
 }
diff --git a/app/widgets/gimpdock.h b/app/widgets/gimpdock.h
index f6d4339..00e1ddc 100644
--- a/app/widgets/gimpdock.h
+++ b/app/widgets/gimpdock.h
@@ -64,7 +64,8 @@ struct _GimpDockClass
   GtkVBoxClass  parent_class;
 
   /*  virtual functions  */
-  gchar * (* get_description)         (GimpDock       *dock);
+  gchar * (* get_description)         (GimpDock       *dock,
+                                       gboolean        complete);
   void    (* set_host_geometry_hints) (GimpDock       *dock,
                                        GtkWindow      *window);
 
@@ -80,7 +81,8 @@ struct _GimpDockClass
 
 GType               gimp_dock_get_type                (void) G_GNUC_CONST;
 
-gchar             * gimp_dock_get_description         (GimpDock       *dock);
+gchar             * gimp_dock_get_description         (GimpDock       *dock,
+                                                       gboolean        complete);
 void                gimp_dock_set_host_geometry_hints (GimpDock       *dock,
                                                        GtkWindow      *window);
 void                gimp_dock_invalidate_geometry     (GimpDock       *dock);
diff --git a/app/widgets/gimpdockwindow.c b/app/widgets/gimpdockwindow.c
index deee286..580729f 100644
--- a/app/widgets/gimpdockwindow.c
+++ b/app/widgets/gimpdockwindow.c
@@ -137,6 +137,8 @@ static void      gimp_dock_window_image_flush             (GimpImage
                                                            GimpDockWindow        *dock_window);
 static void      gimp_dock_window_update_title            (GimpDockWindow        *dock_window);
 static gboolean  gimp_dock_window_update_title_idle       (GimpDockWindow        *dock_window);
+static gchar *   gimp_dock_window_get_description         (GimpDockWindow        *dock_window,
+                                                           gboolean               complete);
 static void      gimp_dock_window_dock_removed            (GimpDockWindow        *dock_window,
                                                            GimpDock              *dock,
                                                            GimpDockColumns       *dock_columns);
@@ -626,6 +628,7 @@ gimp_dock_window_delete_event (GtkWidget   *widget,
   GimpSessionInfo        *info        = NULL;
   const gchar            *entry_name  = NULL;
   GimpDialogFactoryEntry *entry       = NULL;
+  gchar                  *name        = NULL;
 
   /* Don't add docks with just a singe dockable to the list of
    * recently closed dock since those can be brought back through the
@@ -636,8 +639,9 @@ gimp_dock_window_delete_event (GtkWidget   *widget,
 
   info = gimp_session_info_new ();
 
-  gimp_object_set_name (GIMP_OBJECT (info),
-                        gtk_window_get_title (GTK_WINDOW (dock_window)));
+  name = gimp_dock_window_get_description (dock_window, TRUE /*complete*/);
+  gimp_object_set_name (GIMP_OBJECT (info), name);
+  g_free (name);
 
   gimp_session_info_set_widget (info, GTK_WIDGET (dock_window));
   gimp_session_info_get_info (info);
@@ -730,29 +734,36 @@ gimp_dock_window_update_title (GimpDockWindow *dock_window)
 static gboolean
 gimp_dock_window_update_title_idle (GimpDockWindow *dock_window)
 {
-  GString *complete_title = g_string_new ("");
-  GList   *iter           = NULL;
+  gchar *desc = gimp_dock_window_get_description (dock_window,
+                                                  FALSE /*complete*/);
+  if (desc != NULL)
+    gtk_window_set_title (GTK_WINDOW (dock_window), desc);
+
+  dock_window->p->update_title_idle_id = 0;
+
+  return FALSE;
+}
+
+static gchar *
+gimp_dock_window_get_description (GimpDockWindow *dock_window,
+                                  gboolean        complete)
+{
+  GString *complete_desc = g_string_new (NULL);
+  GList   *iter          = NULL;
 
   for (iter = gimp_dock_window_get_docks (dock_window);
        iter;
        iter = g_list_next (iter))
     {
-      gchar *title = gimp_dock_get_description (GIMP_DOCK (iter->data));
-      g_string_append (complete_title, title);
-      g_free (title);
+      gchar *desc = gimp_dock_get_description (GIMP_DOCK (iter->data), complete);
+      g_string_append (complete_desc, desc);
+      g_free (desc);
 
       if (g_list_next (iter))
-        g_string_append (complete_title, GIMP_DOCK_COLUMN_SEPARATOR);
+        g_string_append (complete_desc, GIMP_DOCK_COLUMN_SEPARATOR);
     }
 
-  if (complete_title->len > 0)
-    gtk_window_set_title (GTK_WINDOW (dock_window), complete_title->str);
-
-  g_string_free (complete_title, TRUE /*free_segment*/);
-
-  dock_window->p->update_title_idle_id = 0;
-
-  return FALSE;
+  return g_string_free (complete_desc, FALSE /*free_segment*/);
 }
 
 static void
diff --git a/app/widgets/gimptoolbox.c b/app/widgets/gimptoolbox.c
index ae7125a..2f3c41e 100644
--- a/app/widgets/gimptoolbox.c
+++ b/app/widgets/gimptoolbox.c
@@ -132,7 +132,8 @@ static gboolean    gimp_toolbox_drag_drop               (GtkWidget             *
                                                          gint                   y,
                                                          guint                  time,
                                                          GimpToolbox           *toolbox);
-static gchar     * gimp_toolbox_get_description         (GimpDock              *dock);
+static gchar     * gimp_toolbox_get_description         (GimpDock              *dock,
+                                                         gboolean               complete);
 static void        gimp_toolbox_set_host_geometry_hints (GimpDock              *dock,
                                                          GtkWindow             *window);
 static void        gimp_toolbox_book_added              (GimpDock              *dock,
@@ -767,10 +768,12 @@ gimp_toolbox_drag_drop (GtkWidget      *widget,
 }
 
 static gchar *
-gimp_toolbox_get_description (GimpDock *dock)
+gimp_toolbox_get_description (GimpDock *dock,
+                              gboolean  complete)
 {
   GString *desc      = g_string_new (_("Toolbox"));
-  gchar   *dock_desc = GIMP_DOCK_CLASS (parent_class)->get_description (dock);
+  gchar   *dock_desc = GIMP_DOCK_CLASS (parent_class)->get_description (dock,
+                                                                        complete);
 
   if (dock_desc && strlen (dock_desc) > 0)
     {
@@ -787,6 +790,9 @@ static void
 gimp_toolbox_book_added (GimpDock     *dock,
                          GimpDockbook *dockbook)
 {
+  if (GIMP_DOCK_CLASS (gimp_toolbox_parent_class)->book_added)
+    GIMP_DOCK_CLASS (gimp_toolbox_parent_class)->book_added (dock, dockbook);
+  
   if (g_list_length (gimp_dock_get_dockbooks (dock)) == 1)
     {
       gimp_dock_invalidate_geometry (dock);
@@ -797,6 +803,9 @@ static void
 gimp_toolbox_book_removed (GimpDock     *dock,
                            GimpDockbook *dockbook)
 {
+  if (GIMP_DOCK_CLASS (gimp_toolbox_parent_class)->book_removed)
+    GIMP_DOCK_CLASS (gimp_toolbox_parent_class)->book_removed (dock, dockbook);
+
   if (g_list_length (gimp_dock_get_dockbooks (dock)) == 0 &&
       ! (GTK_OBJECT_FLAGS (dock) & GTK_IN_DESTRUCTION))
     {



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