[gtksourceview/gtksourcecompletion] Add minimum word size property



commit 13236b7edfa7c3b30303bf800bd43c048e995052
Author: Jesse van den Kieboom <jessevdk gnome org>
Date:   Mon Sep 21 23:19:57 2009 +0200

    Add minimum word size property

 .../words/gtksourcecompletionwords.c               |   72 ++++++++++++++++----
 .../words/gtksourcecompletionwordsbuffer.c         |   22 +++++-
 .../words/gtksourcecompletionwordsbuffer.h         |    6 +-
 3 files changed, 80 insertions(+), 20 deletions(-)
---
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwords.c b/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
index 2cd7a6a..dc5e723 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwords.c
@@ -39,7 +39,8 @@ enum
 	PROP_NAME,
 	PROP_ICON,
 	PROP_PROPOSALS_BATCH_SIZE,
-	PROP_SCAN_BATCH_SIZE
+	PROP_SCAN_BATCH_SIZE,
+	PROP_MINIMUM_WORD_SIZE
 };
 
 struct _GtkSourceCompletionWordsPrivate
@@ -58,6 +59,7 @@ struct _GtkSourceCompletionWordsPrivate
 	
 	guint proposals_batch_size;
 	guint scan_batch_size;
+	guint minimum_word_size;
 	
 	GtkSourceCompletionWordsLibrary *library;
 	GList *buffers;
@@ -97,13 +99,6 @@ gtk_source_completion_words_get_icon (GtkSourceCompletionProvider *self)
 }
 
 static gboolean
-gtk_source_completion_words_match (GtkSourceCompletionProvider *provider,
-                                   GtkSourceCompletionContext  *context)
-{
-	return TRUE;
-}
-
-static gboolean
 is_word_char (gunichar ch)
 {
 	return g_unichar_isprint (ch) && 
@@ -232,6 +227,25 @@ add_in_idle (GtkSourceCompletionWords *words)
 	return !finished;
 }
 
+static gboolean
+gtk_source_completion_words_match (GtkSourceCompletionProvider *provider,
+                                   GtkSourceCompletionContext  *context)
+{
+	GtkSourceCompletionWords *words = GTK_SOURCE_COMPLETION_WORDS (provider);
+	GtkTextIter iter;
+	gchar *word;
+	gboolean ret;
+
+	gtk_source_completion_context_get_iter (context, &iter);
+	word = get_word_at_iter (words, &iter);
+	
+	ret = g_utf8_strlen (word, -1) >= words->priv->minimum_word_size;
+	
+	g_free (word);
+	
+	return ret;
+}
+
 static void
 gtk_source_completion_words_populate (GtkSourceCompletionProvider *provider,
                                       GtkSourceCompletionContext  *context)
@@ -328,6 +342,19 @@ update_buffers_batch_size (GtkSourceCompletionWords *words)
 }
 
 static void
