in the spirit of the fix for bug #165618 below, allow tools to specify up

2005-03-04  Michael Natterer  <mitch@gimp.org>

	* app/tools/gimptoolcontrol.[ch]: in the spirit of the fix for bug
	#165618 below, allow tools to specify up to two "object actions"
	(actions which select brushes, patterns, ...).

	* app/tools/gimpblendtool.c
	* app/tools/gimpbucketfilltool.c
	* app/tools/gimpclonetool.c
	* app/tools/gimppainttool.c
	* app/tools/gimptexttool.c: set actions where appropriate.

	* app/actions/actions.c (action_select_object): allow objects to
	be selected by index.

	* app/actions/context-actions.c: added actions which select
	objects by index. Not really used but the same actions can be used
	to generically pass any GimpActionSelectType enum value to the
	action callbacks.

	* app/actions/tools-actions.c
	* app/actions/tools-commands.[ch]: added actions and callbacks
	for the new generic tool objects.

	Also fixed and cleaned up the new generic tool value code.
This commit is contained in:
Michael Natterer 2005-03-04 19:05:40 +00:00 committed by Michael Natterer
parent fa041c2043
commit 1870b5d5c9
15 changed files with 337 additions and 89 deletions

View File

@ -1,3 +1,29 @@
2005-03-04 Michael Natterer <mitch@gimp.org>
* app/tools/gimptoolcontrol.[ch]: in the spirit of the fix for bug
#165618 below, allow tools to specify up to two "object actions"
(actions which select brushes, patterns, ...).
* app/tools/gimpblendtool.c
* app/tools/gimpbucketfilltool.c
* app/tools/gimpclonetool.c
* app/tools/gimppainttool.c
* app/tools/gimptexttool.c: set actions where appropriate.
* app/actions/actions.c (action_select_object): allow objects to
be selected by index.
* app/actions/context-actions.c: added actions which select
objects by index. Not really used but the same actions can be used
to generically pass any GimpActionSelectType enum value to the
action callbacks.
* app/actions/tools-actions.c
* app/actions/tools-commands.[ch]: added actions and callbacks
for the new generic tool objects.
Also fixed and cleaned up the new generic tool value code.
2003-03-04 Manish Singh <yosh@gimp.org>
* plug-ins/common/gqbist.c: #include gstdio.h

View File

