[gtksourceview] Completion: simplify some utils functions
- From: SÃbastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview] Completion: simplify some utils functions
- Date: Sat, 16 Feb 2013 18:49:01 +0000 (UTC)
commit 8ef618003d9e1fc184be61b6590e89891d34dcf9
Author: SÃbastien Wilmet <swilmet gnome org>
Date: Sat Feb 16 19:15:34 2013 +0100
Completion: simplify some utils functions
Some parameters or return values were not used.
gtksourceview/gtksourcecompletion.c | 10 +--
gtksourceview/gtksourcecompletionutils.c | 108 +++++++----------------------
gtksourceview/gtksourcecompletionutils.h | 5 +-
3 files changed, 30 insertions(+), 93 deletions(-)
---
diff --git a/gtksourceview/gtksourcecompletion.c b/gtksourceview/gtksourcecompletion.c
index d73307c..b159fb6 100644
--- a/gtksourceview/gtksourcecompletion.c
+++ b/gtksourceview/gtksourcecompletion.c
@@ -335,8 +335,7 @@ activate_current_proposal (GtkSourceCompletion *completion)
}
else
{
- gtk_source_completion_utils_replace_current_word (GTK_SOURCE_BUFFER (buffer),
- text);
+ gtk_source_completion_utils_replace_current_word (buffer, text);
}
g_free (text);
@@ -1513,14 +1512,9 @@ update_typing_offsets (GtkSourceCompletion *completion)
GtkTextBuffer *buffer;
GtkTextIter start;
GtkTextIter end;
- gchar *word;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (completion->priv->view));
- word = gtk_source_completion_utils_get_word_iter (GTK_SOURCE_BUFFER (buffer),
- NULL,
- &start,
- &end);
- g_free (word);
+ gtk_source_completion_utils_get_word_iter (buffer, &start, &end);
completion->priv->typing_line = gtk_text_iter_get_line (&start);
completion->priv->typing_line_offset = gtk_text_iter_get_line_offset (&start);
diff --git a/gtksourceview/gtksourcecompletionutils.c b/gtksourceview/gtksourcecompletionutils.c
index 93a2f09..ac8b32f 100644
--- a/gtksourceview/gtksourcecompletionutils.c
+++ b/gtksourceview/gtksourcecompletionutils.c
@@ -46,58 +46,31 @@ gtk_source_completion_utils_is_separator (const gunichar ch)
/**
* gtk_source_completion_utils_get_word_iter:
- * @source_buffer: a #GtkSourceBuffer.
- * @current: (allow-none): the iter of the position to consider, or %NULL to use the current insert position
- * @start_word: (allow-none): if not %NULL then assign it the start position of the word
- * @end_word: (allow-none): if not %NULL then assing it the end position of the word
- *
- * Returns: the current word.
+ * @buffer: a #GtkTextBuffer.
+ * @start_word: assign it the start position of the word
+ * @end_word: assign it the end position of the word
*/
-gchar *
-gtk_source_completion_utils_get_word_iter (GtkSourceBuffer *source_buffer,
- GtkTextIter *current,
- GtkTextIter *start_word,
- GtkTextIter *end_word)
+void
+gtk_source_completion_utils_get_word_iter (GtkTextBuffer *buffer,
+ GtkTextIter *start_word,
+ GtkTextIter *end_word)
{
- GtkTextBuffer *text_buffer;
- gunichar ch;
- gboolean no_doc_start;
-
- text_buffer = GTK_TEXT_BUFFER (source_buffer);
-
- if (current == NULL)
- {
- gtk_text_buffer_get_iter_at_mark (text_buffer,
- start_word,
- gtk_text_buffer_get_insert (text_buffer));
- }
- else
- {
- *start_word = *current;
- }
+ gtk_text_buffer_get_iter_at_mark (buffer,
+ end_word,
+ gtk_text_buffer_get_insert (buffer));
- *end_word = *start_word;
+ *start_word = *end_word;
- while ((no_doc_start = gtk_text_iter_backward_char (start_word)) == TRUE)
+ while (gtk_text_iter_backward_char (start_word))
{
- ch = gtk_text_iter_get_char (start_word);
+ gunichar ch = gtk_text_iter_get_char (start_word);
if (gtk_source_completion_utils_is_separator (ch))
{
- break;
+ gtk_text_iter_forward_char (start_word);
+ return;
}
}
-
- if (!no_doc_start)
- {
- gtk_text_buffer_get_start_iter (text_buffer, start_word);
- return gtk_text_iter_get_text (start_word, end_word);
- }
- else
- {
- gtk_text_iter_forward_char (start_word);
- return gtk_text_iter_get_text (start_word, end_word);
- }
}
static void
@@ -134,26 +107,24 @@ get_iter_pos (GtkSourceView *source_view,
*height = location.height;
}
-static void
-gtk_source_completion_utils_replace_word (GtkSourceBuffer *source_buffer,
- GtkTextIter *iter,
- const gchar *text)
+/**
+ * gtk_source_completion_utils_replace_current_word:
+ * @buffer: a #GtkTextBuffer.
+ * @text: (allow-none): The text to be inserted instead of the current word.
+ *
+ * Replaces the current word in the #GtkSourceBuffer with the new word.
+ */
+void
+gtk_source_completion_utils_replace_current_word (GtkTextBuffer *buffer,
+ const gchar *text)
{
- GtkTextBuffer *buffer;
- gchar *word;
GtkTextIter word_start;
GtkTextIter word_end;
- GtkTextMark *mark;
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (source_buffer));
+ gtk_source_completion_utils_get_word_iter (buffer, &word_start, &word_end);
- buffer = GTK_TEXT_BUFFER (source_buffer);
gtk_text_buffer_begin_user_action (buffer);
- mark = gtk_text_buffer_create_mark (buffer, NULL, iter, TRUE);
- word = gtk_source_completion_utils_get_word_iter (source_buffer, iter, &word_start, &word_end);
- g_free (word);
-
gtk_text_buffer_delete (buffer, &word_start, &word_end);
if (text != NULL)
@@ -161,36 +132,9 @@ gtk_source_completion_utils_replace_word (GtkSourceBuffer *source_buffer,
gtk_text_buffer_insert (buffer, &word_start, text, -1);
}
- /* Reinitialize iter */
- gtk_text_buffer_get_iter_at_mark (buffer, iter, mark);
- gtk_text_buffer_delete_mark (buffer, mark);
gtk_text_buffer_end_user_action (buffer);
}
-/**
- * gtk_source_completion_utils_replace_current_word:
- * @source_buffer: a #GtkSourceBuffer.
- * @text: (allow-none): The text to be inserted instead of the current word.
- *
- * Replaces the current word in the #GtkSourceBuffer with the new word.
- */
-void
-gtk_source_completion_utils_replace_current_word (GtkSourceBuffer *source_buffer,
- const gchar *text)
-{
- GtkTextIter iter;
- GtkTextMark *mark;
-
- g_return_if_fail (GTK_SOURCE_IS_BUFFER (source_buffer));
-
- mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (source_buffer));
- gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (source_buffer),
- &iter,
- mark);
-
- gtk_source_completion_utils_replace_word (source_buffer, &iter, text);
-}
-
static void
compensate_for_gravity (GtkWindow *window,
gint *x,
diff --git a/gtksourceview/gtksourcecompletionutils.h b/gtksourceview/gtksourcecompletionutils.h
index 57dfe01..a545632 100644
--- a/gtksourceview/gtksourcecompletionutils.h
+++ b/gtksourceview/gtksourcecompletionutils.h
@@ -28,13 +28,12 @@
G_BEGIN_DECLS
G_GNUC_INTERNAL
-gchar *gtk_source_completion_utils_get_word_iter (GtkSourceBuffer *source_buffer,
- GtkTextIter *current,
+void gtk_source_completion_utils_get_word_iter (GtkTextBuffer *buffer,
GtkTextIter *start_word,
GtkTextIter *end_word);
G_GNUC_INTERNAL
-void gtk_source_completion_utils_replace_current_word (GtkSourceBuffer *source_buffer,
+void gtk_source_completion_utils_replace_current_word (GtkTextBuffer *buffer,
const gchar *text);
G_GNUC_INTERNAL
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]