[gtksourceview/wip/compact-completion: 6/6] Completion: move remaining utils functions



commit 65433c3d0ca20a9327346e6335e867d9bd350063
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Sun Apr 28 22:31:36 2013 +0200

    Completion: move remaining utils functions
    
    The remaining utils functions were used only in Completion.

 docs/reference/Makefile.am               |    1 -
 gtksourceview/Makefile.am                |    2 -
 gtksourceview/gtksourcecompletion.c      |   66 ++++++++++++++++++-
 gtksourceview/gtksourcecompletioninfo.c  |    1 -
 gtksourceview/gtksourcecompletionitem.c  |    1 -
 gtksourceview/gtksourcecompletionitem.h  |    3 +-
 gtksourceview/gtksourcecompletionutils.c |  102 ------------------------------
 gtksourceview/gtksourcecompletionutils.h |   41 ------------
 gtksourceview/gtksourceview.c            |    1 -
 9 files changed, 64 insertions(+), 154 deletions(-)
---
diff --git a/docs/reference/Makefile.am b/docs/reference/Makefile.am
index e523956..0ca15ae 100644
--- a/docs/reference/Makefile.am
+++ b/docs/reference/Makefile.am
@@ -23,7 +23,6 @@ IGNORE_HFILES =                                       \
        config.h                                \
        gtksourcecompletionmodel.h              \
        gtksourcecompletion-private.h           \
-       gtksourcecompletionutils.h              \
        gtksourcecompletionwordsbuffer.h        \
        gtksourcecompletionwordslibrary.h       \
        gtksourcecompletionwordsproposal.h      \
diff --git a/gtksourceview/Makefile.am b/gtksourceview/Makefile.am
index ea451b6..bf91768 100644
--- a/gtksourceview/Makefile.am
+++ b/gtksourceview/Makefile.am
@@ -48,7 +48,6 @@ libgtksourceview_headers =                    \
 libgtksourceview_private_headers = \
        gtksourcecompletionmodel.h              \
        gtksourcecompletion-private.h           \
-       gtksourcecompletionutils.h              \
        gtksourcecontextengine.h                \
        gtksourceengine.h                       \
        gtksourcegutter-private.h               \
@@ -67,7 +66,6 @@ libgtksourceview_private_headers = \
 
 libgtksourceview_private_c_files = \
        gtksourcecompletionmodel.c      \
-       gtksourcecompletionutils.c      \
        gtksourcecontextengine.c        \
        gtksourceengine.c               \
        gtksourcepixbufhelper.c         \
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index e0fee4a..7e454d5 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -76,13 +76,13 @@
 
 #include "gtksourcecompletion.h"
 #include "gtksourcecompletion-private.h"
-#include "gtksourcecompletionutils.h"
 #include "gtksourcecompletionmodel.h"
 #include "gtksourcecompletioncontext.h"
 #include "gtksourcecompletioninfo.h"
 #include "gtksourcecompletionproposal.h"
 #include "gtksourcecompletionprovider.h"
 #include "gtksourcebuffer.h"
+#include "gtksourceview.h"
 #include "gtksourceview-marshal.h"
 #include "gtksourceview-i18n.h"
 
@@ -365,6 +365,66 @@ reset_completion (GtkSourceCompletion *completion)
        completion->priv->active_providers = NULL;
 }
 
