[gimp] Some text deleteion refactoring
- From: Michael Natterer <mitch src gnome org>
- To: svn-commits-list gnome org
- Subject: [gimp] Some text deleteion refactoring
- Date: Wed, 24 Jun 2009 11:53:01 +0000 (UTC)
commit 2d8ced10c068bf6467334df11eebe9ee6f42fbf4
Author: Michael Natterer <mitch gimp org>
Date: Wed Jun 24 13:51:25 2009 +0200
Some text deleteion refactoring
Change public text tool API to gimp_text_tool_delete_selection() and
move delete and backspace code to their own handlers in preparation of
handling all text deletion types.
app/actions/text-tool-commands.c | 5 +--
app/tools/gimptexttool.c | 70 +++++++++++++++++++++++--------------
app/tools/gimptexttool.h | 3 +-
3 files changed, 46 insertions(+), 32 deletions(-)
---
diff --git a/app/actions/text-tool-commands.c b/app/actions/text-tool-commands.c
index e14b253..5e4317c 100644
--- a/app/actions/text-tool-commands.c
+++ b/app/actions/text-tool-commands.c
@@ -84,8 +84,7 @@ text_tool_delete_cmd_callback (GtkAction *action,
{
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, TRUE /* unused */);
+ gimp_text_tool_delete_selection (text_tool);
}
void
@@ -154,7 +153,7 @@ text_tool_clear_cmd_callback (GtkAction *action,
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, TRUE /* unused */);
+ gimp_text_tool_delete_selection (text_tool);
}
void
diff --git a/app/tools/gimptexttool.c b/app/tools/gimptexttool.c
index b25d540..4d4404d 100644
--- a/app/tools/gimptexttool.c
+++ b/app/tools/gimptexttool.c
@@ -1627,16 +1627,33 @@ gimp_text_tool_delete_from_cursor (GimpTextTool *text_tool,
GtkDeleteType type,
gint count)
{
+ GtkTextIter cursor;
+ GtkTextIter end;
+
g_printerr ("%s: %s count = %d\n",
G_STRFUNC,
g_enum_get_value (g_type_class_ref (GTK_TYPE_DELETE_TYPE),
type)->value_name,
count);
+ gtk_text_buffer_get_iter_at_mark (text_tool->text_buffer,
+ &cursor,
+ gtk_text_buffer_get_insert (text_tool->text_buffer));
+
+ end = cursor;
+
switch (type)
{
case GTK_DELETE_CHARS:
- gimp_text_tool_delete_text (text_tool, FALSE);
+ if (gtk_text_buffer_get_has_selection (text_tool->text_buffer))
+ {
+ gtk_text_buffer_delete_selection (text_tool->text_buffer, TRUE, TRUE);
+ return;
+ }
+ else
+ {
+ gtk_text_iter_forward_cursor_positions (&end, count);
+ }
break;
case GTK_DELETE_WORD_ENDS:
@@ -1660,12 +1677,33 @@ gimp_text_tool_delete_from_cursor (GimpTextTool *text_tool,
case GTK_DELETE_WHITESPACE:
break;
}
+
+ if (gtk_text_iter_compare (&cursor, &end))
+ {
+ gtk_text_buffer_delete_interactive (text_tool->text_buffer,
+ &cursor, &end, TRUE);
+ }
}
static void
-gimp_text_tool_backspace (GimpTextTool *text_tool)
+gimp_text_tool_backspace (GimpTextTool *text_tool)
{
- gimp_text_tool_delete_text (text_tool, TRUE);
+ if (gtk_text_buffer_get_has_selection (text_tool->text_buffer))
+ {
+ gtk_text_buffer_delete_selection (text_tool->text_buffer, TRUE, TRUE);
+ }
+ else
+ {
+ GtkTextMark *cursor_mark;
+ GtkTextIter cursor;
+
+ cursor_mark = gtk_text_buffer_get_insert (text_tool->text_buffer);
+
+ gtk_text_buffer_get_iter_at_mark (text_tool->text_buffer,
+ &cursor, cursor_mark);
+
+ gtk_text_buffer_backspace (text_tool->text_buffer, &cursor, TRUE, TRUE);
+ }
}
@@ -2478,10 +2516,7 @@ static void
gimp_text_tool_enter_text (GimpTextTool *text_tool,
const gchar *str)
{
- if (gtk_text_buffer_get_has_selection (text_tool->text_buffer))
- {
- gtk_text_buffer_delete_selection (text_tool->text_buffer, TRUE, TRUE);
- }
+ gimp_text_tool_delete_selection (text_tool);
gtk_text_buffer_insert_at_cursor (text_tool->text_buffer, str, -1);
}
@@ -2613,31 +2648,12 @@ gimp_text_tool_get_has_text_selection (GimpTextTool *text_tool)
}
void
-gimp_text_tool_delete_text (GimpTextTool *text_tool,
- gboolean backspace)
+gimp_text_tool_delete_selection (GimpTextTool *text_tool)
{
- GtkTextIter cursor;
-
- 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 if (backspace)
- {
- gtk_text_buffer_backspace (text_tool->text_buffer, &cursor, TRUE, TRUE);
- }
- else
- {
- GtkTextIter end = cursor;
-
- gtk_text_iter_forward_cursor_positions (&end, 1);
- gtk_text_buffer_delete_interactive (text_tool->text_buffer,
- &cursor, &end, TRUE);
- }
}
void
diff --git a/app/tools/gimptexttool.h b/app/tools/gimptexttool.h
index b87a48a..746de54 100644
--- a/app/tools/gimptexttool.h
+++ b/app/tools/gimptexttool.h
@@ -94,8 +94,7 @@ void gimp_text_tool_set_layer (GimpTextTool *text_tool,
gboolean gimp_text_tool_get_has_text_selection (GimpTextTool *text_tool);
-void gimp_text_tool_delete_text (GimpTextTool *text_tool,
- gboolean backspace);
+void gimp_text_tool_delete_selection (GimpTextTool *text_tool);
void gimp_text_tool_clipboard_cut (GimpTextTool *text_tool);
void gimp_text_tool_clipboard_copy (GimpTextTool *text_tool,
gboolean use_clipboard);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]