[gimp/gimp-2-10] app: move tool-activation upon tool-group active-tool change to GimpToolManager
- From: Ell <ell src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/gimp-2-10] app: move tool-activation upon tool-group active-tool change to GimpToolManager
- Date: Thu, 30 Jan 2020 14:39:49 +0000 (UTC)
commit c58d4017de478bf25ec77317bcbab1dd5b09e78d
Author: Ell <ell_se yahoo com>
Date: Thu Jan 30 16:24:13 2020 +0200
app: move tool-activation upon tool-group active-tool change to GimpToolManager
When the active tool of the tool group associated with the
currently-selected tool changes, we select the new active tool;
this is currently handled in GimpToolButton. Move this logic to
GimpToolManager, which already handles the other half of the
problem: updating the group's active tool when one of its tools is
selected.
app/tools/tool_manager.c | 132 +++++++++++++++++++++++++++++--------------
app/widgets/gimptoolbutton.c | 6 --
2 files changed, 89 insertions(+), 49 deletions(-)
---
diff --git a/app/tools/tool_manager.c b/app/tools/tool_manager.c
index 338a09bb3f..7f4b31e3f5 100644
--- a/app/tools/tool_manager.c
+++ b/app/tools/tool_manager.c
@@ -48,37 +48,48 @@ typedef struct _GimpToolManager GimpToolManager;
struct _GimpToolManager
{
- GimpTool *active_tool;
- GSList *tool_stack;
+ Gimp *gimp;
- GQuark image_clean_handler_id;
- GQuark image_dirty_handler_id;
- GQuark image_saving_handler_id;
+ GimpTool *active_tool;
+ GSList *tool_stack;
+
+ GimpToolGroup *active_tool_group;
+
+ GQuark image_clean_handler_id;
+ GQuark image_dirty_handler_id;
+ GQuark image_saving_handler_id;
};
/* local function prototypes */
-static GimpToolManager * tool_manager_get (Gimp *gimp);
-static void tool_manager_set (Gimp *gimp,
- GimpToolManager *tool_manager);
-static void tool_manager_select_tool (Gimp *gimp,
- GimpTool *tool);
-static void tool_manager_tool_changed (GimpContext *user_context,
- GimpToolInfo *tool_info,
- GimpToolManager *tool_manager);
-static void tool_manager_preset_changed (GimpContext *user_context,
- GimpToolPreset *preset,
- GimpToolManager *tool_manager);
-static void tool_manager_image_clean_dirty (GimpImage *image,
- GimpDirtyMask dirty_mask,
- GimpToolManager *tool_manager);
-static void tool_manager_image_saving (GimpImage *image,
- GimpToolManager *tool_manager);
-static void tool_manager_tool_ancestry_changed (GimpToolInfo *tool_info,
- GimpToolManager *tool_manager);
-
-static void tool_manager_cast_spell (GimpToolInfo *tool_info);
+static void tool_manager_set (Gimp *gimp,
+ GimpToolManager *tool_manager);
+static GimpToolManager * tool_manager_get (Gimp *gimp);
+
+static void tool_manager_select_tool (GimpToolManager *tool_manager,
+ GimpTool *tool);
+
+static void tool_manager_set_active_tool_group (GimpToolManager *tool_manager,
+ GimpToolGroup *tool_group);
+
+static void tool_manager_tool_changed (GimpContext *user_context,
+ GimpToolInfo *tool_info,
+ GimpToolManager *tool_manager);
+static void tool_manager_preset_changed (GimpContext *user_context,
+ GimpToolPreset *preset,
+ GimpToolManager *tool_manager);
+static void tool_manager_image_clean_dirty (GimpImage *image,
+ GimpDirtyMask dirty_mask,
+ GimpToolManager *tool_manager);
+static void tool_manager_image_saving (GimpImage *image,
+ GimpToolManager *tool_manager);
+static void tool_manager_tool_ancestry_changed (GimpToolInfo *tool_info,
+ GimpToolManager *tool_manager);
+static void tool_manager_group_active_tool_changed (GimpToolGroup *tool_group,
+ GimpToolManager *tool_manager);
+
+static void tool_manager_cast_spell (GimpToolInfo *tool_info);
/* public functions */
@@ -93,8 +104,10 @@ tool_manager_init (Gimp *gimp)
tool_manager = g_slice_new0 (GimpToolManager);
+ tool_manager->gimp = gimp;
tool_manager->active_tool = NULL;
tool_manager->tool_stack = NULL;
+ tool_manager->active_tool_group = NULL;
tool_manager->image_clean_handler_id = 0;
tool_manager->image_dirty_handler_id = 0;
tool_manager->image_saving_handler_id = 0;
@@ -167,6 +180,8 @@ tool_manager_exit (Gimp *gimp)
g_clear_object (&tool_manager->active_tool);
}
+ tool_manager_set_active_tool_group (tool_manager, NULL);
+
g_slice_free (GimpToolManager, tool_manager);
}
@@ -204,7 +219,7 @@ tool_manager_push_tool (Gimp *gimp,
g_object_ref (tool_manager->tool_stack->data);
}
- tool_manager_select_tool (gimp, tool);
+ tool_manager_select_tool (tool_manager, tool);
if (focus_display)
tool_manager_focus_display_active (gimp, focus_display);
@@ -226,7 +241,7 @@ tool_manager_pop_tool (Gimp *gimp)
tool_manager->tool_stack = g_slist_remove (tool_manager->tool_stack,
tool);
- tool_manager_select_tool (gimp, tool);
+ tool_manager_select_tool (tool_manager, tool);
g_object_unref (tool);
}
@@ -598,35 +613,30 @@ tool_manager_get_popup_active (Gimp *gimp,
static GQuark tool_manager_quark = 0;
-static GimpToolManager *
-tool_manager_get (Gimp *gimp)
+static void
+tool_manager_set (Gimp *gimp,
+ GimpToolManager *tool_manager)
{
if (! tool_manager_quark)
tool_manager_quark = g_quark_from_static_string ("gimp-tool-manager");
- return g_object_get_qdata (G_OBJECT (gimp), tool_manager_quark);
+ g_object_set_qdata (G_OBJECT (gimp), tool_manager_quark, tool_manager);
}
-static void
-tool_manager_set (Gimp *gimp,
- GimpToolManager *tool_manager)
+static GimpToolManager *
+tool_manager_get (Gimp *gimp)
{
if (! tool_manager_quark)
tool_manager_quark = g_quark_from_static_string ("gimp-tool-manager");
- g_object_set_qdata (G_OBJECT (gimp), tool_manager_quark, tool_manager);
+ return g_object_get_qdata (G_OBJECT (gimp), tool_manager_quark);
}
static void
-tool_manager_select_tool (Gimp *gimp,
- GimpTool *tool)
+tool_manager_select_tool (GimpToolManager *tool_manager,
+ GimpTool *tool)
{
- GimpToolManager *tool_manager;
-
- g_return_if_fail (GIMP_IS_GIMP (gimp));
- g_return_if_fail (GIMP_IS_TOOL (tool));
-
- tool_manager = tool_manager_get (gimp);
+ Gimp *gimp = tool_manager->gimp;
/* reset the previously selected tool, but only if it is not only
* temporarily pushed to the tool stack
@@ -650,6 +660,32 @@ tool_manager_select_tool (Gimp *gimp,
g_set_object (&tool_manager->active_tool, tool);
}
+static void
+tool_manager_set_active_tool_group (GimpToolManager *tool_manager,
+ GimpToolGroup *tool_group)
+{
+ if (tool_group != tool_manager->active_tool_group)
+ {
+ if (tool_manager->active_tool_group)
+ {
+ g_signal_handlers_disconnect_by_func (
+ tool_manager->active_tool_group,
+ tool_manager_group_active_tool_changed,
+ tool_manager);
+ }
+
+ g_set_object (&tool_manager->active_tool_group, tool_group);
+
+ if (tool_manager->active_tool_group)
+ {
+ g_signal_connect (
+ tool_manager->active_tool_group, "active-tool-changed",
+ G_CALLBACK (tool_manager_group_active_tool_changed),
+ tool_manager);
+ }
+ }
+}
+
static void
tool_manager_tool_changed (GimpContext *user_context,
GimpToolInfo *tool_info,
@@ -727,7 +763,7 @@ tool_manager_tool_changed (GimpContext *user_context,
"tool-info", tool_info,
NULL);
- tool_manager_select_tool (user_context->gimp, new_tool);
+ tool_manager_select_tool (tool_manager, new_tool);
g_object_unref (new_tool);
@@ -859,6 +895,16 @@ tool_manager_tool_ancestry_changed (GimpToolInfo *tool_info,
gimp_tool_group_set_active_tool_info (GIMP_TOOL_GROUP (parent),
tool_info);
}
+
+ tool_manager_set_active_tool_group (tool_manager, GIMP_TOOL_GROUP (parent));
+}
+
+static void
+tool_manager_group_active_tool_changed (GimpToolGroup *tool_group,
+ GimpToolManager *tool_manager)
+{
+ gimp_context_set_tool (tool_manager->gimp->user_context,
+ gimp_tool_group_get_active_tool_info (tool_group));
}
static void
diff --git a/app/widgets/gimptoolbutton.c b/app/widgets/gimptoolbutton.c
index 81c4f29e65..ff21d96d69 100644
--- a/app/widgets/gimptoolbutton.c
+++ b/app/widgets/gimptoolbutton.c
@@ -508,14 +508,11 @@ gimp_tool_button_scroll (GtkWidget *widget,
if (tool_info && GIMP_IS_TOOL_GROUP (tool_button->priv->tool_item))
{
- GimpContext *context;
GimpContainer *children;
gint n_children;
gint index;
gint i;
- context = gimp_toolbox_get_context (tool_button->priv->toolbox);
-
children = gimp_viewable_get_children (
GIMP_VIEWABLE (tool_button->priv->tool_item));
@@ -540,9 +537,6 @@ gimp_tool_button_scroll (GtkWidget *widget,
gimp_tool_group_set_active_tool_info (
GIMP_TOOL_GROUP (tool_button->priv->tool_item), new_tool_info);
- if (tool_info == gimp_context_get_tool (context))
- gimp_context_set_tool (context, new_tool_info);
-
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]