gimp r26401 - in branches/soc-2008-text: . app/actions app/tools



Author: danedde
Date: Wed Aug  6 16:26:32 2008
New Revision: 26401
URL: http://svn.gnome.org/viewvc/gimp?rev=26401&view=rev

Log:
2008-08-06  Daniel Eddeland <danedde svn gnome org>

	* app/tools/gimptexttool.c
	* app/tools/gimptexttool.h
	* app/actions/text-tool-actions.c
	* app/actions/text-tool-commands.c
	* app/actions/text-tool-commands.h: Continued working on
	context-sensitive menu and clipboard actions etc.



Modified:
   branches/soc-2008-text/ChangeLog
   branches/soc-2008-text/app/actions/text-tool-actions.c
   branches/soc-2008-text/app/actions/text-tool-commands.c
   branches/soc-2008-text/app/actions/text-tool-commands.h
   branches/soc-2008-text/app/tools/gimptexttool.c
   branches/soc-2008-text/app/tools/gimptexttool.h

Modified: branches/soc-2008-text/app/actions/text-tool-actions.c
==============================================================================
--- branches/soc-2008-text/app/actions/text-tool-actions.c	(original)
+++ branches/soc-2008-text/app/actions/text-tool-actions.c	Wed Aug  6 16:26:32 2008
@@ -38,31 +38,35 @@
 {
   { "text-tool-popup", NULL,
     N_("Text Tool Popup"), NULL, NULL, NULL,
-    GIMP_HELP_TEXT_EDITOR_DIALOG },
+    NULL },
 
-  { "text-tool-cut", NULL,
+  { "text-tool-cut", GTK_STOCK_CUT,
     N_("Cut"), NULL, NULL,
-    NULL, NULL },
+    G_CALLBACK (text_tool_cut_cmd_callback),
+    NULL },
 
-  { "text-tool-copy", NULL,
+  { "text-tool-copy", GTK_STOCK_COPY,
     N_("Copy"), NULL, NULL,
-    NULL, NULL },
+    G_CALLBACK (text_tool_copy_cmd_callback),
+    NULL },
 
-  { "text-tool-paste", NULL,
+  { "text-tool-paste", GTK_STOCK_PASTE,
     N_("Paste"), NULL, NULL,
-    NULL, NULL },
+    G_CALLBACK (text_tool_paste_cmd_callback),
+    NULL },
 
-  { "text-tool-delete", NULL,
-    N_("Delete"), NULL, NULL,
-    NULL, NULL },
+  { "text-tool-delete", GTK_STOCK_DELETE,
+    N_("Delete selected"), NULL, NULL,
+    G_CALLBACK (text_tool_delete_cmd_callback), 
+    NULL },
 
-  { "text-tool-load", NULL,
+  { "text-tool-load", GTK_STOCK_OPEN,
     N_("Open"), NULL,
     N_("Load text from file"),
     G_CALLBACK (text_tool_load_cmd_callback),
     NULL },
 
-  { "text-tool-clear", NULL,
+  { "text-tool-clear", GTK_STOCK_CLEAR,
     N_("Clear"), "",
     N_("Clear all text"),
     G_CALLBACK (text_tool_clear_cmd_callback),
@@ -70,7 +74,7 @@
 
   { "text-tool-input-methods", NULL,
     N_("Input Methods"), NULL, NULL, NULL,
-    GIMP_HELP_TEXT_EDITOR_DIALOG }
+    NULL }
 };
 
 static const GimpRadioActionEntry text_tool_direction_actions[] =

Modified: branches/soc-2008-text/app/actions/text-tool-commands.c
==============================================================================
--- branches/soc-2008-text/app/actions/text-tool-commands.c	(original)
+++ branches/soc-2008-text/app/actions/text-tool-commands.c	Wed Aug  6 16:26:32 2008
@@ -32,6 +32,8 @@
 #include "widgets/gimpuimanager.h"
 #include "widgets/gimpwidgets-utils.h"
 
+#include "tools/gimptexttool.h"
+
 #include "text-tool-commands.h"
 
 #include "gimp-intl.h"
@@ -47,6 +49,39 @@
 /*  public functions  */
 
 void
+text_tool_cut_cmd_callback (GtkAction *action,
+                            gpointer   data)
+{
+  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data); 
+  gimp_text_tool_clipboard_cut (text_tool);
+}
+
+void
+text_tool_copy_cmd_callback (GtkAction *action,
+                             gpointer   data)
+{
+  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data); 
+  gimp_text_tool_clipboard_copy (text_tool);
+}
+
+void
+text_tool_paste_cmd_callback (GtkAction *action,
+                              gpointer   data)
+{
+  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data); 
+  gimp_text_tool_clipboard_paste (text_tool);
+}
+
+void
+text_tool_delete_cmd_callback (GtkAction *action,
+                               gpointer   data)
+{
+  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data); 
+  if (gtk_text_buffer_get_has_selection (text_tool->text_buffer))
+    gimp_text_tool_delete_text (text_tool);
+}
+
+void
 text_tool_load_cmd_callback (GtkAction *action,
                              gpointer   data)
 {
@@ -99,12 +134,12 @@
 text_tool_clear_cmd_callback (GtkAction *action,
                               gpointer   data)
 {
-  GimpTextEditor *editor = GIMP_TEXT_EDITOR (data);
-  GtkTextBuffer  *buffer;
-
-  buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (editor->view));
-
-  gtk_text_buffer_set_text (buffer, "", 0);
+  GimpTextTool *text_tool = GIMP_TEXT_TOOL (data); 
+  GtkTextIter start, end;
+  
+  gtk_text_buffer_get_bounds (text_tool->text_buffer, &start, &end);
+  gtk_text_buffer_select_range (text_tool->text_buffer, &start, &end);
+  gimp_text_tool_delete_text (text_tool);
 }
 
 void

