[gimp] app: Add and use GimpDockWindow window title infrastructure



commit a23a220d60c34cc62fc98178fb04c27dd05ff61e
Author: Martin Nordholts <martinn src gnome org>
Date:   Sun Sep 13 13:14:18 2009 +0200

    app: Add and use GimpDockWindow window title infrastructure
    
    Add a "title-invalidated" signal to GimpDock and a virtual function
    GimpDock::get_title(). When GimpDocks have a state change that their
    title depends on they call gimp_dock_invalidate_title(). The
    GimpDockWindow listens to this signal and update its window title
    using GimpDock::get_title() in an idle handler.

 app/widgets/gimpdock.c       |   30 ++++++++++++++++++++++++++
 app/widgets/gimpdock.h       |   22 +++++++++++--------
 app/widgets/gimpdockwindow.c |   47 ++++++++++++++++++++++++++++++++++++++++++
 app/widgets/gimpmenudock.c   |   41 ++++++++----------------------------
 app/widgets/gimpmenudock.h   |    2 -
 app/widgets/gimptoolbox.c    |    9 +++++++-
 6 files changed, 107 insertions(+), 44 deletions(-)
---
diff --git a/app/widgets/gimpdock.c b/app/widgets/gimpdock.c
index 9cadac8..e1d3eef 100644
--- a/app/widgets/gimpdock.c
+++ b/app/widgets/gimpdock.c
@@ -50,6 +50,7 @@ enum
 {
   BOOK_ADDED,
   BOOK_REMOVED,
+  TITLE_INVALIDATED,
   LAST_SIGNAL
 };
 
@@ -116,6 +117,15 @@ gimp_dock_class_init (GimpDockClass *klass)
                   G_TYPE_NONE, 1,
                   GIMP_TYPE_DOCKBOOK);
 
+  dock_signals[TITLE_INVALIDATED] =
+    g_signal_new ("title-invalidated",
+                  G_TYPE_FROM_CLASS (klass),
+                  G_SIGNAL_RUN_FIRST,
+                  G_STRUCT_OFFSET (GimpDockClass, title_invalidated),
+                  NULL, NULL,
+                  gimp_marshal_VOID__VOID,
+                  G_TYPE_NONE, 0);
+
   object_class->set_property    = gimp_dock_set_property;
   object_class->get_property    = gimp_dock_get_property;
 
@@ -124,6 +134,7 @@ gimp_dock_class_init (GimpDockClass *klass)
   klass->setup                  = NULL;
   klass->book_added             = gimp_dock_real_book_added;
   klass->book_removed           = gimp_dock_real_book_removed;