@ -389,7 +389,7 @@ action_select_value (GimpActionSelectType select_type,
break;
default:
if (value >= 0)
if ((gint) select_type >= 0)
value = (gdouble) select_type * (max - min) / 1000.0 + min;
else
g_return_val_if_reached (value);
@ -488,7 +488,10 @@ action_select_object (GimpActionSelectType select_type,
break;
default:
g_return_val_if_reached (current);
if ((gint) select_type >= 0)
select_index = (gint) select_type;
else
g_return_val_if_reached (current);
break;
}

View File

@ -318,6 +318,10 @@ static GimpEnumActionEntry context_paint_mode_actions[] =
static GimpEnumActionEntry context_tool_select_actions[] =
{
{ "context-tool-select-set", GIMP_STOCK_TOOLS,
"Select Tool by Index", NULL, NULL,
GIMP_ACTION_SELECT_SET, TRUE,
NULL },
{ "context-tool-select-first", GIMP_STOCK_TOOLS,
"First Tool", NULL, NULL,
GIMP_ACTION_SELECT_FIRST, FALSE,
@ -338,6 +342,10 @@ static GimpEnumActionEntry context_tool_select_actions[] =
static GimpEnumActionEntry context_brush_select_actions[] =
{
{ "context-brush-select-set", GIMP_STOCK_BRUSH,
"Select Brush by Index", NULL, NULL,
GIMP_ACTION_SELECT_SET, TRUE,
NULL },
{ "context-brush-select-first", GIMP_STOCK_BRUSH,
"First Brush", NULL, NULL,
GIMP_ACTION_SELECT_FIRST, FALSE,
@ -358,6 +366,10 @@ static GimpEnumActionEntry context_brush_select_actions[] =
static GimpEnumActionEntry context_pattern_select_actions[] =
{
{ "context-pattern-select-set", GIMP_STOCK_PATTERN,
"Select Pattern by Index", NULL, NULL,
GIMP_ACTION_SELECT_SET, TRUE,
NULL },
{ "context-pattern-select-first", GIMP_STOCK_PATTERN,
"First Pattern", NULL, NULL,
GIMP_ACTION_SELECT_FIRST, FALSE,
@ -378,6 +390,10 @@ static GimpEnumActionEntry context_pattern_select_actions[] =
static GimpEnumActionEntry context_palette_select_actions[] =
{
{ "context-palette-select-set", GIMP_STOCK_PALETTE,
"Select Palette by Index", NULL, NULL,
GIMP_ACTION_SELECT_SET, TRUE,
NULL },
{ "context-palette-select-first", GIMP_STOCK_PALETTE,
"First Palette", NULL, NULL,
GIMP_ACTION_SELECT_FIRST, FALSE,
@ -398,6 +414,10 @@ static GimpEnumActionEntry context_palette_select_actions[] =
static GimpEnumActionEntry context_gradient_select_actions[] =
{
{ "context-gradient-select-set", GIMP_STOCK_GRADIENT,
"Select Gradient by Index", NULL, NULL,
GIMP_ACTION_SELECT_SET, TRUE,
NULL },
{ "context-gradient-select-first", GIMP_STOCK_GRADIENT,
"First Gradient", NULL, NULL,
GIMP_ACTION_SELECT_FIRST, FALSE,
@ -418,6 +438,10 @@ static GimpEnumActionEntry context_gradient_select_actions[] =
static GimpEnumActionEntry context_font_select_actions[] =
{
{ "context-font-select-set", GIMP_STOCK_FONT,
"Select Font by Index", NULL, NULL,
GIMP_ACTION_SELECT_SET, TRUE,
NULL },
{ "context-font-select-first", GIMP_STOCK_FONT,
"First Font", NULL, NULL,
GIMP_ACTION_SELECT_FIRST, FALSE,

View File

@ -364,6 +364,54 @@ static GimpEnumActionEntry tools_value_4_actions[] =
NULL },
};
static GimpEnumActionEntry tools_object_1_actions[] =
{
{ "tools-object-1-set", GIMP_STOCK_TOOL_OPTIONS,
"Select Object 1 by Index", NULL, NULL,
GIMP_ACTION_SELECT_SET, TRUE,
NULL },
{ "tools-object-1-first", GIMP_STOCK_TOOL_OPTIONS,
"First Object 1", NULL, NULL,
GIMP_ACTION_SELECT_FIRST, FALSE,
NULL },
{ "tools-object-1-last", GIMP_STOCK_TOOL_OPTIONS,
"Last Object 1", NULL, NULL,
GIMP_ACTION_SELECT_LAST, FALSE,
NULL },
{ "tools-object-1-previous", GIMP_STOCK_TOOL_OPTIONS,
"Previous Object 1", NULL, NULL,
GIMP_ACTION_SELECT_PREVIOUS, FALSE,
NULL },
{ "tools-object-1-next", GIMP_STOCK_TOOL_OPTIONS,
"Next Object 1", NULL, NULL,
GIMP_ACTION_SELECT_NEXT, FALSE,
NULL }
};
static GimpEnumActionEntry tools_object_2_actions[] =
{
{ "tools-object-2-set", GIMP_STOCK_TOOL_OPTIONS,
"Select Object 2 by Index", NULL, NULL,
GIMP_ACTION_SELECT_SET, TRUE,
NULL },
{ "tools-object-2-first", GIMP_STOCK_TOOL_OPTIONS,
"First Object 2", NULL, NULL,
GIMP_ACTION_SELECT_FIRST, FALSE,
NULL },
{ "tools-object-2-last", GIMP_STOCK_TOOL_OPTIONS,
"Last Object 2", NULL, NULL,
GIMP_ACTION_SELECT_LAST, FALSE,
NULL },
{ "tools-object-2-previous", GIMP_STOCK_TOOL_OPTIONS,
"Previous Object 2", NULL, NULL,
GIMP_ACTION_SELECT_PREVIOUS, FALSE,
NULL },
{ "tools-object-2-next", GIMP_STOCK_TOOL_OPTIONS,
"Next Object 2", NULL, NULL,
GIMP_ACTION_SELECT_NEXT, FALSE,
NULL }
};
void
tools_actions_setup (GimpActionGroup *group)
@ -427,6 +475,15 @@ tools_actions_setup (GimpActionGroup *group)
G_N_ELEMENTS (tools_value_4_actions),
G_CALLBACK (tools_value_4_cmd_callback));
gimp_action_group_add_enum_actions (group,
tools_object_1_actions,
G_N_ELEMENTS (tools_object_1_actions),
G_CALLBACK (tools_object_1_cmd_callback));
gimp_action_group_add_enum_actions (group,
tools_object_2_actions,
G_N_ELEMENTS (tools_object_2_actions),
G_CALLBACK (tools_object_2_cmd_callback));
for (list = GIMP_LIST (group->gimp->tool_info_list)->list;
list;
list = g_list_next (list))

View File

@ -44,6 +44,14 @@
#include "tools-commands.h"
/* local function prototypes */
static void tools_activate_enum_action (const gchar *action_desc,
gint value);
/* public functions */
void
tools_select_cmd_callback (GtkAction *action,
const gchar *value,
@ -306,42 +314,6 @@ tools_ink_blob_angle_cmd_callback (GtkAction *action,
}
}
static void
tools_activate_value_action (const gchar *action_desc,
gint value)
{
gchar *group_name;
gchar *action_name;
group_name = g_strdup (action_desc);
action_name = strchr (group_name, '/');
if (action_name)
{
GList *managers;
GtkAction *action;
*action_name++ = '\0';
managers = gimp_ui_managers_from_name ("<Image>");
action = gimp_ui_manager_find_action (managers->data,
group_name, action_name);
if (GIMP_IS_ENUM_ACTION (action))
{
gint old_value;
old_value = GIMP_ENUM_ACTION (action)->value;
GIMP_ENUM_ACTION (action)->value = value;
gtk_action_activate (action);
GIMP_ENUM_ACTION (action)->value = old_value;
}
}
g_free (group_name);
}
void
tools_value_1_cmd_callback (GtkAction *action,
gint value,
@ -360,7 +332,7 @@ tools_value_1_cmd_callback (GtkAction *action,
action_desc = gimp_tool_control_get_action_value_1 (tool->control);
if (action_desc)
tools_activate_value_action (action_desc, value);
tools_activate_enum_action (action_desc, value);
}
}
@ -382,7 +354,7 @@ tools_value_2_cmd_callback (GtkAction *action,
action_desc = gimp_tool_control_get_action_value_2 (tool->control);
if (action_desc)
tools_activate_value_action (action_desc, value);
tools_activate_enum_action (action_desc, value);
}
}
@ -404,7 +376,7 @@ tools_value_3_cmd_callback (GtkAction *action,
action_desc = gimp_tool_control_get_action_value_3 (tool->control);
if (action_desc)
tools_activate_value_action (action_desc, value);
tools_activate_enum_action (action_desc, value);
}
}
@ -426,6 +398,90 @@ tools_value_4_cmd_callback (GtkAction *action,
action_desc = gimp_tool_control_get_action_value_4 (tool->control);
if (action_desc)
tools_activate_value_action (action_desc, value);
tools_activate_enum_action (action_desc, value);
}
}
void
tools_object_1_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpContext *context;
GimpTool *tool;
return_if_no_context (context, data);
tool = tool_manager_get_active (context->gimp);
if (tool)
{
const gchar *action_desc;
action_desc = gimp_tool_control_get_action_object_1 (tool->control);
if (action_desc)
tools_activate_enum_action (action_desc, value);
}
}
void
tools_object_2_cmd_callback (GtkAction *action,
gint value,
gpointer data)
{
GimpContext *context;
GimpTool *tool;
return_if_no_context (context, data);
tool = tool_manager_get_active (context->gimp);
if (tool)
{
const gchar *action_desc;
action_desc = gimp_tool_control_get_action_object_2 (tool->control);
if (action_desc)
tools_activate_enum_action (action_desc, value);
}
}
/* private functions */
static void
tools_activate_enum_action (const gchar *action_desc,
gint value)
{
gchar *group_name;
gchar *action_name;
group_name = g_strdup (action_desc);
action_name = strchr (group_name, '/');
if (action_name)
{
GList *managers;
GtkAction *action;
*action_name++ = '\0';
managers = gimp_ui_managers_from_name ("<Image>");
action = gimp_ui_manager_find_action (managers->data,
group_name, action_name);
if (GIMP_IS_ENUM_ACTION (action) &&
GIMP_ENUM_ACTION (action)->value_variable)
{
gint old_value;
old_value = GIMP_ENUM_ACTION (action)->value;
GIMP_ENUM_ACTION (action)->value = value;
gtk_action_activate (action);
GIMP_ENUM_ACTION (action)->value = old_value;
}
}
g_free (group_name);
}

View File

@ -65,5 +65,12 @@ void tools_value_4_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void tools_object_1_cmd_callback (GtkAction *action,
gint value,
gpointer data);
void tools_object_2_cmd_callback (GtkAction *action,
gint value,
gpointer data);
#endif /* __TOOLS_COMMANDS_H__ */

View File

@ -158,10 +158,13 @@ gimp_blend_tool_init (GimpBlendTool *blend_tool)
{
GimpTool *tool = GIMP_TOOL (blend_tool);
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_BLEND);
gimp_tool_control_set_action_value_1 (tool->control,
"context/context-opacity-set");
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_BLEND);
gimp_tool_control_set_action_value_1 (tool->control,
"context/context-opacity-set");
gimp_tool_control_set_action_object_1 (tool->control,
"context/context-gradient-select-set");
}
static void

View File

@ -183,15 +183,18 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool)
{
GimpTool *tool = GIMP_TOOL (paint_tool);
gimp_tool_control_set_motion_mode (tool->control, GIMP_MOTION_MODE_EXACT);
gimp_tool_control_set_action_value_1 (tool->control,
"context/context-opacity-set");
gimp_tool_control_set_action_value_2 (tool->control,
"context/context-brush-radius-set");
gimp_tool_control_set_action_value_3 (tool->control,
"context/context-brush-aspect-set");
gimp_tool_control_set_action_value_4 (tool->control,
"context/context-brush-angle-set");
gimp_tool_control_set_motion_mode (tool->control,
GIMP_MOTION_MODE_EXACT);
gimp_tool_control_set_action_value_1 (tool->control,
"context/context-opacity-set");
gimp_tool_control_set_action_value_2 (tool->control,
"context/context-brush-radius-set");
gimp_tool_control_set_action_value_3 (tool->control,
"context/context-brush-aspect-set");
gimp_tool_control_set_action_value_4 (tool->control,
"context/context-brush-angle-set");
gimp_tool_control_set_action_object_1 (tool->control,
"context/context-brush-select-set");
paint_tool->pick_colors = FALSE;
paint_tool->draw_line = FALSE;

View File

@ -145,11 +145,13 @@ gimp_bucket_fill_tool_init (GimpBucketFillTool *bucket_fill_tool)
{
GimpTool *tool = GIMP_TOOL (bucket_fill_tool);
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_BUCKET_FILL);
gimp_tool_control_set_action_value_1 (tool->control,
"context/context-opacity-set");
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_BUCKET_FILL);
gimp_tool_control_set_action_value_1 (tool->control,
"context/context-opacity-set");
gimp_tool_control_set_action_object_1 (tool->control,
"context/context-pattern-select-set");
}
static void

View File

@ -141,7 +141,10 @@ gimp_clone_tool_init (GimpCloneTool *clone)
{
GimpTool *tool = GIMP_TOOL (clone);
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_CLONE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_CLONE);
gimp_tool_control_set_action_object_2 (tool->control,
"context/context-pattern-select-set");
}
static void

View File

@ -183,15 +183,18 @@ gimp_paint_tool_init (GimpPaintTool *paint_tool)
{
GimpTool *tool = GIMP_TOOL (paint_tool);
gimp_tool_control_set_motion_mode (tool->control, GIMP_MOTION_MODE_EXACT);
gimp_tool_control_set_action_value_1 (tool->control,
"context/context-opacity-set");
gimp_tool_control_set_action_value_2 (tool->control,
"context/context-brush-radius-set");
gimp_tool_control_set_action_value_3 (tool->control,
"context/context-brush-aspect-set");
gimp_tool_control_set_action_value_4 (tool->control,
"context/context-brush-angle-set");
gimp_tool_control_set_motion_mode (tool->control,
GIMP_MOTION_MODE_EXACT);
gimp_tool_control_set_action_value_1 (tool->control,
"context/context-opacity-set");
gimp_tool_control_set_action_value_2 (tool->control,
"context/context-brush-radius-set");
gimp_tool_control_set_action_value_3 (tool->control,
"context/context-brush-aspect-set");
gimp_tool_control_set_action_value_4 (tool->control,
"context/context-brush-angle-set");
gimp_tool_control_set_action_object_1 (tool->control,
"context/context-brush-select-set");
paint_tool->pick_colors = FALSE;
paint_tool->draw_line = FALSE;

View File

@ -141,7 +141,10 @@ gimp_clone_tool_init (GimpCloneTool *clone)
{
GimpTool *tool = GIMP_TOOL (clone);
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_CLONE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_CLONE);
gimp_tool_control_set_action_object_2 (tool->control,
"context/context-pattern-select-set");
}
static void

View File

@ -209,8 +209,11 @@ gimp_text_tool_init (GimpTextTool *text_tool)
text_tool->layer = NULL;
text_tool->image = NULL;
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
gimp_tool_control_set_tool_cursor (tool->control, GIMP_TOOL_CURSOR_TEXT);
gimp_tool_control_set_scroll_lock (tool->control, TRUE);
gimp_tool_control_set_tool_cursor (tool->control,
GIMP_TOOL_CURSOR_TEXT);
gimp_tool_control_set_action_object_1 (tool->control,
"context/context-font-select-set");
}
static GObject *

