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.
This commit is contained in:
Ell 2020-01-30 16:24:13 +02:00
parent bae9f2d880
commit 00b756d2da
2 changed files with 78 additions and 39 deletions

View File

@ -47,9 +47,13 @@ typedef struct _GimpToolManager GimpToolManager;
struct _GimpToolManager
{
Gimp *gimp;
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;
@ -60,8 +64,12 @@ struct _GimpToolManager
static GimpToolManager * tool_manager_get (Gimp *gimp);
static void tool_manager_select_tool (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);
@ -75,6 +83,8 @@ 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);
@ -97,6 +107,8 @@ tool_manager_init (Gimp *gimp)
tool_manager = g_slice_new0 (GimpToolManager);
tool_manager->gimp = gimp;
g_object_set_qdata (G_OBJECT (gimp), tool_manager_quark, tool_manager);
tool_manager->image_clean_handler_id =
@ -166,6 +178,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);
g_object_set_qdata (G_OBJECT (gimp), tool_manager_quark, NULL);
@ -205,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);
@ -227,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);
}
@ -604,15 +618,10 @@ tool_manager_get (Gimp *gimp)
}
static void
tool_manager_select_tool (Gimp *gimp,
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
@ -636,6 +645,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,
@ -713,7 +748,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);
@ -845,6 +880,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

View File

@ -512,14 +512,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));
@ -544,9 +541,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;
}
}