[gimp] Enable cut/copy/paste for the text tool



commit 0f55bf15bc60d53dae9f53efa8237133312fa7a2
Author: Michael Natterer <mitch gimp org>
Date:   Sun Jun 21 23:37:18 2009 +0200

    Enable cut/copy/paste for the text tool
    
    * app/tools/tools-enums.[ch]: add enum GimpClipboardAction which can be
    { CUT, COPY, PASTE }
    
    * app/tools/gimptool.[ch]
    * app/tools/tool_manager.[ch]: add GimpTool::clipboard_action() which
    returns a boolean indicating whether the tool handled the action.
    
    * app/tools/gimptexttool.c: implement clipboard_action().
    
    * app/actions/edit-commands.c: try the active tool first in the cut,
    copy and paste callbacks.

 app/actions/edit-commands.c |   40 ++++++++++++++++--
 app/tools/gimptexttool.c    |   94 +++++++++++++++++++++++++++++--------------
 app/tools/gimptool.c        |   24 +++++++++++
 app/tools/gimptool.h        |    7 +++
 app/tools/tool_manager.c    |   21 ++++++++++
 app/tools/tool_manager.h    |    3 +
 app/tools/tools-enums.c     |   31 ++++++++++++++
 app/tools/tools-enums.h     |   12 +++++
 8 files changed, 197 insertions(+), 35 deletions(-)
---
diff --git a/app/actions/edit-commands.c b/app/actions/edit-commands.c
index e7c7dc1..c823c4f 100644
--- a/app/actions/edit-commands.c
+++ b/app/actions/edit-commands.c
@@ -38,16 +38,18 @@
 
 #include "vectors/gimpvectors-import.h"
 
-#include "display/gimpdisplay.h"
-#include "display/gimpdisplayshell.h"
-#include "display/gimpdisplayshell-transform.h"
-
 #include "widgets/gimpclipboard.h"
 #include "widgets/gimphelp-ids.h"
 #include "widgets/gimpdialogfactory.h"
 #include "widgets/gimpmessagebox.h"
 #include "widgets/gimpmessagedialog.h"
 
+#include "display/gimpdisplay.h"
+#include "display/gimpdisplayshell.h"
+#include "display/gimpdisplayshell-transform.h"
+
+#include "tools/tool_manager.h"
+
 #include "dialogs/dialogs.h"
 #include "dialogs/fade-dialog.h"
 