+/* A separator is a character like (, a space etc. An _ is not a separator. */
+static gboolean
+is_separator (const gunichar ch)
+{
+       if (g_unichar_isprint (ch) &&
+           (g_unichar_isalnum (ch) || ch == g_utf8_get_char ("_")))
+       {
+               return FALSE;
+       }
+
+       return TRUE;
+}
+
+/* Assigns @start_word to the start position of the word, and @end_word to the
+ * end position.
+ */
+static void
+get_word_iter (GtkTextBuffer *buffer,
+              GtkTextIter   *start_word,
+              GtkTextIter   *end_word)
+{
+       gtk_text_buffer_get_iter_at_mark (buffer,
+                                         end_word,
+                                         gtk_text_buffer_get_insert (buffer));
+
+       *start_word = *end_word;
+
+       while (gtk_text_iter_backward_char (start_word))
+       {
+               gunichar ch = gtk_text_iter_get_char (start_word);
+
+               if (is_separator (ch))
+               {
+                       gtk_text_iter_forward_char (start_word);
+                       return;
+               }
+       }
+}
+
+static void
+replace_current_word (GtkTextBuffer *buffer,
+                     const gchar   *new_text)
+{
+       GtkTextIter word_start;
+       GtkTextIter word_end;
+
+       get_word_iter (buffer, &word_start, &word_end);
+
+       gtk_text_buffer_begin_user_action (buffer);
+
+       gtk_text_buffer_delete (buffer, &word_start, &word_end);
+
+       if (new_text != NULL)
+       {
+               gtk_text_buffer_insert (buffer, &word_start, new_text, -1);
+       }
+
+       gtk_text_buffer_end_user_action (buffer);
+}
+
 static void
 update_window_position (GtkSourceCompletion *completion)
 {
@@ -392,7 +452,7 @@ update_window_position (GtkSourceCompletion *completion)
                GtkTextIter end_word;
                GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (completion->priv->view));
 
-               gtk_source_completion_utils_get_word_iter (buffer, &iter, &end_word);
+               get_word_iter (buffer, &iter, &end_word);
        }
 
        gtk_source_completion_info_move_to_iter (completion->priv->main_window,
@@ -558,7 +618,7 @@ gtk_source_completion_activate_proposal (GtkSourceCompletion *completion)
                }
                else
                {
-                       gtk_source_completion_utils_replace_current_word (buffer, text);
+                       replace_current_word (buffer, text);
                }
 
                g_free (text);
diff --git a/gtksourceview/gtksourcecompletioninfo.c b/gtksourceview/gtksourcecompletioninfo.c
index 21bba12..fafc69e 100644
--- a/gtksourceview/gtksourcecompletioninfo.c
+++ b/gtksourceview/gtksourcecompletioninfo.c
@@ -57,7 +57,6 @@
  */
 
 #include <gtksourceview/gtksourcecompletioninfo.h>
-#include "gtksourcecompletionutils.h"
 #include "gtksourceview-i18n.h"
 
 struct _GtkSourceCompletionInfoPrivate
diff --git a/gtksourceview/gtksourcecompletionitem.c b/gtksourceview/gtksourcecompletionitem.c
index 193e431..dc2824c 100644
--- a/gtksourceview/gtksourcecompletionitem.c
+++ b/gtksourceview/gtksourcecompletionitem.c
@@ -30,7 +30,6 @@
 
 #include "gtksourcecompletionitem.h"
 #include "gtksourcecompletionproposal.h"
-#include "gtksourcecompletionutils.h"
 #include "gtksourceview-i18n.h"
 
 #define GTK_SOURCE_COMPLETION_ITEM_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), 
GTK_SOURCE_TYPE_COMPLETION_ITEM, GtkSourceCompletionItemPrivate))
diff --git a/gtksourceview/gtksourcecompletionitem.h b/gtksourceview/gtksourcecompletionitem.h
index fd9e9eb..2c9e3f5 100644
--- a/gtksourceview/gtksourcecompletionitem.h
+++ b/gtksourceview/gtksourcecompletionitem.h
@@ -22,8 +22,7 @@
 #ifndef __GTK_SOURCE_COMPLETION_ITEM_H__
 #define __GTK_SOURCE_COMPLETION_ITEM_H__
 
-#include <glib-object.h>
-#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gtk/gtk.h>
 #include <gtksourceview/gtksourcetypes.h>
 
 G_BEGIN_DECLS
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index f686faf..01e748d 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -42,7 +42,6 @@
 #include "gtksourcestylescheme.h"
 #include "gtksourcecompletionprovider.h"
 #include "gtksourcecompletion-private.h"
-#include "gtksourcecompletionutils.h"
 #include "gtksourcegutter.h"
 #include "gtksourcegutter-private.h"
 #include "gtksourcegutterrendererlines.h"


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