Modified: branches/soc-2008-text/app/actions/text-tool-commands.h
==============================================================================
--- branches/soc-2008-text/app/actions/text-tool-commands.h	(original)
+++ branches/soc-2008-text/app/actions/text-tool-commands.h	Wed Aug  6 16:26:32 2008
@@ -20,6 +20,14 @@
 #define __TEXT_TOOL_COMMANDS_H__
 
 
+void   text_tool_cut_cmd_callback      (GtkAction *action,
+                                        gpointer   data);
+void   text_tool_copy_cmd_callback      (GtkAction *action,
+                                         gpointer   data);
+void   text_tool_paste_cmd_callback      (GtkAction *action,
+                                          gpointer   data);
+void   text_tool_delete_cmd_callback      (GtkAction *action,
+                                          gpointer   data);
 void   text_tool_load_cmd_callback      (GtkAction *action,
                                          gpointer   data);
 void   text_tool_clear_cmd_callback     (GtkAction *action,

Modified: branches/soc-2008-text/app/tools/gimptexttool.c
==============================================================================
--- branches/soc-2008-text/app/tools/gimptexttool.c	(original)
+++ branches/soc-2008-text/app/tools/gimptexttool.c	Wed Aug  6 16:26:32 2008
@@ -160,7 +160,7 @@
 
 static void      gimp_text_tool_update_layout  (GimpTextTool *text_tool);
 
-static void      gimp_text_tool_show_context_menu (GimpTextTool *text_tool, GimpCoords *coords);
+static void      gimp_text_tool_show_context_menu (GimpTool *tool, GimpCoords *coords);
 
 /* IM Context Callbacks
  */
@@ -169,12 +169,11 @@
                                                    GimpTextTool *text_tool);
 
 static void     gimp_text_tool_preedit_changed_cb (GtkIMContext *context,
-                                                   const gchar *str,
                                                    GimpTextTool *text_tool);
 
-static void gimp_text_tool_enter_text (GimpTextTool *text_tool,
-                                       const gchar  *str);
-static void gimp_text_tool_delete_text (GimpTextTool *text_tool);
+static void gimp_text_tool_enter_text   (GimpTextTool *text_tool,
+                                         const gchar  *str);
+static void gimp_text_tool_update_proxy (GimpTextTool *text_tool);
 
 G_DEFINE_TYPE_WITH_CODE (GimpTextTool, gimp_text_tool,
                          GIMP_TYPE_DRAW_TOOL,
@@ -232,7 +231,7 @@
                 0, NULL, NULL,
                 gimp_marshal_VOID__POINTER,
                 G_TYPE_NONE, 1,
-                G_TYPE_INT);
+                G_TYPE_POINTER);
 }
 
 static void