+update_buffers_minimum_word_size (GtkSourceCompletionWords *words)
+{
+	GList *item;
+	
+	for (item = words->priv->buffers; item; item = g_list_next (item))
+	{
+		BufferBinding *binding = (BufferBinding *)item->data;
+		gtk_source_completion_words_buffer_set_minimum_word_size (binding->buffer,
+		                                                          words->priv->minimum_word_size);
+	}
+}
+
+static void
 gtk_source_completion_words_set_property (GObject      *object,
                                           guint         prop_id,
                                           const GValue *value,
@@ -358,11 +385,12 @@ gtk_source_completion_words_set_property (GObject      *object,
 			self->priv->proposals_batch_size = g_value_get_uint (value);
 		break;
 		case PROP_SCAN_BATCH_SIZE:
-		{
 			self->priv->scan_batch_size = g_value_get_uint (value);
-			
 			update_buffers_batch_size (self);
-		}
+		break;
+		case PROP_MINIMUM_WORD_SIZE:
+			self->priv->minimum_word_size = g_value_get_uint (value);
+			update_buffers_minimum_word_size (self);
 		break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -392,6 +420,9 @@ gtk_source_completion_words_get_property (GObject    *object,
 		case PROP_SCAN_BATCH_SIZE:
 			g_value_set_uint (value, self->priv->scan_batch_size);
 		break;
+		case PROP_MINIMUM_WORD_SIZE:
+			g_value_set_uint (value, self->priv->minimum_word_size);
+		break;
 		default:
 			G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 		break;
@@ -444,6 +475,16 @@ gtk_source_completion_words_class_init (GtkSourceCompletionWordsClass *klass)
 	                                                    20,
 	                                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
 	
+	g_object_class_install_property (object_class,
+	                                 PROP_MINIMUM_WORD_SIZE,
+	                                 g_param_spec_uint ("minimum-word-size",
+	                                                    _("Minimum Word Size"),
+	                                                    _("The minimum word size to complete"),
+	                                                    2,
+	                                                    G_MAXUINT,
+	                                                    3,
+	                                                    G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
+	
 	g_type_class_add_private (object_class, sizeof(GtkSourceCompletionWordsPrivate));
 }
 
@@ -515,9 +556,12 @@ gtk_source_completion_words_register (GtkSourceCompletionWords *words,
 	}
 	
 	buf = gtk_source_completion_words_buffer_new (words->priv->library,
-	                                              buffer,
-	                                              words->priv->scan_batch_size);
-
+	                                              buffer);
+	
+	gtk_source_completion_words_buffer_set_scan_batch_size (buffer,
+	                                                        words->priv->scan_batch_size);
+	gtk_source_completion_words_buffer_set_minimum_word_size (buffer,
+	                                                          words->priv->minimum_word_size);
 	
 	binding = g_slice_new (BufferBinding);
 	binding->words = words;
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c b/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
index 379cb31..26c5f3d 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.c
@@ -54,6 +54,7 @@ struct _GtkSourceCompletionWordsBufferPrivate
 	
 	guint ext_signal_handlers[NUM_EXT_SIGNALS];
 	guint scan_batch_size;
+	guint minimum_word_size;
 	
 	guint lock_handler_id;
 	guint unlock_handler_id;
@@ -159,6 +160,9 @@ static void
 gtk_source_completion_words_buffer_init (GtkSourceCompletionWordsBuffer *self)
 {
 	self->priv = GTK_SOURCE_COMPLETION_WORDS_BUFFER_GET_PRIVATE (self);
+	
+	self->priv->scan_batch_size = 20;
+	self->priv->minimum_word_size = 3;
 }
 
 static void
@@ -660,20 +664,17 @@ on_library_unlock (GtkSourceCompletionWordsBuffer *buffer)
 
 GtkSourceCompletionWordsBuffer *
 gtk_source_completion_words_buffer_new (GtkSourceCompletionWordsLibrary *library,
-                                        GtkTextBuffer                   *buffer,
-                                        guint                            scan_batch_size)
+                                        GtkTextBuffer                   *buffer)
 {
 	GtkSourceCompletionWordsBuffer *ret;
 	
 	g_return_val_if_fail (GTK_IS_SOURCE_COMPLETION_WORDS_LIBRARY (library), NULL);
 	g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
-	g_return_val_if_fail (scan_batch_size > 0, NULL);
 	
 	ret = g_object_new (GTK_TYPE_SOURCE_COMPLETION_WORDS_BUFFER, NULL);
 
 	ret->priv->library = g_object_ref (library);
 	ret->priv->buffer = g_object_ref (buffer);
-	ret->priv->scan_batch_size = scan_batch_size;
 	
 	ret->priv->lock_handler_id =
 		g_signal_connect_swapped (ret->priv->library,
@@ -705,5 +706,18 @@ gtk_source_completion_words_buffer_set_scan_batch_size (GtkSourceCompletionWords
                                                         guint                           size)
 {
 	g_return_if_fail (GTK_IS_SOURCE_COMPLETION_WORDS_BUFFER (buffer));
+	g_return_if_fail (size != 0);
+
 	buffer->priv->scan_batch_size = size;
 }
+
+void
+gtk_source_completion_words_buffer_set_minimum_word_size (GtkSourceCompletionWordsBuffer *buffer,
+                                                          guint                           size)
+{
+	g_return_if_fail (GTK_IS_SOURCE_COMPLETION_WORDS_BUFFER (buffer));
+	g_return_if_fail (size != 0);
+
+	buffer->priv->minimum_word_size = size;
+}
+
diff --git a/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.h b/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.h
index 293b859..2703f04 100644
--- a/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.h
+++ b/gtksourceview/completion-providers/words/gtksourcecompletionwordsbuffer.h
@@ -56,14 +56,16 @@ GType gtk_source_completion_words_buffer_get_type (void) G_GNUC_CONST;
 
 GtkSourceCompletionWordsBuffer *
 		 gtk_source_completion_words_buffer_new 	(GtkSourceCompletionWordsLibrary *library,
-								 GtkTextBuffer                   *buffer,
-								 guint                            process_batch);
+								 GtkTextBuffer                   *buffer);
 
 GtkTextBuffer 	*gtk_source_completion_words_buffer_get_buffer	(GtkSourceCompletionWordsBuffer  *buffer);
 
 void		 gtk_source_completion_words_buffer_set_scan_batch_size (GtkSourceCompletionWordsBuffer *buffer,
                                                                          guint                           size);
 
+void		 gtk_source_completion_words_buffer_set_minimum_word_size (GtkSourceCompletionWordsBuffer *buffer,
+                                                                           guint                           size);
+
 G_END_DECLS
 
 #endif /* __GTK_SOURCE_COMPLETION_WORDS_BUFFER_H__ */



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