View File

@ -104,6 +104,8 @@ gimp_tool_control_init (GimpToolControl *control)
control->action_value_2 = NULL;
control->action_value_3 = NULL;
control->action_value_4 = NULL;
control->action_object_1 = NULL;
control->action_object_2 = NULL;
}
static void
@ -115,6 +117,8 @@ gimp_tool_control_finalize (GObject *object)
g_free (control->action_value_2);
g_free (control->action_value_3);
g_free (control->action_value_4);
g_free (control->action_object_1);
g_free (control->action_object_2);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -430,14 +434,14 @@ gimp_tool_control_get_toggle_cursor_modifier (GimpToolControl *control)
void
gimp_tool_control_set_action_value_1 (GimpToolControl *control,
const gchar *action_name)
const gchar *action_desc)
{
g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
if (action_name != control->action_value_1)
if (action_desc != control->action_value_1)
{
g_free (control->action_value_1);
control->action_value_1 = g_strdup (action_name);
control->action_value_1 = g_strdup (action_desc);
}
}
@ -451,14 +455,14 @@ gimp_tool_control_get_action_value_1 (GimpToolControl *control)
void
gimp_tool_control_set_action_value_2 (GimpToolControl *control,
const gchar *action_name)
const gchar *action_desc)
{
g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
if (action_name != control->action_value_2)
if (action_desc != control->action_value_2)
{
g_free (control->action_value_2);
control->action_value_2 = g_strdup (action_name);
control->action_value_2 = g_strdup (action_desc);
}
}
@ -472,14 +476,14 @@ gimp_tool_control_get_action_value_2 (GimpToolControl *control)
void
gimp_tool_control_set_action_value_3 (GimpToolControl *control,
const gchar *action_name)
const gchar *action_desc)
{
g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
if (action_name != control->action_value_3)
if (action_desc != control->action_value_3)
{
g_free (control->action_value_3);
control->action_value_3 = g_strdup (action_name);
control->action_value_3 = g_strdup (action_desc);
}
}
@ -493,14 +497,14 @@ gimp_tool_control_get_action_value_3 (GimpToolControl *control)
void
gimp_tool_control_set_action_value_4 (GimpToolControl *control,
const gchar *action_name)
const gchar *action_desc)
{
g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
if (action_name != control->action_value_4)
if (action_desc != control->action_value_4)
{
g_free (control->action_value_4);
control->action_value_4 = g_strdup (action_name);
control->action_value_4 = g_strdup (action_desc);
}
}
@ -511,3 +515,46 @@ gimp_tool_control_get_action_value_4 (GimpToolControl *control)
return control->action_value_4;
}
void
gimp_tool_control_set_action_object_1 (GimpToolControl *control,
const gchar *action_desc)
{
g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
if (action_desc != control->action_object_1)
{
g_free (control->action_object_1);
control->action_object_1 = g_strdup (action_desc);
}
}
const gchar *
gimp_tool_control_get_action_object_1 (GimpToolControl *control)
{
g_return_val_if_fail (GIMP_IS_TOOL_CONTROL (control), NULL);
return control->action_object_1;
}
void
gimp_tool_control_set_action_object_2 (GimpToolControl *control,
const gchar *action_desc)
{
g_return_if_fail (GIMP_IS_TOOL_CONTROL (control));
if (action_desc != control->action_object_2)
{
g_free (control->action_object_2);
control->action_object_2 = g_strdup (action_desc);
}
}
const gchar *
gimp_tool_control_get_action_object_2 (GimpToolControl *control)
{
g_return_val_if_fail (GIMP_IS_TOOL_CONTROL (control), NULL);
return control->action_object_2;
}