@@ -306,9 +305,12 @@
   gimp_text_tool_set_drawable (text_tool, NULL, FALSE);
 
   gimp_tool_control_set_wants_all_key_events (tool->control, FALSE);
+  gimp_tool_control_set_show_context_menu (tool->control, FALSE);
+
   gtk_text_buffer_set_text (text_tool->text_buffer, "", -1);
   g_signal_handlers_disconnect_by_func (text_tool->im_context, gimp_text_tool_commit_cb, text_tool);
   g_signal_handlers_disconnect_by_func (text_tool->im_context, gimp_text_tool_preedit_changed_cb, text_tool);
+  g_signal_handlers_disconnect_by_func (text_tool, gimp_text_tool_show_context_menu, NULL);
   G_OBJECT_CLASS (parent_class)->dispose (object);
 }
 
@@ -660,6 +662,30 @@
   gtk_text_buffer_get_iter_at_mark (text_tool->text_buffer, &selection,
                                     gtk_text_buffer_get_selection_bound (text_tool->text_buffer));
 
+  if (kevent->state & GDK_CONTROL_MASK)
+    {
+      printf ("ctrl is down\n");
+      if (kevent->keyval == GDK_X ||
+          kevent->keyval == GDK_x)
+        {
+          gimp_text_tool_clipboard_cut (text_tool);
+          return TRUE;
+        }
+      if (kevent->keyval == GDK_C ||
+          kevent->keyval == GDK_c)
+        {
+          gimp_text_tool_clipboard_copy (text_tool);
+          return TRUE;
+        }
+      if (kevent->keyval == GDK_V ||
+          kevent->keyval == GDK_v)
+        {
+          gimp_text_tool_clipboard_paste (text_tool);
+          return TRUE;
+        }
+      return FALSE;
+    }
+
   if (kevent->state & GDK_SHIFT_MASK)
       sel_start = &cursor;
   else
@@ -670,6 +696,7 @@
       kevent->keyval == GDK_ISO_Enter)
     {
       gimp_draw_tool_pause (draw_tool);
+      gtk_text_buffer_delete_selection (text_tool->text_buffer, TRUE, TRUE);
       gimp_text_tool_enter_text (text_tool, "\n");
       gimp_text_tool_update_layout (text_tool);
       gimp_draw_tool_resume (draw_tool);
@@ -1887,39 +1914,26 @@
   gimp_text_tool_enter_text (text_tool, str);
 }
 
-/* TODO: This function does nothing right now, 
- * but it will be used for special Input Methods */
 static void
 gimp_text_tool_preedit_changed_cb (GtkIMContext *context,
-                                   const gchar *str,
                                    GimpTextTool *text_tool)
 {
-  printf ("debug. preedit_changed\n");
 
   gchar *string;
   gint cursor;
-/*
-  gtk_im_context_get_preedit_string (text_tool->im_context, &string, NULL, &cursor);
-*/
+  
+  gtk_im_context_get_preedit_string (context,
+                                    &string, NULL, &cursor);
+  printf ("preedit changed. string: %s\n", string);
+  g_free (string);
 }
 
 static void
-gimp_text_tool_delete_text (GimpTextTool *text_tool)
+gimp_text_tool_update_proxy (GimpTextTool *text_tool)
 {
-  GtkTextIter cursor, start, end;
-
-  gtk_text_buffer_get_iter_at_mark (text_tool->text_buffer,
-                                   &cursor,
-                                    gtk_text_buffer_get_insert (text_tool->text_buffer));
-
-
-  if (gtk_text_buffer_get_has_selection (text_tool->text_buffer))
-    gtk_text_buffer_delete_selection (text_tool->text_buffer, TRUE, TRUE);
-  else
-    gtk_text_buffer_backspace (text_tool->text_buffer, &cursor, TRUE, TRUE);
-
   if (text_tool->text)
     {
+      GtkTextIter start, end;
       gchar *string;
 
       gtk_text_buffer_get_bounds (text_tool->text_buffer, &start, &end);
@@ -1934,6 +1948,24 @@
     }
 }
 
