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:
@ -48,9 +48,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;
|
||||
@ -59,11 +63,16 @@ struct _GimpToolManager
|
||||
|
||||
/* 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,
|
||||
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);
|
||||
@ -77,6 +86,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);
|
||||
|
||||
@ -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,15 +613,6 @@ tool_manager_get_popup_active (Gimp *gimp,
|
||||
|
||||
static GQuark tool_manager_quark = 0;
|
||||
|
||||
static GimpToolManager *
|
||||
tool_manager_get (Gimp *gimp)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
static void
|
||||
tool_manager_set (Gimp *gimp,
|
||||
GimpToolManager *tool_manager)
|
||||
@ -617,16 +623,20 @@ tool_manager_set (Gimp *gimp,
|
||||
g_object_set_qdata (G_OBJECT (gimp), tool_manager_quark, tool_manager);
|
||||
}
|
||||
|
||||
static GimpToolManager *
|
||||
tool_manager_get (Gimp *gimp)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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
|
||||
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user