From dab374b2bc13c9ff9e6a7baf5cf41d59b616498c Mon Sep 17 00:00:00 2001 From: Gabriele Barbero Date: Mon, 9 Jun 2025 13:56:30 +0200 Subject: [PATCH] tools: implement restore option for on-canvas text editor ... ... to reset its position via right-click menu This commit adds the ability to restore the original position of the on-canvas text editor after it has been moved, by accessing the option from the context menu opened with a right-click on the text box. --- app/actions/text-tool-actions.c | 11 ++++++++++- app/actions/text-tool-commands.c | 17 +++++++++++++++++ app/actions/text-tool-commands.h | 4 ++++ app/tools/gimptexttool-editor.c | 11 +++++++++++ menus/text-tool-menu.ui | 3 +++ 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app/actions/text-tool-actions.c b/app/actions/text-tool-actions.c index 0fcf5e32f1..fb188fea90 100644 --- a/app/actions/text-tool-actions.c +++ b/app/actions/text-tool-actions.c @@ -89,7 +89,12 @@ static const GimpActionEntry text_tool_actions[] = NC_("text-tool-action", "Bend the text along the currently active path"), text_tool_text_along_path_cmd_callback, - GIMP_HELP_TEXT_TOOL_TEXT_ALONG_PATH } + GIMP_HELP_TEXT_TOOL_TEXT_ALONG_PATH }, + + { "text-tool-restore-on-canvas-editor-position", NULL, + NC_("text-tool-action", "Restore On-Canvas Editor Position"), NULL, { NULL }, NULL, + text_tool_restore_on_canvas_editor_position_cmd_callback, + NULL } }; static const GimpRadioActionEntry text_tool_direction_actions[] = @@ -166,6 +171,7 @@ text_tool_actions_update (GimpActionGroup *group, gboolean clip = FALSE; /* clipboard has text available */ GimpTextDirection direction; gint i; + gdouble x, y; layers = gimp_image_get_selected_layers (image); @@ -197,6 +203,9 @@ text_tool_actions_update (GimpActionGroup *group, SET_SENSITIVE ("text-tool-load", image); SET_SENSITIVE ("text-tool-text-to-path", text_layer); SET_SENSITIVE ("text-tool-text-along-path", text_layer && g_list_length (paths) == 1); + SET_SENSITIVE ("text-tool-restore-on-canvas-editor-position", + text_layer && + gimp_text_layer_get_style_overlay_position (text_tool->layer, &x, &y)); direction = gimp_text_tool_get_direction (text_tool); for (i = 0; i < G_N_ELEMENTS (text_tool_direction_actions); i++) diff --git a/app/actions/text-tool-commands.c b/app/actions/text-tool-commands.c index 882aaff7b0..6e0688820e 100644 --- a/app/actions/text-tool-commands.c +++ b/app/actions/text-tool-commands.c @@ -36,7 +36,10 @@ #include "display/gimpdisplay.h" +#include "text/gimptextlayer.h" + #include "tools/gimptexttool.h" +#include "tools/gimptexttool-editor.h" #include "dialogs/dialogs.h" @@ -206,6 +209,20 @@ text_tool_direction_cmd_callback (GimpAction *action, NULL); } +void +text_tool_restore_on_canvas_editor_position_cmd_callback (GimpAction *action, + GVariant *value, + gpointer data) +{ + GimpTextTool *text_tool = GIMP_TEXT_TOOL (data); + + if (text_tool->layer) + gimp_text_layer_set_style_overlay_position (text_tool->layer, FALSE, 0, 0); + + gimp_text_tool_editor_position (text_tool); +} + + /* private functions */ diff --git a/app/actions/text-tool-commands.h b/app/actions/text-tool-commands.h index d7bef1c8ad..51a994ed80 100644 --- a/app/actions/text-tool-commands.h +++ b/app/actions/text-tool-commands.h @@ -46,6 +46,10 @@ void text_tool_text_along_path_cmd_callback (GimpAction *action, void text_tool_direction_cmd_callback (GimpAction *action, GVariant *value, gpointer data); +void text_tool_restore_on_canvas_editor_position_cmd_callback + (GimpAction *action, + GVariant *value, + gpointer data); #endif /* __TEXT_TOOL_COMMANDS_H__ */ diff --git a/app/tools/gimptexttool-editor.c b/app/tools/gimptexttool-editor.c index 10ee2df220..6548302839 100644 --- a/app/tools/gimptexttool-editor.c +++ b/app/tools/gimptexttool-editor.c @@ -298,6 +298,17 @@ gimp_text_tool_editor_position (GimpTextTool *text_tool) } else { + GimpOverlayChild *child_overlay; + + /* + * Set 'relative_to_shell' to FALSE to allow the overlay to be positioned + * independently from the shell. This enables the overlay to be moved freely + * and later restored to its original position on screen. + */ + child_overlay = gimp_overlay_child_find (GIMP_OVERLAY_BOX (shell->canvas), + text_tool->style_overlay); + gimp_overlay_child_set_relative_to_shell (child_overlay, FALSE); + gimp_display_shell_move_overlay (shell, text_tool->style_overlay, x, y, GIMP_HANDLE_ANCHOR_SOUTH_WEST, diff --git a/menus/text-tool-menu.ui b/menus/text-tool-menu.ui index 1881c5ac9c..de94ac63e0 100644 --- a/menus/text-tool-menu.ui +++ b/menus/text-tool-menu.ui @@ -9,6 +9,9 @@ text-tool.text-tool-copy text-tool.text-tool-paste text-tool.text-tool-delete +
+ text-tool.text-tool-restore-on-canvas-editor-position +
text-tool.text-tool-load text-tool.text-tool-clear