From 48eb979db56557a0f96b0e195424789f64a1f429 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Barbero=20Rodr=C3=ADguez?= Date: Sat, 12 Sep 2009 00:30:18 +0200 Subject: [PATCH] Use of GtkTextView instead of GtkSourceView We have not a real dependency on GtkSourceView, we will use GtkTextView instead. --- gtksourcecompletion/gsc-completion-priv.h | 32 ----------------- gtksourcecompletion/gsc-completion.c | 35 +++++++++--------- gtksourcecompletion/gsc-completion.h | 8 ++--- gtksourcecompletion/gsc-context.c | 2 +- gtksourcecompletion/gsc-info.c | 4 +-- gtksourcecompletion/gsc-model.c | 6 ---- gtksourcecompletion/gsc-utils.c | 44 ++++++++++------------- gtksourcecompletion/gsc-utils.h | 14 ++++---- po/Makefile.in.in | 2 +- test/completion-simple.c | 5 +-- 10 files changed, 51 insertions(+), 101 deletions(-) delete mode 100644 gtksourcecompletion/gsc-completion-priv.h diff --git a/gtksourcecompletion/gsc-completion-priv.h b/gtksourcecompletion/gsc-completion-priv.h deleted file mode 100644 index c7b93ca..0000000 --- a/gtksourcecompletion/gsc-completion-priv.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * gsc-private.h - * This file is part of gsc - * - * Copyright (C) 2009 - Jesse van den Kieboom - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, - * Boston, MA 02110-1301 USA - */ - -#ifndef __GSC_COMPLETION_PIVATE_H__ -#define __GSC_COMPLETION_PIVATE_H__ - -#include -#include "gsc-completion.h" - -GscCompletion*gsc_completion_new (struct _GtkSourceView *source_view); - -#endif /* __GSC_COMPLETION_PIVATE_H__ */ - diff --git a/gtksourcecompletion/gsc-completion.c b/gtksourcecompletion/gsc-completion.c index 14a874c..3a1ba13 100644 --- a/gtksourcecompletion/gsc-completion.c +++ b/gtksourcecompletion/gsc-completion.c @@ -36,7 +36,6 @@ #include "gsc-model.h" #include "gsc-context.h" #include -#include #include #define WINDOW_WIDTH 350 @@ -97,7 +96,7 @@ struct _GscCompletionPrivate gboolean select_on_show; /* Completion management */ - GtkSourceView *view; + GtkTextView *view; GList *providers; GHashTable *capability_map; @@ -126,8 +125,6 @@ G_DEFINE_TYPE(GscCompletion, gsc_completion, G_TYPE_OBJECT); * call twice to gsc_proposal_new, the second time it returns * the previous created GscCompletion, not creates a new one * - * FIXME We will remove this functions when we will integrate - * Gsc in GtkSourceView */ static GHashTable *gsccompletion_map = NULL; @@ -298,7 +295,7 @@ activate_current_proposal (GscCompletion *completion) if (!activated) { text = gsc_proposal_get_text (proposal); - gsc_utils_replace_current_word (GTK_SOURCE_BUFFER (buffer), + gsc_utils_replace_current_word (buffer, text ? text : NULL, -1); } @@ -1007,7 +1004,7 @@ gsc_completion_user_request (GscCompletion *completion) } static gboolean -view_key_press_event_cb (GtkSourceView *view, +view_key_press_event_cb (GtkTextView *view, GdkEventKey *event, GscCompletion *completion) { @@ -1117,7 +1114,7 @@ update_typing_offsets (GscCompletion *completion) gchar *word; buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (completion->priv->view)); - word = gsc_utils_get_word_iter (GTK_SOURCE_BUFFER (buffer), + word = gsc_utils_get_word_iter (buffer, NULL, &start, &end); @@ -1157,7 +1154,7 @@ show_auto_completion (GscCompletion *completion) return FALSE; } - word = gsc_utils_get_word_iter (GTK_SOURCE_BUFFER (buffer), + word = gsc_utils_get_word_iter (buffer, &iter, &start, &end); @@ -1461,15 +1458,15 @@ gsc_completion_class_init (GscCompletionClass *klass) /** * Gsc:view: * - * The #GtkSourceView bound to the completion object. + * The #GtkTextView bound to the completion object. * */ g_object_class_install_property (object_class, PROP_VIEW, g_param_spec_object ("view", _("View"), - _("The GtkSourceView bound to the completion"), - GTK_TYPE_SOURCE_VIEW, + _("The GtkTextView bound to the completion"), + GTK_TYPE_TEXT_VIEW, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY)); /** @@ -2079,12 +2076,12 @@ gsc_completion_show (GscCompletion *completion, if (place == NULL) { gsc_utils_move_to_cursor (GTK_WINDOW (completion->priv->window), - GTK_SOURCE_VIEW (completion->priv->view)); + completion->priv->view); } else { gsc_utils_move_to_iter (GTK_WINDOW (completion->priv->window), - GTK_SOURCE_VIEW (completion->priv->view), + completion->priv->view, place); } @@ -2155,16 +2152,16 @@ gsc_completion_error_quark (void) /** * gsc_completion_new: - * @view: A #GtkSourceView + * @view: A #GtkTextView * * Create a new #GscCompletion associated with @view. * * Returns: The new #Gsc. */ GscCompletion * -gsc_completion_new (GtkSourceView *view) +gsc_completion_new (GtkTextView *view) { - g_return_val_if_fail (GTK_IS_SOURCE_VIEW (view), NULL); + g_return_val_if_fail (GTK_IS_TEXT_VIEW (view), NULL); GscCompletion *self = g_object_new (GSC_TYPE_COMPLETION, "view", view, @@ -2310,11 +2307,11 @@ gsc_completion_get_info_window (GscCompletion *completion) * gsc_completion_get_view: * @completion: A #Gsc * - * The #GtkSourceView associated with @completion. + * The #GtkTextView associated with @completion. * - * Returns: The #GtkSourceView associated with @completion. + * Returns: The #GtkTextView associated with @completion. */ -GtkSourceView * +GtkTextView * gsc_completion_get_view (GscCompletion *completion) { g_return_val_if_fail (GSC_IS_COMPLETION (completion), NULL); diff --git a/gtksourcecompletion/gsc-completion.h b/gtksourcecompletion/gsc-completion.h index c22ab36..8246a85 100644 --- a/gtksourcecompletion/gsc-completion.h +++ b/gtksourcecompletion/gsc-completion.h @@ -24,7 +24,6 @@ #define GSC_COMPLETION_H #include -#include #include "gsc-info.h" #include "gsc-provider.h" @@ -52,9 +51,6 @@ typedef enum GSC_COMPLETION_ERROR_NOT_BOUND, } GscCompletionError; -/* Forward declaration of GtkSourceView */ -struct _GtkSourceView; - struct _GscCompletion { GObject parent; @@ -79,7 +75,7 @@ GType gsc_completion_get_type (void) G_GNUC_CONST; GQuark gsc_completion_error_quark (void); -GscCompletion *gsc_completion_new (GtkSourceView *source_view); +GscCompletion *gsc_completion_new (GtkTextView *source_view); gboolean gsc_completion_add_provider (GscCompletion *completion, GscProvider *provider, @@ -100,7 +96,7 @@ void gsc_completion_hide (GscCompletion *completion); GscInfo * gsc_completion_get_info_window (GscCompletion *completion); -GtkSourceView *gsc_completion_get_view (GscCompletion *completion); +GtkTextView *gsc_completion_get_view (GscCompletion *completion); G_END_DECLS diff --git a/gtksourcecompletion/gsc-context.c b/gtksourcecompletion/gsc-context.c index f64cf05..803662d 100644 --- a/gtksourcecompletion/gsc-context.c +++ b/gtksourcecompletion/gsc-context.c @@ -151,7 +151,7 @@ update_criteria (GscContext *context) g_free (context->priv->criteria); context->priv->criteria = - gsc_utils_get_word (GTK_SOURCE_BUFFER (gtk_text_view_get_buffer (context->priv->view))); + gsc_utils_get_word (gtk_text_view_get_buffer (context->priv->view)); } GscContext* diff --git a/gtksourcecompletion/gsc-info.c b/gtksourcecompletion/gsc-info.c index fb6aa4f..7296ec6 100644 --- a/gtksourcecompletion/gsc-info.c +++ b/gtksourcecompletion/gsc-info.c @@ -411,7 +411,7 @@ gsc_completion_info_move_to_iter (GscInfo *info, GtkTextIter start; g_return_if_fail (GSC_IS_INFO (info)); - g_return_if_fail (GTK_IS_SOURCE_VIEW (view)); + g_return_if_fail (GTK_IS_TEXT_VIEW (view)); if (iter == NULL) { @@ -425,7 +425,7 @@ gsc_completion_info_move_to_iter (GscInfo *info, } gsc_utils_move_to_iter (GTK_WINDOW (info), - GTK_SOURCE_VIEW (view), + view, &start); } diff --git a/gtksourcecompletion/gsc-model.c b/gtksourcecompletion/gsc-model.c index 38bcd6f..b17bc4f 100644 --- a/gtksourcecompletion/gsc-model.c +++ b/gtksourcecompletion/gsc-model.c @@ -303,7 +303,6 @@ tree_model_iter_n_children (GtkTreeModel *tree_model, if (iter == NULL) { - g_debug ("n children num: %i", GSC_MODEL (tree_model)->priv->num); return GSC_MODEL (tree_model)->priv->num; } else @@ -796,8 +795,6 @@ gsc_model_set_proposals (GscModel *model, g_hash_table_destroy (rinfo.proposals); } - g_debug ("%s> %i",gsc_provider_get_name (info->provider), info->num); - if (info->num == 0) { remove_node (model, info->header_node, @@ -890,7 +887,6 @@ gsc_model_is_empty (GscModel *model, gboolean invisible) { g_return_val_if_fail (GSC_IS_MODEL (model), FALSE); - g_debug ("is empty num: %i", model->priv->num); if (invisible) { return model->priv->num == 0; @@ -911,8 +907,6 @@ gsc_model_n_proposals (GscModel *model, g_return_val_if_fail (GSC_IS_MODEL (model), 0); g_return_val_if_fail (GSC_IS_PROVIDER (provider), 0); - g_debug ("n proposals num: %i", model->priv->num); - info = g_hash_table_lookup (model->priv->providers_info, provider); if (info == NULL) diff --git a/gtksourcecompletion/gsc-utils.c b/gtksourcecompletion/gsc-utils.c index a5e1426..a61c050 100644 --- a/gtksourcecompletion/gsc-utils.c +++ b/gtksourcecompletion/gsc-utils.c @@ -84,7 +84,7 @@ gsc_utils_is_separator(const gunichar ch) /** * gsc_utils_get_word_iter: * - * @source_buffer: The #GtkSourceBuffer + * @text_buffer: The #GtkTextBuffer * @start_word: if != NULL then assign it the start position of the word * @end_word: if != NULL then assing it the end position of the word * @@ -92,17 +92,14 @@ gsc_utils_is_separator(const gunichar ch) * */ gchar * -gsc_utils_get_word_iter (GtkSourceBuffer *source_buffer, +gsc_utils_get_word_iter (GtkTextBuffer *text_buffer, GtkTextIter *current, 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, @@ -140,36 +137,33 @@ gsc_utils_get_word_iter (GtkSourceBuffer *source_buffer, /** * gsc_utils_get_word: - * @source_buffer: The #GtkSourceBuffer + * @text_buffer: The #GtkTextBuffer * * Returns: the current word */ gchar * -gsc_utils_get_word (GtkSourceBuffer *source_buffer) +gsc_utils_get_word (GtkTextBuffer *text_buffer) { GtkTextIter start; GtkTextIter end; - return gsc_utils_get_word_iter (source_buffer, NULL, &start, &end); + return gsc_utils_get_word_iter (text_buffer, NULL, &start, &end); } static void -get_iter_pos (GtkSourceView *source_view, +get_iter_pos (GtkTextView *text_view, GtkTextIter *iter, gint *x, gint *y, gint *height) { GdkWindow *win; - GtkTextView *text_view; GdkRectangle location; gint win_x; gint win_y; gint xx; gint yy; - text_view = GTK_TEXT_VIEW (source_view); - gtk_text_view_get_iter_location (text_view, iter, &location); gtk_text_view_buffer_to_window_coords (text_view, @@ -188,7 +182,7 @@ get_iter_pos (GtkSourceView *source_view, } void -gsc_utils_replace_word (GtkSourceBuffer *source_buffer, +gsc_utils_replace_word (GtkTextBuffer *text_buffer, GtkTextIter *iter, const gchar *text, gint len) @@ -199,13 +193,13 @@ gsc_utils_replace_word (GtkSourceBuffer *source_buffer, GtkTextIter word_end; GtkTextMark *mark; - g_return_if_fail (GTK_IS_SOURCE_BUFFER (source_buffer)); + g_return_if_fail (GTK_IS_TEXT_BUFFER (text_buffer)); - buffer = GTK_TEXT_BUFFER (source_buffer); + buffer = GTK_TEXT_BUFFER (text_buffer); gtk_text_buffer_begin_user_action (buffer); mark = gtk_text_buffer_create_mark (buffer, NULL, iter, TRUE); - word = gsc_utils_get_word_iter (source_buffer, iter, &word_start, &word_end); + word = gsc_utils_get_word_iter (text_buffer, iter, &word_start, &word_end); g_free (word); gtk_text_buffer_delete (buffer, &word_start, &word_end); @@ -223,28 +217,28 @@ gsc_utils_replace_word (GtkSourceBuffer *source_buffer, /** * gsc_utils_view_replace_current_word: - * @source_buffer: The #GtkSourceBuffer + * @text_buffer: The #GtkTextBuffer * @text: The text to be inserted instead of the current word * - * Replaces the current word in the #GtkSourceBuffer with the new word + * Replaces the current word in the #GtkTextBuffer with the new word * */ void -gsc_utils_replace_current_word (GtkSourceBuffer *source_buffer, +gsc_utils_replace_current_word (GtkTextBuffer *text_buffer, const gchar *text, gint len) { GtkTextIter iter; GtkTextMark *mark; - g_return_if_fail (GTK_IS_SOURCE_BUFFER (source_buffer)); + g_return_if_fail (GTK_IS_TEXT_BUFFER (text_buffer)); - mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (source_buffer)); - gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (source_buffer), + mark = gtk_text_buffer_get_insert (GTK_TEXT_BUFFER (text_buffer)); + gtk_text_buffer_get_iter_at_mark (GTK_TEXT_BUFFER (text_buffer), &iter, mark); - gsc_utils_replace_word (source_buffer, + gsc_utils_replace_word (text_buffer, &iter, text, len); @@ -332,7 +326,7 @@ move_overlap (gint *x, */ void gsc_utils_move_to_iter (GtkWindow *window, - GtkSourceView *view, + GtkTextView *view, GtkTextIter *iter) { gint x; @@ -406,7 +400,7 @@ gsc_utils_move_to_iter (GtkWindow *window, */ void gsc_utils_move_to_cursor (GtkWindow *window, - GtkSourceView *view) + GtkTextView *view) { GtkTextBuffer *buffer; GtkTextIter insert; diff --git a/gtksourcecompletion/gsc-utils.h b/gtksourcecompletion/gsc-utils.h index 6b6fa26..a113dd0 100644 --- a/gtksourcecompletion/gsc-utils.h +++ b/gtksourcecompletion/gsc-utils.h @@ -23,7 +23,7 @@ #ifndef __GSC_COMPLETION_UTILS_H__ #define __GSC_COMPLETION_UTILS_H__ -#include +#include G_BEGIN_DECLS @@ -34,28 +34,28 @@ gchar *gsc_utils_clear_word (const gchar* word); gboolean gsc_utils_is_separator (gunichar ch); -gchar *gsc_utils_get_word_iter (GtkSourceBuffer *source_buffer, +gchar *gsc_utils_get_word_iter (GtkTextBuffer *text_buffer, GtkTextIter *current, GtkTextIter *start_word, GtkTextIter *end_word); -gchar *gsc_utils_get_word (GtkSourceBuffer *text_view); +gchar *gsc_utils_get_word (GtkTextBuffer *text_view); -void gsc_utils_replace_word (GtkSourceBuffer *source_buffer, +void gsc_utils_replace_word (GtkTextBuffer *text_buffer, GtkTextIter *iter, const gchar *text, gint len); -void gsc_utils_replace_current_word (GtkSourceBuffer *source_buffer, +void gsc_utils_replace_current_word (GtkTextBuffer *text_buffer, const gchar *text, gint len); void gsc_utils_move_to_iter (GtkWindow *window, - GtkSourceView *view, + GtkTextView *view, GtkTextIter *iter); void gsc_utils_move_to_cursor (GtkWindow *window, - GtkSourceView *view); + GtkTextView *view); G_END_DECLS diff --git a/po/Makefile.in.in b/po/Makefile.in.in index c7e8302..402a25f 100644 --- a/po/Makefile.in.in +++ b/po/Makefile.in.in @@ -56,7 +56,7 @@ ALL_LINGUAS = @ALL_LINGUAS@ PO_LINGUAS=$(shell if test -r $(srcdir)/LINGUAS; then grep -v "^\#" $(srcdir)/LINGUAS; else echo "$(ALL_LINGUAS)"; fi) -USER_LINGUAS=$(shell if test -n "$(LINGUAS)"; then LLINGUAS="$(LINGUAS)"; ALINGUAS="$(ALL_LINGUAS)"; for lang in $$LLINGUAS; do if test -n "`grep '^$$lang$$' $(srcdir)/LINGUAS 2>/dev/null`" -o -n "`echo $$ALINGUAS|tr ' ' '\n'|grep '^$$lang$$'`"; then printf "$$lang "; fi; done; fi) +USER_LINGUAS=$(shell if test -n "$(LINGUAS)"; then LLINGUAS="$(LINGUAS)"; ALINGUAS="$(ALL_LINGUAS)"; for lang in $$LLINGUAS; do if test -n "`grep \^$$lang$$ $(srcdir)/LINGUAS 2>/dev/null`" -o -n "`echo $$ALINGUAS|tr ' ' '\n'|grep \^$$lang$$`"; then printf "$$lang "; fi; done; fi) USE_LINGUAS=$(shell if test -n "$(USER_LINGUAS)" -o -n "$(LINGUAS)"; then LLINGUAS="$(USER_LINGUAS)"; else if test -n "$(PO_LINGUAS)"; then LLINGUAS="$(PO_LINGUAS)"; else LLINGUAS="$(ALL_LINGUAS)"; fi; fi; for lang in $$LLINGUAS; do printf "$$lang "; done) diff --git a/test/completion-simple.c b/test/completion-simple.c index 9066b52..9a78063 100644 --- a/test/completion-simple.c +++ b/test/completion-simple.c @@ -180,6 +180,7 @@ static void create_completion(void) { GscProviderTest *prov_test1; + GscProvider *prov_words; GdkPixbuf *icon; comp = gsc_completion_new (GTK_TEXT_VIEW (view)); @@ -207,13 +208,13 @@ create_completion(void) gsc_completion_add_provider (comp, GSC_PROVIDER (prov_test1), NULL); icon = get_icon_from_theme (GTK_STOCK_FILE); - prov_test1 = gsc_provider_words_new ("Document words", icon); + prov_words = GSC_PROVIDER (gsc_provider_words_new ("Document words", icon)); if (icon != NULL) { g_object_unref (icon); } - gsc_completion_add_provider (comp, GSC_PROVIDER (prov_test1), NULL); + gsc_completion_add_provider (comp, GSC_PROVIDER (prov_words), NULL); /* icon = get_icon_from_theme (GTK_STOCK_CLOSE);