mirror of
https://gitlab.gnome.org/GNOME/gimp.git
synced 2025-10-06 01:12:40 +02:00
Merge branch 'bug373060-test-last-tool' into 'master'
~~Bug 373060~~ Issue Teams/GIMP/Design/gimp-ux#289 - allow to easily switch to last used tool. See merge request GNOME/gimp!2392
This commit is contained in:
@@ -42,6 +42,15 @@
|
||||
#include "gimp-intl.h"
|
||||
|
||||
|
||||
static const GimpActionEntry tools_actions[] =
|
||||
{
|
||||
{ "tools-swap", NULL,
|
||||
NC_("tools-action", "Activate _Last Tool"), NULL, { "<shift>X", NULL },
|
||||
NC_("tools-action", "Switch back to the last activated tool"),
|
||||
tools_swap_cmd_callback,
|
||||
GIMP_HELP_TOOLBOX_SWAP_TOOLS }
|
||||
};
|
||||
|
||||
static const GimpStringActionEntry tools_alternative_actions[] =
|
||||
{
|
||||
{ "tools-by-color-select-short", GIMP_ICON_TOOL_BY_COLOR_SELECT,
|
||||
@@ -653,6 +662,10 @@ tools_actions_setup (GimpActionGroup *group)
|
||||
{
|
||||
GList *list;
|
||||
|
||||
gimp_action_group_add_actions (group, "tools-action",
|
||||
tools_actions,
|
||||
G_N_ELEMENTS (tools_actions));
|
||||
|
||||
gimp_action_group_add_string_actions (group, "tools-action",
|
||||
tools_alternative_actions,
|
||||
G_N_ELEMENTS (tools_alternative_actions),
|
||||
|
@@ -65,6 +65,18 @@ static void tools_activate_enum_action (const gchar *action_desc,
|
||||
|
||||
/* public functions */
|
||||
|
||||
void
|
||||
tools_swap_cmd_callback (GimpAction *action,
|
||||
GVariant *value,
|
||||
gpointer data)
|
||||
{
|
||||
Gimp *gimp;
|
||||
|
||||
return_if_no_gimp (gimp, data);
|
||||
|
||||
tool_manager_swap_tools (gimp);
|
||||
}
|
||||
|
||||
void
|
||||
tools_select_cmd_callback (GimpAction *action,
|
||||
GVariant *value,
|
||||
|
@@ -18,6 +18,10 @@
|
||||
#pragma once
|
||||
|
||||
|
||||
void tools_swap_cmd_callback (GimpAction *action,
|
||||
GVariant *value,
|
||||
gpointer data);
|
||||
|
||||
void tools_select_cmd_callback (GimpAction *action,
|
||||
GVariant *value,
|
||||
gpointer data);
|
||||
|
@@ -2234,9 +2234,11 @@ gimp_context_real_set_tool (GimpContext *context,
|
||||
}
|
||||
|
||||
if (context->tool_info)
|
||||
g_signal_handlers_disconnect_by_func (context->tool_info,
|
||||
gimp_context_tool_dirty,
|
||||
context);
|
||||
{
|
||||
g_signal_handlers_disconnect_by_func (context->tool_info,
|
||||
G_CALLBACK (gimp_context_tool_dirty),
|
||||
context);
|
||||
}
|
||||
|
||||
g_set_object (&context->tool_info, tool_info);
|
||||
|
||||
|
@@ -239,8 +239,8 @@ void gimp_context_display_changed (GimpContext *context);
|
||||
GimpToolInfo * gimp_context_get_tool (GimpContext *context);
|
||||
void gimp_context_set_tool (GimpContext *context,
|
||||
GimpToolInfo *tool_info);
|
||||
void gimp_context_tool_changed (GimpContext *context);
|
||||
|
||||
void gimp_context_tool_changed (GimpContext *context);
|
||||
|
||||
/* paint info */
|
||||
GimpPaintInfo * gimp_context_get_paint_info (GimpContext *context);
|
||||
|
@@ -26,6 +26,9 @@
|
||||
#include "libgimpmath/gimpmath.h"
|
||||
#include "libgimpwidgets/gimpwidgets.h"
|
||||
|
||||
#include "tools/tools-types.h"
|
||||
#include "tools/tool_manager.h"
|
||||
|
||||
#include "dialogs/dialogs-types.h"
|
||||
|
||||
#include "display/gimpdisplay.h"
|
||||
@@ -435,6 +438,59 @@ paintbrush_is_standard_tool (gconstpointer data)
|
||||
"gimp-tool-paintbrush");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* swap_tools:
|
||||
* @data:
|
||||
*
|
||||
* Testing switchback to last used tool <shift>X. Tools are taken from gimp->tool_info_list.
|
||||
* Not all possible combinations of available tools are tested though.
|
||||
**/
|
||||
static void
|
||||
swap_tools (gconstpointer data)
|
||||
{
|
||||
Gimp *gimp = GIMP (data);
|
||||
GimpContext *user_context = gimp_get_user_context (gimp);
|
||||
GimpToolInfo *first_tool_info = NULL;
|
||||
GimpToolInfo *second_tool_info = NULL;
|
||||
GList *tool_info_list = NULL;
|
||||
guint i, j = 0;
|
||||
|
||||
/* Arbitrarily testing only the first 10 available tools from gimp->tool_info_list
|
||||
* because there are tools which aren't settable within the reduced framework of
|
||||
* gimp_init_for_gui_testing's environment!
|
||||
*/
|
||||
guint tool_info_list_length = 10; /* Value should actually be g_list_length (tool_info_list) */
|
||||
|
||||
tool_info_list = gimp_get_tool_info_iter (gimp);
|
||||
|
||||
for (i = 0; i < tool_info_list_length; i++)
|
||||
{
|
||||
/* Getting the first reference tool */
|
||||
first_tool_info = g_list_nth_data (tool_info_list, i);
|
||||
|
||||
for (j = 0; j < tool_info_list_length; j++)
|
||||
{
|
||||
/* Now get the second tool. Set both one after another and loop the second tool through
|
||||
* all available tools to test switchback.
|
||||
*/
|
||||
second_tool_info = g_list_nth_data (tool_info_list, j);
|
||||
|
||||
if (first_tool_info != second_tool_info)
|
||||
{
|
||||
gimp_context_set_tool (user_context, first_tool_info);
|
||||
g_assert (gimp_context_get_tool (user_context) == first_tool_info);
|
||||
|
||||
gimp_context_set_tool (user_context, second_tool_info);
|
||||
g_assert (gimp_context_get_tool (user_context) == second_tool_info);
|
||||
|
||||
tool_manager_swap_tools (gimp);
|
||||
g_assert (gimp_context_get_tool (user_context) == first_tool_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gimp_ui_synthesize_delete_event:
|
||||
* @widget:
|
||||
@@ -553,6 +609,7 @@ int main(int argc, char **argv)
|
||||
ADD_TEST (switch_back_to_multi_window_mode);
|
||||
ADD_TEST (close_image);
|
||||
ADD_TEST (window_roles);
|
||||
ADD_TEST (swap_tools);
|
||||
|
||||
/* Run the tests and return status */
|
||||
g_application_run (gimp->app, 0, NULL);
|
||||
|
@@ -1224,6 +1224,9 @@ gimp_filter_tool_halt (GimpFilterTool *filter_tool)
|
||||
}
|
||||
|
||||
filter_tool->existing_filter = NULL;
|
||||
|
||||
if (tool_manager_get_active (tool->tool_info->gimp) == tool)
|
||||
tool_manager_swap_tools (tool->tool_info->gimp);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@@ -55,6 +55,8 @@ struct _GimpToolManager
|
||||
GimpTool *active_tool;
|
||||
GSList *tool_stack;
|
||||
|
||||
GList *history;
|
||||
|
||||
GimpToolGroup *active_tool_group;
|
||||
|
||||
GimpImage *image;
|
||||
@@ -119,7 +121,8 @@ tool_manager_init (Gimp *gimp)
|
||||
|
||||
tool_manager = g_slice_new0 (GimpToolManager);
|
||||
|
||||
tool_manager->gimp = gimp;
|
||||
tool_manager->gimp = gimp;
|
||||
tool_manager->history = NULL;
|
||||
|
||||
g_object_set_qdata (G_OBJECT (gimp), tool_manager_quark, tool_manager);
|
||||
|
||||
@@ -209,6 +212,8 @@ tool_manager_exit (Gimp *gimp)
|
||||
|
||||
tool_manager_set_active_tool_group (tool_manager, NULL);
|
||||
|
||||
g_list_free (tool_manager->history);
|
||||
|
||||
g_slice_free (GimpToolManager, tool_manager);
|
||||
|
||||
g_object_set_qdata (G_OBJECT (gimp), tool_manager_quark, NULL);
|
||||
@@ -276,6 +281,20 @@ tool_manager_pop_tool (Gimp *gimp)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
tool_manager_swap_tools (Gimp *gimp)
|
||||
{
|
||||
GimpToolManager *tool_manager;
|
||||
|
||||
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
||||
|
||||
tool_manager = tool_manager_get (gimp);
|
||||
|
||||
if (g_list_length (tool_manager->history) > 1)
|
||||
gimp_context_set_tool (tool_manager->gimp->user_context,
|
||||
g_list_nth_data (tool_manager->history, 1));
|
||||
}
|
||||
|
||||
gboolean
|
||||
tool_manager_initialize_active (Gimp *gimp,
|
||||
GimpDisplay *display)
|
||||
@@ -672,6 +691,38 @@ tool_manager_select_tool (GimpToolManager *tool_manager,
|
||||
}
|
||||
}
|
||||
|
||||
if (tool_manager->history == NULL ||
|
||||
tool_manager->history->data != tool->tool_info)
|
||||
{
|
||||
/* Update the history up to 3 element maximum and avoiding
|
||||
* duplicates.
|
||||
*/
|
||||
GList *found;
|
||||
|
||||
if ((found = g_list_find (tool_manager->history, tool->tool_info)))
|
||||
{
|
||||
tool_manager->history = g_list_remove_link (tool_manager->history, found);
|
||||
tool_manager->history = g_list_concat (found, tool_manager->history);
|
||||
}
|
||||
else
|
||||
{
|
||||
tool_manager->history = g_list_prepend (tool_manager->history, tool->tool_info);
|
||||
if (g_list_length (tool_manager->history) > 3)
|
||||
tool_manager->history = g_list_delete_link (tool_manager->history,
|
||||
g_list_last (tool_manager->history));
|
||||
}
|
||||
|
||||
if (g_list_length (tool_manager->history) > 1)
|
||||
{
|
||||
/* Never store filter tool in history (only as current tool). */
|
||||
GList *prev_list = g_list_nth (tool_manager->history, 1);
|
||||
GimpToolInfo *prev_tool = prev_list->data;
|
||||
|
||||
if (g_type_is_a (prev_tool->tool_type, GIMP_TYPE_FILTER_TOOL))
|
||||
tool_manager->history = g_list_delete_link (tool_manager->history, prev_list);
|
||||
}
|
||||
}
|
||||
|
||||
g_set_object (&tool_manager->active_tool, tool);
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,7 @@ void tool_manager_push_tool (Gimp *gimp,
|
||||
GimpTool *tool);
|
||||
void tool_manager_pop_tool (Gimp *gimp);
|
||||
|
||||
void tool_manager_swap_tools (Gimp *gimp);
|
||||
|
||||
gboolean tool_manager_initialize_active (Gimp *gimp,
|
||||
GimpDisplay *display);
|
||||
|
@@ -511,6 +511,7 @@
|
||||
#define GIMP_HELP_TOOLBOX_INDICATOR_AREA "gimp-toolbox-indicator-area"
|
||||
#define GIMP_HELP_TOOLBOX_DEFAULT_COLORS "gimp-toolbox-default-colors"
|
||||
#define GIMP_HELP_TOOLBOX_SWAP_COLORS "gimp-toolbox-swap-colors"
|
||||
#define GIMP_HELP_TOOLBOX_SWAP_TOOLS "gimp-toolbox-swap-tools"
|
||||
|
||||
#define GIMP_HELP_BRUSH_DIALOG "gimp-brush-dialog"
|
||||
#define GIMP_HELP_BRUSH_EDIT "gimp-brush-edit"
|
||||
|
Reference in New Issue
Block a user