[gimp] app: Update Windows->Toolbox menu entry depending on if toolbox exists



commit d44ee9e2c4ba716616cb25530f7d5290408902ec
Author: Martin Nordholts <martinn src gnome org>
Date:   Sun Mar 7 12:24:26 2010 +0100

    app: Update Windows->Toolbox menu entry depending on if toolbox exists
    
    Update Windows->Toolbox menu entry depending on if toolbox exists. If
    an existing toolbox will be raised, set "Toolbox". If it will create a
    new toolbox, set "New Toolbox". We need this special treatment since
    there can be only one toolbox, so "New Toolbox" will remove any
    toolbox docks from Recently Closed Docks. If we would just have
    "Toolbox" it could be misinterpreted as "get me the toolbox I just
    closed".

 app/actions/dialogs-actions.c |   39 ++++++++++++++++++++++++++++++++++++++-
 app/display/gimpimagewindow.c |   19 +++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletions(-)
---
diff --git a/app/actions/dialogs-actions.c b/app/actions/dialogs-actions.c
index 2a578a2..2d16df6 100644
--- a/app/actions/dialogs-actions.c
+++ b/app/actions/dialogs-actions.c
@@ -24,7 +24,10 @@
 #include "actions-types.h"
 
 #include "widgets/gimpactiongroup.h"
+#include "widgets/gimpdialogfactory.h"
 #include "widgets/gimphelp-ids.h"
+#include "widgets/gimpsessioninfo.h"
+#include "widgets/gimptoolbox.h"
 
 #include "dialogs-actions.h"
 #include "dialogs-commands.h"
@@ -32,11 +35,14 @@
 #include "gimp-intl.h"
 
 
+static gboolean dialogs_actions_toolbox_exists (void);
+
+
 const GimpStringActionEntry dialogs_dockable_actions[] =
 {
   { "dialogs-toolbox", NULL,
     NC_("windows-action", "Tool_box"), "<control>B",
-    NC_("windows-action", "Raise the toolbox"),
+    NULL /* set in dialogs_actions_update() */,
     "gimp-toolbox",
     GIMP_HELP_TOOLBOX },
 
@@ -251,6 +257,21 @@ static const GimpStringActionEntry dialogs_toplevel_actions[] =
 };
 
 
+static gboolean
+dialogs_actions_toolbox_exists (void)
+{
+  GimpDialogFactory *factory = gimp_dialog_factory_get_singleton ();
+  GtkWidget         *widget  = NULL;
+  GimpSessionInfo   *info    = NULL;
+
+  info = gimp_dialog_factory_find_session_info (factory, "gimp-toolbox-window");
+
+  if (info)
+    widget = gimp_session_info_get_widget (info);
+
+  return widget != NULL;
+}
+
 void
 dialogs_actions_setup (GimpActionGroup *group)
 {
@@ -269,4 +290,20 @@ void
 dialogs_actions_update (GimpActionGroup *group,
                         gpointer         data)
 {
+  const gchar *toolbox_label   = NULL;
+  const gchar *toolbox_tooltip = NULL;
+
+  if (dialogs_actions_toolbox_exists ())
+    {
+      toolbox_label   = _("Toolbox");
+      toolbox_tooltip = _("Raise the toolbox");
+    }
+  else
+    {
+      toolbox_label   = _("New Toolbox");
+      toolbox_tooltip = _("Create a new toolbox");
+    }
+
+  gimp_action_group_set_action_label (group, "dialogs-toolbox", toolbox_label);
+  gimp_action_group_set_action_tooltip (group, "dialogs-toolbox", toolbox_tooltip);
 }
diff --git a/app/display/gimpimagewindow.c b/app/display/gimpimagewindow.c
index c5102bc..6a47a2f 100644
--- a/app/display/gimpimagewindow.c
+++ b/app/display/gimpimagewindow.c
@@ -140,6 +140,7 @@ static void      gimp_image_window_show_tooltip        (GimpUIManager       *man
                                                         GimpImageWindow     *window);
 static void      gimp_image_window_hide_tooltip        (GimpUIManager       *manager,
                                                         GimpImageWindow     *window);
+static void      gimp_image_window_update_ui_manager   (GimpImageWindow     *window);
 
 static gboolean  gimp_image_window_resume_shell        (GimpDisplayShell    *shell);
 static void      gimp_image_window_shell_size_allocate (GimpDisplayShell    *shell,
@@ -258,6 +259,13 @@ gimp_image_window_constructor (GType                  type,
 
   g_assert (GIMP_IS_UI_MANAGER (private->menubar_manager));
 
+  g_signal_connect_object (private->dialog_factory, "dock-window-added",
+                           G_CALLBACK (gimp_image_window_update_ui_manager),
+                           window, G_CONNECT_SWAPPED);
+  g_signal_connect_object (private->dialog_factory, "dock-window-removed",
+                           G_CALLBACK (gimp_image_window_update_ui_manager),
+                           window, G_CONNECT_SWAPPED);
+
   gtk_window_add_accel_group (GTK_WINDOW (window),
                               gtk_ui_manager_get_accel_group (GTK_UI_MANAGER (private->menubar_manager)));
 
@@ -376,6 +384,10 @@ gimp_image_window_finalize (GObject *object)
       private->menubar_manager = NULL;
     }
 
+  g_signal_handlers_disconnect_by_func (private->dialog_factory,
+                                        gimp_image_window_update_ui_manager,
+                                        window);
+
   G_OBJECT_CLASS (parent_class)->finalize (object);
 }
 
@@ -1138,6 +1150,13 @@ gimp_image_window_hide_tooltip (GimpUIManager   *manager,
   gimp_statusbar_pop (statusbar, "menu-tooltip");
 }
 
+static void
+gimp_image_window_update_ui_manager (GimpImageWindow *window)
+{
+  GimpImageWindowPrivate *private = GIMP_IMAGE_WINDOW_GET_PRIVATE (window);
+  gimp_ui_manager_update (private->menubar_manager, private->active_shell->display);
+}
+
 static gboolean
 gimp_image_window_resume_shell (GimpDisplayShell *shell)
 {



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