@@ -189,9 +191,20 @@ edit_cut_cmd_callback (GtkAction *action,
 {
   GimpImage    *image;
   GimpDrawable *drawable;
+  GimpDisplay  *display;
   GError       *error = NULL;
   return_if_no_drawable (image, drawable, data);
 
+  display = action_data_get_display (data);
+
+  if (display &&
+      tool_manager_clipboard_action_active (display->gimp,
+                                            GIMP_CLIPBOARD_ACTION_CUT,
+                                            display))
+    {
+      return;
+    }
+
   if (gimp_edit_cut (image, drawable, action_data_get_context (data), &error))
     {
       GimpDisplay *display = action_data_get_display (data);
@@ -219,9 +232,20 @@ edit_copy_cmd_callback (GtkAction *action,
 {
   GimpImage    *image;
   GimpDrawable *drawable;
+  GimpDisplay  *display;
   GError       *error = NULL;
   return_if_no_drawable (image, drawable, data);
 
+  display = action_data_get_display (data);
+
+  if (display &&
+      tool_manager_clipboard_action_active (display->gimp,
+                                            GIMP_CLIPBOARD_ACTION_COPY,
+                                            display))
+    {
+      return;
+    }
+
   if (gimp_edit_copy (image, drawable, action_data_get_context (data), &error))
     {
       GimpDisplay *display = action_data_get_display (data);
@@ -278,6 +302,14 @@ edit_paste_cmd_callback (GtkAction *action,
 {
   GimpDisplay *display = action_data_get_display (data);
 
+  if (display &&
+      tool_manager_clipboard_action_active (display->gimp,
+                                            GIMP_CLIPBOARD_ACTION_PASTE,
+                                            display))
+    {
+      return;
+    }
+
   if (display && display->image)
     edit_paste (display, FALSE);
   else
diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c
index 591c7fe..e9f98e2 100644
--- a/app/tools/gimptexttool.c
+++ b/app/tools/gimptexttool.c
@@ -102,6 +102,9 @@ static void      gimp_text_tool_motion          (GimpTool          *tool,
 static gboolean  gimp_text_tool_key_press       (GimpTool          *tool,
                                                  GdkEventKey       *kevent,
                                                  GimpDisplay       *display);
+static gboolean gimp_text_tool_clipboard_action (GimpTool          *tool,
+                                                 GimpClipboardAction action,
+                                                 GimpDisplay       *display);
 static void      gimp_text_tool_oper_update     (GimpTool          *tool,
                                                  const GimpCoords  *coords,
                                                  GdkModifierType    state,
@@ -221,22 +224,23 @@ gimp_text_tool_class_init (GimpTextToolClass *klass)
   GimpToolClass     *tool_class      = GIMP_TOOL_CLASS (klass);
   GimpDrawToolClass *draw_tool_class = GIMP_DRAW_TOOL_CLASS (klass);
 
-  object_class->constructor  = gimp_text_tool_constructor;
-  object_class->dispose      = gimp_text_tool_dispose;
-  object_class->finalize     = gimp_text_tool_finalize;
-  object_class->set_property = gimp_rectangle_tool_set_property;
-  object_class->get_property = gimp_rectangle_tool_get_property;
+  object_class->constructor    = gimp_text_tool_constructor;
+  object_class->dispose        = gimp_text_tool_dispose;
+  object_class->finalize       = gimp_text_tool_finalize;
+  object_class->set_property   = gimp_rectangle_tool_set_property;
+  object_class->get_property   = gimp_rectangle_tool_get_property;
 
-  tool_class->control        = gimp_text_tool_control;
-  tool_class->button_press   = gimp_text_tool_button_press;
-  tool_class->motion         = gimp_text_tool_motion;
-  tool_class->button_release = gimp_text_tool_button_release;
-  tool_class->key_press      = gimp_text_tool_key_press;
-  tool_class->oper_update    = gimp_text_tool_oper_update;
-  tool_class->cursor_update  = gimp_text_tool_cursor_update;
-  tool_class->get_popup      = gimp_text_tool_get_popup;
+  tool_class->control          = gimp_text_tool_control;
+  tool_class->button_press     = gimp_text_tool_button_press;
+  tool_class->motion           = gimp_text_tool_motion;
+  tool_class->button_release   = gimp_text_tool_button_release;
+  tool_class->key_press        = gimp_text_tool_key_press;
+  tool_class->clipboard_action = gimp_text_tool_clipboard_action;
+  tool_class->oper_update      = gimp_text_tool_oper_update;
+  tool_class->cursor_update    = gimp_text_tool_cursor_update;
+  tool_class->get_popup        = gimp_text_tool_get_popup;
 
-  draw_tool_class->draw      = gimp_text_tool_draw;
+  draw_tool_class->draw        = gimp_text_tool_draw;
 
   gimp_rectangle_tool_install_properties (object_class);
 }
@@ -1000,6 +1004,51 @@ gimp_text_tool_key_press (GimpTool    *tool,
   return retval;
 }
 
+static gboolean
+gimp_text_tool_clipboard_action (GimpTool            *tool,
+                                 GimpClipboardAction  action,
+                                 GimpDisplay         *display)
+{
+  GimpTextTool *text_tool = GIMP_TEXT_TOOL (tool);
+
+  if (display != tool->display)
+    return FALSE;
+
+  switch (action)
+    {
+    case GIMP_CLIPBOARD_ACTION_CUT:
+      gimp_text_tool_clipboard_cut (text_tool);
+      break;
+
+    case GIMP_CLIPBOARD_ACTION_COPY:
+      gimp_text_tool_clipboard_copy (text_tool, TRUE);
+      break;
+
+    case GIMP_CLIPBOARD_ACTION_PASTE:
+      gimp_text_tool_clipboard_paste (text_tool, TRUE);
+      break;
+    }
+
+  return TRUE;
+}
+
+static void
+gimp_text_tool_oper_update (GimpTool         *tool,
+                            const GimpCoords *coords,
+                            GdkModifierType   state,
+                            gboolean          proximity,
+                            GimpDisplay      *display)
+{
+  GimpTextTool      *text_tool = GIMP_TEXT_TOOL (tool);
+  GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (tool);
+
+  gimp_rectangle_tool_oper_update (tool, coords, state, proximity, display);
+
+  text_tool->moving = (gimp_rectangle_tool_get_function (rect_tool) ==
+                       GIMP_RECTANGLE_TOOL_MOVING &&
+                       (state & GDK_MOD1_MASK));
+}
+
 static void
 gimp_text_tool_cursor_update (GimpTool         *tool,
                               const GimpCoords *coords,
@@ -1036,23 +1085,6 @@ gimp_text_tool_cursor_update (GimpTool         *tool,
   GIMP_TOOL_CLASS (parent_class)->cursor_update (tool, coords, state, display);
 }
 
-static void
-gimp_text_tool_oper_update (GimpTool         *tool,
-                            const GimpCoords *coords,
-                            GdkModifierType   state,
-                            gboolean          proximity,
-                            GimpDisplay      *display)
-{
-  GimpTextTool      *text_tool = GIMP_TEXT_TOOL (tool);
-  GimpRectangleTool *rect_tool = GIMP_RECTANGLE_TOOL (tool);
-
-  gimp_rectangle_tool_oper_update (tool, coords, state, proximity, display);
-
-  text_tool->moving = (gimp_rectangle_tool_get_function (rect_tool) ==
-                       GIMP_RECTANGLE_TOOL_MOVING &&
-                       (state & GDK_MOD1_MASK));
-}
-
 static GimpUIManager *
 gimp_text_tool_get_popup (GimpTool         *tool,
                           const GimpCoords *coords,
diff --git a/app/tools/gimptool.c b/app/tools/gimptool.c
index e4e57a0..2172f4a 100644
--- a/app/tools/gimptool.c
+++ b/app/tools/gimptool.c
@@ -98,6 +98,9 @@ static void  gimp_tool_real_active_modifier_key (GimpTool              *tool,
                                                  gboolean               press,
                                                  GdkModifierType        state,
                                                  GimpDisplay           *display);
+static gboolean gimp_tool_real_clipboard_action (GimpTool              *tool,
+                                                 GimpClipboardAction    action,
+                                                 GimpDisplay           *display);
 static void       gimp_tool_real_oper_update    (GimpTool              *tool,
                                                  const GimpCoords      *coords,
                                                  GdkModifierType        state,
@@ -142,6 +145,7 @@ gimp_tool_class_init (GimpToolClass *klass)
   klass->key_press           = gimp_tool_real_key_press;
   klass->modifier_key        = gimp_tool_real_modifier_key;
   klass->active_modifier_key = gimp_tool_real_active_modifier_key;
+  klass->clipboard_action    = gimp_tool_real_clipboard_action;
   klass->oper_update         = gimp_tool_real_oper_update;
   klass->cursor_update       = gimp_tool_real_cursor_update;
   klass->get_popup           = gimp_tool_real_get_popup;
@@ -351,6 +355,14 @@ gimp_tool_real_active_modifier_key (GimpTool        *tool,
 {
 }
 
+static gboolean
+gimp_tool_real_clipboard_action (GimpTool            *tool,
+                                 GimpClipboardAction  action,
+                                 GimpDisplay         *display)
+{
+  return FALSE;
+}
+
 static void
 gimp_tool_real_oper_update (GimpTool         *tool,
                             const GimpCoords *coords,
@@ -835,6 +847,18 @@ gimp_tool_set_active_modifier_state (GimpTool        *tool,
   tool->active_modifier_state = state;
 }
 
+gboolean
+gimp_tool_clipboard_action (GimpTool            *tool,
+                            GimpClipboardAction  action,
+                            GimpDisplay         *display)
+{
+  g_return_val_if_fail (GIMP_IS_TOOL (tool), FALSE);
+  g_return_val_if_fail (GIMP_IS_DISPLAY (display), FALSE);
+  g_return_val_if_fail (display == tool->focus_display, FALSE);
+
+  return GIMP_TOOL_GET_CLASS (tool)->clipboard_action (tool, action, display);
+}
+
 void
 gimp_tool_oper_update (GimpTool         *tool,
                        const GimpCoords *coords,
diff --git a/app/tools/gimptool.h b/app/tools/gimptool.h
index 9bdeaeb..5cbacdb 100644
--- a/app/tools/gimptool.h
+++ b/app/tools/gimptool.h
@@ -118,6 +118,9 @@ struct _GimpToolClass
                                            gboolean               press,
                                            GdkModifierType        state,
                                            GimpDisplay           *display);
+  gboolean        (* clipboard_action)    (GimpTool              *tool,
+                                           GimpClipboardAction    action,
+                                           GimpDisplay           *display);
 
   void            (* oper_update)         (GimpTool              *tool,
                                            const GimpCoords      *coords,
@@ -182,6 +185,10 @@ void    gimp_tool_set_active_modifier_state (GimpTool            *tool,
                                              GdkModifierType      state,
                                              GimpDisplay         *display);
 
+gboolean      gimp_tool_clipboard_action    (GimpTool            *tool,
+                                             GimpClipboardAction  action,
+                                             GimpDisplay         *display);
+
 void          gimp_tool_oper_update         (GimpTool            *tool,
                                              const GimpCoords    *coords,
                                              GdkModifierType      state,
diff --git a/app/tools/tool_manager.c b/app/tools/tool_manager.c
index 2224f75..3a8a9f8 100644
--- a/app/tools/tool_manager.c
+++ b/app/tools/tool_manager.c
@@ -356,6 +356,27 @@ tool_manager_key_press_active (Gimp        *gimp,
   return FALSE;
 }
 
+gboolean
+tool_manager_clipboard_action_active (Gimp                *gimp,
+                                      GimpClipboardAction  action,
+                                      GimpDisplay         *display)
+{
+  GimpToolManager *tool_manager;
+
+  g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
+
+  tool_manager = tool_manager_get (gimp);
+
+  if (tool_manager->active_tool)
+    {
+      return gimp_tool_clipboard_action (tool_manager->active_tool,
+                                         action,
+                                         display);
+    }
+
+  return FALSE;
+}
+
 void
 tool_manager_focus_display_active (Gimp        *gimp,
                                    GimpDisplay *display)
diff --git a/app/tools/tool_manager.h b/app/tools/tool_manager.h
index 7597a75..8263d13 100644
--- a/app/tools/tool_manager.h
+++ b/app/tools/tool_manager.h
@@ -56,6 +56,9 @@ void       tool_manager_motion_active              (Gimp             *gimp,
 gboolean   tool_manager_key_press_active           (Gimp             *gimp,
                                                     GdkEventKey      *kevent,
                                                     GimpDisplay      *display);
+gboolean   tool_manager_clipboard_action_active    (Gimp             *gimp,
+                                                    GimpClipboardAction action,
+                                                    GimpDisplay      *display);
 
 void       tool_manager_focus_display_active       (Gimp             *gimp,
                                                     GimpDisplay      *display);
diff --git a/app/tools/tools-enums.c b/app/tools/tools-enums.c
index 0f243db..767ffeb 100644
--- a/app/tools/tools-enums.c
+++ b/app/tools/tools-enums.c
@@ -74,6 +74,37 @@ gimp_button_release_type_get_type (void)
 }
 
 GType
+gimp_clipboard_action_get_type (void)
+{
+  static const GEnumValue values[] =
+  {
+    { GIMP_CLIPBOARD_ACTION_CUT, "GIMP_CLIPBOARD_ACTION_CUT", "cut" },
+    { GIMP_CLIPBOARD_ACTION_COPY, "GIMP_CLIPBOARD_ACTION_COPY", "copy" },
+    { GIMP_CLIPBOARD_ACTION_PASTE, "GIMP_CLIPBOARD_ACTION_PASTE", "paste" },
+    { 0, NULL, NULL }
+  };
+
+  static const GimpEnumDesc descs[] =
+  {
+    { GIMP_CLIPBOARD_ACTION_CUT, "GIMP_CLIPBOARD_ACTION_CUT", NULL },
+    { GIMP_CLIPBOARD_ACTION_COPY, "GIMP_CLIPBOARD_ACTION_COPY", NULL },
+    { GIMP_CLIPBOARD_ACTION_PASTE, "GIMP_CLIPBOARD_ACTION_PASTE", NULL },
+    { 0, NULL, NULL }
+  };
+
+  static GType type = 0;
+
+  if (G_UNLIKELY (! type))
+    {
+      type = g_enum_register_static ("GimpClipboardAction", values);
+      gimp_type_set_translation_context (type, "clipboard-action");
+      gimp_enum_set_value_descriptions (type, descs);
+    }
+
+  return type;
+}
+
+GType
 gimp_rectangle_guide_get_type (void)
 {
   static const GEnumValue values[] =
diff --git a/app/tools/tools-enums.h b/app/tools/tools-enums.h
index 3a508a7..fe998e0 100644
--- a/app/tools/tools-enums.h
+++ b/app/tools/tools-enums.h
@@ -47,6 +47,18 @@ typedef enum
 } GimpButtonReleaseType;
 
 
+#define GIMP_TYPE_CLIPBOARD_ACTION (gimp_clipboard_action_get_type ())
+
+GType gimp_clipboard_action_get_type (void) G_GNUC_CONST;
+
+typedef enum
+{
+  GIMP_CLIPBOARD_ACTION_CUT,
+  GIMP_CLIPBOARD_ACTION_COPY,
+  GIMP_CLIPBOARD_ACTION_PASTE
+} GimpClipboardAction;
+
+
 #define GIMP_TYPE_RECTANGLE_GUIDE (gimp_rectangle_guide_get_type ())
 
 GType gimp_rectangle_guide_get_type (void) G_GNUC_CONST;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]