+  klass->title_invalidated      = NULL;
 
   g_object_class_install_property (object_class, PROP_CONTEXT,
                                    g_param_spec_object ("context", NULL, NULL,
@@ -280,6 +291,25 @@ gimp_dock_get_aux_info (GimpDock *dock)
   return NULL;
 }
 
+gchar *
+gimp_dock_get_title (GimpDock *dock)
+{
+  g_return_val_if_fail (GIMP_IS_DOCK (dock), NULL);
+  
+  if (GIMP_DOCK_GET_CLASS (dock)->get_title)
+    return GIMP_DOCK_GET_CLASS (dock)->get_title (dock);
+
+  return NULL;
+}
+
+void
+gimp_dock_invalidate_title (GimpDock *dock)
+{
+  g_return_if_fail (GIMP_IS_DOCK (dock));
+  
+  g_signal_emit (dock, dock_signals[TITLE_INVALIDATED], 0);
+}
+
 GimpContext *
 gimp_dock_get_context (GimpDock *dock)
 {
diff --git a/app/widgets/gimpdock.h b/app/widgets/gimpdock.h
index f0365db..62ee33e 100644
--- a/app/widgets/gimpdock.h
+++ b/app/widgets/gimpdock.h
@@ -51,17 +51,19 @@ struct _GimpDockClass
   GimpDockWindowClass  parent_class;
 
   /*  virtual functions  */
-  void    (* setup)        (GimpDock       *dock,
-                            const GimpDock *template);
-  void    (* set_aux_info) (GimpDock       *dock,
-                            GList          *aux_info);
-  GList * (* get_aux_info) (GimpDock       *dock);
+  void    (* setup)             (GimpDock       *dock,
+                                 const GimpDock *template);
+  void    (* set_aux_info)      (GimpDock       *dock,
+                                 GList          *aux_info);
+  GList * (* get_aux_info)      (GimpDock       *dock);
+  gchar * (* get_title)         (GimpDock       *dock);
 
   /*  signals  */
-  void    (* book_added)   (GimpDock       *dock,
-                            GimpDockbook   *dockbook);
-  void    (* book_removed) (GimpDock       *dock,
-                            GimpDockbook   *dockbook);
+  void    (* book_added)        (GimpDock       *dock,
+                                 GimpDockbook   *dockbook);
+  void    (* book_removed)      (GimpDock       *dock,
+                                 GimpDockbook   *dockbook);
+  void    (* title_invalidated) (GimpDock       *dock);
 };
 
 
@@ -72,6 +74,8 @@ void                gimp_dock_setup              (GimpDock       *dock,
 void                gimp_dock_set_aux_info       (GimpDock       *dock,
                                                   GList          *aux_info);
 GList             * gimp_dock_get_aux_info       (GimpDock       *dock);
+gchar             * gimp_dock_get_title          (GimpDock       *dock);
+void                gimp_dock_invalidate_title   (GimpDock       *dock);
 GimpContext       * gimp_dock_get_context        (GimpDock       *dock);
 GimpDialogFactory * gimp_dock_get_dialog_factory (GimpDock       *dock);
 GList             * gimp_dock_get_dockbooks      (GimpDock       *dock);
diff --git a/app/widgets/gimpdockwindow.c b/app/widgets/gimpdockwindow.c
index 888d351..8fa4de2 100644
--- a/app/widgets/gimpdockwindow.c
+++ b/app/widgets/gimpdockwindow.c
@@ -72,6 +72,8 @@ struct _GimpDockWindowPrivate
   GimpUIManager     *ui_manager;
   GQuark             image_flush_handler_id;
 
+  guint              update_title_idle_id;
+
   gint               ID;
 };
 
@@ -101,6 +103,8 @@ static void       gimp_dock_window_image_changed     (GimpDockWindow        *doc
 static void       gimp_dock_window_image_flush       (GimpImage             *image,
                                                       gboolean               invalidate_preview,
                                                       GimpDockWindow        *dock_window);
+static void       gimp_dock_window_update_title      (GimpDockWindow        *dock_window);
+static gboolean   gimp_dock_window_update_title_idle (GimpDockWindow        *dock_window);
 
 
 G_DEFINE_TYPE (GimpDockWindow, gimp_dock_window, GIMP_TYPE_WINDOW)
@@ -174,6 +178,7 @@ gimp_dock_window_init (GimpDockWindow *dock_window)
   dock_window->p->ui_manager             = NULL;
   dock_window->p->image_flush_handler_id = 0;
   dock_window->p->ID                     = dock_ID++;
+  dock_window->p->update_title_idle_id   = 0;
 
   /* Some common initialization for all dock windows */
   gtk_window_set_resizable (GTK_WINDOW (dock_window), TRUE);
@@ -194,6 +199,7 @@ gimp_dock_window_constructor (GType                  type,
   GimpDockWindow *dock_window;
   GimpGuiConfig  *config;
   GtkAccelGroup  *accel_group;
+  GimpDock       *dock;
 
   /* Init */
   object      = G_OBJECT_CLASS (parent_class)->constructor (type, n_params, params);
@@ -230,6 +236,14 @@ gimp_dock_window_constructor (GType                  type,
                                 G_CALLBACK (gimp_dock_window_image_flush),
                                 dock_window);
 
+  /* Update window title now and when docks title is invalidated */
+  gimp_dock_window_update_title (dock_window);
+  dock = gimp_dock_window_get_dock (dock_window);
+  g_signal_connect_object (dock, "title-invalidated",
+                           G_CALLBACK (gimp_dock_window_update_title),
+                           dock_window,
+                           G_CONNECT_SWAPPED);
+
   /* Done! */
   return object;
 }
@@ -239,6 +253,12 @@ gimp_dock_window_dispose (GObject *object)
 {
   GimpDockWindow *dock_window = GIMP_DOCK_WINDOW (object);
 
+  if (dock_window->p->update_title_idle_id)
+    {
+      g_source_remove (dock_window->p->update_title_idle_id);
+      dock_window->p->update_title_idle_id = 0;
+    }
+
   if (dock_window->p->image_flush_handler_id)
     {
       gimp_container_remove_handler (dock_window->p->context->gimp->images,
@@ -457,6 +477,33 @@ gimp_dock_window_image_flush (GimpImage      *image,
     }
 }
 
+static void
+gimp_dock_window_update_title (GimpDockWindow *dock_window)
+{
+  if (dock_window->p->update_title_idle_id)
+    g_source_remove (dock_window->p->update_title_idle_id);
+
+  dock_window->p->update_title_idle_id =
+    g_idle_add ((GSourceFunc) gimp_dock_window_update_title_idle,
+                dock_window);
+}
+
+static gboolean
+gimp_dock_window_update_title_idle (GimpDockWindow *dock_window)
+{
+  GimpDock *dock  = gimp_dock_window_get_dock (dock_window);
+  gchar    *title = gimp_dock_get_title (dock);
+
+  if (title)
+    gtk_window_set_title (GTK_WINDOW (dock_window), title);
+
+  g_free (title);
+
+  dock_window->p->update_title_idle_id = 0;
+
+  return FALSE;
+}
+
 gint
 gimp_dock_window_get_id (GimpDockWindow *dock_window)
 {
diff --git a/app/widgets/gimpmenudock.c b/app/widgets/gimpmenudock.c
index cf2aff2..0aa32a1 100644
--- a/app/widgets/gimpmenudock.c
+++ b/app/widgets/gimpmenudock.c
@@ -64,6 +64,7 @@ static void   gimp_menu_dock_setup                   (GimpDock       *dock,
 static void   gimp_menu_dock_set_aux_info            (GimpDock       *dock,
                                                       GList          *aux_info);
 static GList *gimp_menu_dock_get_aux_info            (GimpDock       *dock);
+static gchar *gimp_menu_dock_get_title               (GimpDock       *dock);
 static void   gimp_menu_dock_book_added              (GimpDock       *dock,
                                                       GimpDockbook   *dockbook);
 static void   gimp_menu_dock_book_removed            (GimpDock       *dock,
@@ -72,7 +73,6 @@ static void   gimp_menu_dock_book_removed            (GimpDock       *dock,
 static void   gimp_menu_dock_dockbook_changed        (GimpDockbook   *dockbook,
                                                       GimpDockable   *dockable,
                                                       GimpMenuDock   *dock);
-static void   gimp_menu_dock_update_title            (GimpMenuDock   *dock);
 
 static void   gimp_menu_dock_factory_display_changed (GimpContext    *context,
                                                       GimpObject     *display,
@@ -109,6 +109,7 @@ gimp_menu_dock_class_init (GimpMenuDockClass *klass)
   dock_class->setup         = gimp_menu_dock_setup;
   dock_class->set_aux_info  = gimp_menu_dock_set_aux_info;
   dock_class->get_aux_info  = gimp_menu_dock_get_aux_info;
+  dock_class->get_title     = gimp_menu_dock_get_title;
   dock_class->book_added    = gimp_menu_dock_book_added;
   dock_class->book_removed  = gimp_menu_dock_book_removed;
 
@@ -136,7 +137,6 @@ gimp_menu_dock_init (GimpMenuDock *dock)
   dock->display_container    = NULL;
   dock->show_image_menu      = FALSE;
   dock->auto_follow_active   = TRUE;
-  dock->update_title_idle_id = 0;
 
   hbox = gtk_hbox_new (FALSE, 2);
   gtk_box_pack_start (GTK_BOX (gimp_dock_get_main_vbox (GIMP_DOCK (dock))), hbox,
@@ -192,12 +192,6 @@ gimp_menu_dock_destroy (GtkObject *object)
 {
   GimpMenuDock *dock = GIMP_MENU_DOCK (object);
 
-  if (dock->update_title_idle_id)
-    {
-      g_source_remove (dock->update_title_idle_id);
-      dock->update_title_idle_id = 0;
-    }
-
   /*  remove the image menu and the auto button manually here because
    *  of weird cross-connections with GimpDock's context
    */
@@ -348,7 +342,7 @@ gimp_menu_dock_book_added (GimpDock     *dock,
                     G_CALLBACK (gimp_menu_dock_dockbook_changed),
                     dock);
 
-  gimp_menu_dock_update_title (GIMP_MENU_DOCK (dock));
+  gimp_dock_invalidate_title (GIMP_DOCK (dock));
 
   GIMP_DOCK_CLASS (parent_class)->book_added (dock, dockbook);
 }
@@ -361,7 +355,7 @@ gimp_menu_dock_book_removed (GimpDock     *dock,
                                         gimp_menu_dock_dockbook_changed,
                                         dock);
 
-  gimp_menu_dock_update_title (GIMP_MENU_DOCK (dock));
+  gimp_dock_invalidate_title (GIMP_DOCK (dock));
 
   GIMP_DOCK_CLASS (parent_class)->book_removed (dock, dockbook);
 }
@@ -482,18 +476,18 @@ gimp_menu_dock_dockbook_changed (GimpDockbook *dockbook,
                                  GimpDockable *dockable,
                                  GimpMenuDock *dock)
 {
-  gimp_menu_dock_update_title (dock);
+  gimp_dock_invalidate_title (GIMP_DOCK (dock));
 }
 
-static gboolean
-gimp_menu_dock_update_title_idle (GimpMenuDock *menu_dock)
+static gchar *
+gimp_menu_dock_get_title (GimpDock *dock)
 {
   GString *title;
   GList   *list;
 
   title = g_string_new (NULL);
 
-  for (list = gimp_dock_get_dockbooks (GIMP_DOCK (menu_dock));
+  for (list = gimp_dock_get_dockbooks (dock);
        list;
        list = g_list_next (list))
     {
@@ -519,24 +513,7 @@ gimp_menu_dock_update_title_idle (GimpMenuDock *menu_dock)
         g_string_append (title, " - ");
     }
 
-  gtk_window_set_title (GTK_WINDOW (menu_dock), title->str);
-
-  g_string_free (title, TRUE);
-
-  menu_dock->update_title_idle_id = 0;
-
-  return FALSE;
-}
-
-static void
-gimp_menu_dock_update_title (GimpMenuDock *menu_dock)
-{
-  if (menu_dock->update_title_idle_id)
-    g_source_remove (menu_dock->update_title_idle_id);
-
-  menu_dock->update_title_idle_id =
-    g_idle_add ((GSourceFunc) gimp_menu_dock_update_title_idle,
-                menu_dock);
+  return g_string_free (title, FALSE);
 }
 
 static void
diff --git a/app/widgets/gimpmenudock.h b/app/widgets/gimpmenudock.h
index f7b628a..f3f1e3a 100644
--- a/app/widgets/gimpmenudock.h
+++ b/app/widgets/gimpmenudock.h
@@ -47,8 +47,6 @@ struct _GimpMenuDock
 
   GtkWidget     *image_combo;
   GtkWidget     *auto_button;
-
-  guint          update_title_idle_id;
 };
 
 struct _GimpMenuDockClass
diff --git a/app/widgets/gimptoolbox.c b/app/widgets/gimptoolbox.c
index cd334d0..23d57e1 100644
--- a/app/widgets/gimptoolbox.c
+++ b/app/widgets/gimptoolbox.c
@@ -78,6 +78,7 @@ static gboolean    gimp_toolbox_button_press_event (GtkWidget      *widget,
 static gboolean    gimp_toolbox_expose_event       (GtkWidget      *widget,
                                                     GdkEventExpose *event);
 
+static gchar     * gimp_toolbox_get_title          (GimpDock       *dock);
 static void        gimp_toolbox_book_added         (GimpDock       *dock,
                                                     GimpDockbook   *dockbook);
 static void        gimp_toolbox_book_removed       (GimpDock       *dock,
@@ -149,6 +150,7 @@ gimp_toolbox_class_init (GimpToolboxClass *klass)
   widget_class->button_press_event  = gimp_toolbox_button_press_event;
   widget_class->expose_event        = gimp_toolbox_expose_event;
 
+  dock_class->get_title             = gimp_toolbox_get_title;
   dock_class->book_added            = gimp_toolbox_book_added;
   dock_class->book_removed          = gimp_toolbox_book_removed;
 
@@ -538,6 +540,12 @@ gimp_toolbox_expose_event (GtkWidget      *widget,
   return FALSE;
 }
 
+static gchar *
+gimp_toolbox_get_title (GimpDock *dock)
+{
+  return g_strdup (_("Toolbox"));
+}
+
 static void
 gimp_toolbox_book_added (GimpDock     *dock,
                          GimpDockbook *dockbook)
@@ -617,7 +625,6 @@ gimp_toolbox_new (GimpDialogFactory *dialog_factory,
   g_return_val_if_fail (GIMP_IS_CONTEXT (context), NULL);
 
   toolbox = g_object_new (GIMP_TYPE_TOOLBOX,
-                          "title",               _("Toolbox"),
                           "role",                "gimp-toolbox",
                           "context",             context,
                           "dialog-factory",      dialog_factory,



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