diff --git a/app/actions/text-tool-commands.c b/app/actions/text-tool-commands.c index 6e0688820e..4affed2ee7 100644 --- a/app/actions/text-tool-commands.c +++ b/app/actions/text-tool-commands.c @@ -216,10 +216,7 @@ text_tool_restore_on_canvas_editor_position_cmd_callback (GimpAction *action, { 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); + gimp_text_tool_restore_on_canvas_editor_position (text_tool); } diff --git a/app/tools/gimptexttool-editor.c b/app/tools/gimptexttool-editor.c index ab0836bb34..cfac349673 100644 --- a/app/tools/gimptexttool-editor.c +++ b/app/tools/gimptexttool-editor.c @@ -293,6 +293,9 @@ gimp_text_tool_editor_position (GimpTextTool *text_tool) x, y, -1, text_tool->drag_offset_x + 25, text_tool->drag_offset_y + 25); + + gimp_text_style_show_restore_position_button (GIMP_TEXT_STYLE_EDITOR (text_tool->style_editor), + TRUE); } else { @@ -2033,9 +2036,10 @@ gimp_text_tool_style_overlay_button_motion (GtkWidget *widget, if (text_tool->overlay_dragging) { - GimpTool *tool = GIMP_TOOL (text_tool); - GimpDisplayShell *shell = gimp_display_get_shell (tool->display); - gdouble x, y; + GimpTool *tool = GIMP_TOOL (text_tool); + GimpDisplayShell *shell = gimp_display_get_shell (tool->display); + GimpTextStyleEditor *style_editor; + gdouble x, y; gdk_window_get_device_position_double (gtk_widget_get_window (GTK_WIDGET (shell)), event->device, @@ -2053,6 +2057,9 @@ gimp_text_tool_style_overlay_button_motion (GtkWidget *widget, gimp_text_layer_set_style_overlay_position (text_tool->layer, TRUE, x, y); + + style_editor = GIMP_TEXT_STYLE_EDITOR (text_tool->style_editor); + gimp_text_style_show_restore_position_button (style_editor, TRUE); } return TRUE; diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c index 1c91ed4230..6269d9b91d 100644 --- a/app/tools/gimptexttool.c +++ b/app/tools/gimptexttool.c @@ -65,6 +65,7 @@ #include "widgets/gimphelp-ids.h" #include "widgets/gimpmenufactory.h" #include "widgets/gimptextbuffer.h" +#include "widgets/gimptextstyleeditor.h" #include "widgets/gimpuimanager.h" #include "widgets/gimpviewabledialog.h" @@ -2418,3 +2419,15 @@ gimp_text_tool_get_direction (GimpTextTool *text_tool) GimpTextOptions *options = GIMP_TEXT_TOOL_GET_OPTIONS (text_tool); return options->base_dir; } + +void +gimp_text_tool_restore_on_canvas_editor_position (GimpTextTool *text_tool) +{ + GimpTextStyleEditor *editor = GIMP_TEXT_STYLE_EDITOR (text_tool->style_editor); + + if (text_tool->layer) + gimp_text_layer_set_style_overlay_position (text_tool->layer, FALSE, 0, 0); + + gimp_text_tool_editor_position (text_tool); + gimp_text_style_show_restore_position_button (editor, FALSE); +} diff --git a/app/tools/gimptexttool.h b/app/tools/gimptexttool.h index 6d226ff7bc..6f0978a508 100644 --- a/app/tools/gimptexttool.h +++ b/app/tools/gimptexttool.h @@ -134,5 +134,8 @@ gboolean gimp_text_tool_ensure_layout (GimpTextTool *text_tool); void gimp_text_tool_apply (GimpTextTool *text_tool, gboolean push_undo); +void gimp_text_tool_restore_on_canvas_editor_position + (GimpTextTool *text_tool); + #endif /* __GIMP_TEXT_TOOL_H__ */ diff --git a/app/widgets/gimptextstyleeditor.c b/app/widgets/gimptextstyleeditor.c index ac3bbfe4d9..a51f9bd958 100644 --- a/app/widgets/gimptextstyleeditor.c +++ b/app/widgets/gimptextstyleeditor.c @@ -33,6 +33,10 @@ #include "core/gimpcontainer.h" #include "core/gimpcontext.h" +#include "tools/tools-types.h" +#include "tools/tool_manager.h" +#include "tools/gimptexttool.h" + #include "text/gimptext.h" #include "text/gimpfont.h" @@ -42,6 +46,7 @@ #include "gimptextbuffer.h" #include "gimptextstyleeditor.h" #include "gimptexttag.h" +#include "gimpwidgets-constructors.h" #include "gimpwidgets-utils.h" #include "gimp-intl.h" @@ -120,6 +125,10 @@ static void gimp_text_style_editor_set_kerning (GimpTextStyleEditor * static void gimp_text_style_editor_update (GimpTextStyleEditor *editor); static gboolean gimp_text_style_editor_update_idle (GimpTextStyleEditor *editor); +static void gimp_text_style_editor_restore_position_callback + (GtkWidget *button, + GimpTextStyleEditor *editor); + G_DEFINE_TYPE (GimpTextStyleEditor, gimp_text_style_editor, GTK_TYPE_BOX) @@ -193,6 +202,7 @@ gimp_text_style_editor_init (GimpTextStyleEditor *editor) { GtkWidget *image; GeglColor *color; + GtkWidget *move_icon; gtk_orientable_set_orientation (GTK_ORIENTABLE (editor), GTK_ORIENTATION_VERTICAL); @@ -227,6 +237,30 @@ gimp_text_style_editor_init (GimpTextStyleEditor *editor) G_CALLBACK (gimp_text_style_editor_size_changed), editor); + /* Icon that indicates that the overlay can be moved */ + move_icon = gtk_image_new_from_icon_name (GIMP_ICON_TOOL_MOVE, + GTK_ICON_SIZE_MENU); + gtk_widget_set_sensitive (move_icon, FALSE); + gtk_widget_show (move_icon); + + /* Restore position button */ + editor->restore_position_button = gimp_icon_button_new (GIMP_ICON_RESET, NULL); + gtk_button_set_relief (GTK_BUTTON (editor->restore_position_button), + GTK_RELIEF_NONE); + gtk_image_set_from_icon_name (GTK_IMAGE (gtk_bin_get_child (GTK_BIN (editor->restore_position_button))), + GIMP_ICON_RESET, GTK_ICON_SIZE_MENU); + + gimp_help_set_help_data (editor->restore_position_button, + _("Restore On-Canvas Editor Position"), NULL); + + g_signal_connect (editor->restore_position_button, "clicked", + G_CALLBACK (gimp_text_style_editor_restore_position_callback), + editor); + + gtk_box_pack_end (GTK_BOX (editor->upper_hbox), move_icon, FALSE, FALSE, 0); + gtk_box_pack_end (GTK_BOX (editor->upper_hbox), editor->restore_position_button, + FALSE, FALSE, 0); + /* lower row */ editor->lower_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2); @@ -633,6 +667,16 @@ gimp_text_style_editor_list_tags (GimpTextStyleEditor *editor, return g_list_reverse (tags); } +void +gimp_text_style_show_restore_position_button (GimpTextStyleEditor *editor, + gboolean show) +{ + if (show) + gtk_widget_show (editor->restore_position_button); + else + gtk_widget_hide (editor->restore_position_button); +} + /* private functions */ @@ -1339,3 +1383,13 @@ gimp_text_style_editor_update_idle (GimpTextStyleEditor *editor) return FALSE; } + +static void +gimp_text_style_editor_restore_position_callback (GtkWidget *button, + GimpTextStyleEditor *editor) +{ + GimpTool *tool = tool_manager_get_active (editor->gimp); + GimpTextTool *text_tool = GIMP_TEXT_TOOL (tool); + + gimp_text_tool_restore_on_canvas_editor_position (text_tool); +} diff --git a/app/widgets/gimptextstyleeditor.h b/app/widgets/gimptextstyleeditor.h index 964f12503d..ab4087e430 100644 --- a/app/widgets/gimptextstyleeditor.h +++ b/app/widgets/gimptextstyleeditor.h @@ -48,6 +48,7 @@ struct _GimpTextStyleEditor GtkWidget *upper_hbox; GtkWidget *lower_hbox; + GtkWidget *restore_position_button; GtkWidget *font_entry; GtkWidget *size_entry; @@ -85,5 +86,9 @@ GtkWidget * gimp_text_style_editor_new (Gimp *gimp, GList * gimp_text_style_editor_list_tags (GimpTextStyleEditor *editor, GList **remove_tags); +void gimp_text_style_show_restore_position_button + (GimpTextStyleEditor *editor, + gboolean show); + #endif /* __GIMP_TEXT_STYLE_EDITOR_H__ */