View File

@ -69,6 +69,8 @@ struct _GimpToolControl
gchar *action_value_2;
gchar *action_value_3;
gchar *action_value_4;
gchar *action_object_1;
gchar *action_object_2;
};
struct _GimpToolControlClass
@ -152,17 +154,23 @@ void gimp_tool_control_set_toggle_cursor_modifier (GimpToolControl
GimpCursorModifier cmodifier);
void gimp_tool_control_set_action_value_1 (GimpToolControl *control,
const gchar *action_name);
const gchar *action_desc);
const gchar * gimp_tool_control_get_action_value_1 (GimpToolControl *control);
void gimp_tool_control_set_action_value_2 (GimpToolControl *control,
const gchar *action_name);
const gchar *action_desc);
const gchar * gimp_tool_control_get_action_value_2 (GimpToolControl *control);
void gimp_tool_control_set_action_value_3 (GimpToolControl *control,
const gchar *action_name);
const gchar *action_desc);
const gchar * gimp_tool_control_get_action_value_3 (GimpToolControl *control);
void gimp_tool_control_set_action_value_4 (GimpToolControl *control,
const gchar *action_name);
const gchar *action_desc);
const gchar * gimp_tool_control_get_action_value_4 (GimpToolControl *control);
void gimp_tool_control_set_action_object_1 (GimpToolControl *control,
const gchar *action_desc);
const gchar * gimp_tool_control_get_action_object_1 (GimpToolControl *control);
void gimp_tool_control_set_action_object_2 (GimpToolControl *control,
const gchar *action_desc);
const gchar * gimp_tool_control_get_action_object_2 (GimpToolControl *control);
#endif /* __GIMP_TOOL_CONTROL_H__ */