+void
+gimp_text_tool_delete_text (GimpTextTool *text_tool)
+{
+  GtkTextIter cursor, start, end;
+
+  gtk_text_buffer_get_iter_at_mark (text_tool->text_buffer,
+                                   &cursor,
+                                    gtk_text_buffer_get_insert (text_tool->text_buffer));
+
+
+  if (gtk_text_buffer_get_has_selection (text_tool->text_buffer))
+    gtk_text_buffer_delete_selection (text_tool->text_buffer, TRUE, TRUE);
+  else
+    gtk_text_buffer_backspace (text_tool->text_buffer, &cursor, TRUE, TRUE);
+
+  gimp_text_tool_update_proxy (text_tool);
+}
+
 static void
 gimp_text_tool_enter_text (GimpTextTool *text_tool,
                            const gchar *str)
@@ -1943,20 +1975,7 @@
   gtk_text_buffer_get_bounds (text_tool->text_buffer, &start, &end);
   gtk_text_buffer_insert_at_cursor (text_tool->text_buffer, str, -1);
 
-  if (text_tool->text)
-    {
-      gchar *string;
-
-      gtk_text_buffer_get_bounds (text_tool->text_buffer, &start, &end);
-      string = gtk_text_buffer_get_text (text_tool->text_buffer, &start, &end, TRUE);
-      g_object_set (text_tool->proxy, "text",
-                    string, NULL);
-      g_free (string);
-    }
-  else
-    {
-      gimp_text_tool_create_layer (text_tool, NULL);
-    }
+  gimp_text_tool_update_proxy (text_tool);
 }
 
 static void
@@ -1975,14 +1994,16 @@
 }
 
 static void
-gimp_text_tool_show_context_menu (GimpTextTool *text_tool, GimpCoords *coords)
+gimp_text_tool_show_context_menu (GimpTool *tool, GimpCoords *coords)
 {
-  GimpTool          *tool;
+  GimpTextTool      *text_tool;
   GimpDisplayShell  *shell;
   gint               cx, cy;
   gint               x1, y1, x2, y2;
 
-  tool = GIMP_TOOL (text_tool);
+  text_tool = GIMP_TEXT_TOOL (tool);
+
+  g_return_if_fail (GIMP_IS_TEXT_TOOL (text_tool));
 
   shell = GIMP_DISPLAY_SHELL (tool->display->shell);
   g_object_get (text_tool,
@@ -2008,3 +2029,34 @@
                             GTK_WIDGET (shell),
                             NULL, NULL, NULL, NULL);
 }
+
+void
+gimp_text_tool_clipboard_cut (GimpTextTool *text_tool)
+{
+  GtkClipboard *clipboard;
+  GdkAtom       clipboard_atom;
+
+  clipboard_atom = gdk_atom_intern ("CLIPBOARD", FALSE);
+  clipboard = gtk_clipboard_get (clipboard_atom);
+  gtk_text_buffer_cut_clipboard (text_tool->text_buffer, clipboard, TRUE);
+  gimp_text_tool_update_proxy (text_tool);
+}
+
+void
+gimp_text_tool_clipboard_copy (GimpTextTool *text_tool)
+{
+  GtkClipboard *clipboard;
+
+  clipboard = gtk_clipboard_get (gdk_atom_intern ("CLIPBOARD", FALSE));
+  gtk_text_buffer_copy_clipboard (text_tool->text_buffer, clipboard);
+}
+
+void
+gimp_text_tool_clipboard_paste (GimpTextTool *text_tool)
+{
+  GtkClipboard *clipboard;
+
+  clipboard = gtk_clipboard_get (gdk_atom_intern ("CLIPBOARD", FALSE));
+  gtk_text_buffer_paste_clipboard (text_tool->text_buffer, clipboard, NULL, TRUE);
+  gimp_text_tool_update_proxy (text_tool);
+}

Modified: branches/soc-2008-text/app/tools/gimptexttool.h
==============================================================================
--- branches/soc-2008-text/app/tools/gimptexttool.h	(original)
+++ branches/soc-2008-text/app/tools/gimptexttool.h	Wed Aug  6 16:26:32 2008
@@ -78,5 +78,9 @@
 void    gimp_text_tool_set_layer (GimpTextTool *text_tool,
                                   GimpLayer    *layer);
 
+void    gimp_text_tool_delete_text     (GimpTextTool *text_tool);
+void    gimp_text_tool_clipboard_cut   (GimpTextTool *text_tool);
+void    gimp_text_tool_clipboard_copy  (GimpTextTool *text_tool);
+void    gimp_text_tool_clipboard_paste (GimpTextTool *text_tool);
 
 #endif /* __GIMP_TEXT_TOOL_H__ */



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