[gnome-builder] completion-words: add IdeCompletionWords
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] completion-words: add IdeCompletionWords
- Date: Thu, 3 Nov 2016 00:26:00 +0000 (UTC)
commit 7cfeb0f2252b524b8a1d060e4cbb508b80bc41cf
Author: Christian Hergert <chergert redhat com>
Date: Wed Nov 2 17:25:24 2016 -0700
completion-words: add IdeCompletionWords
This subclasses GtkSourceCompletionWords but changes when the provider
is activated. This avoids activating when we are in comments as that is
much more likely to miss-activate (such as typing a similar word at the
end of a line in a comment).
libide/Makefile.am | 2 +
libide/buffers/ide-buffer-manager.c | 3 +-
libide/ide.h | 1 +
libide/sourceview/ide-completion-words.c | 72 ++++++++++++++++++++++++++++++
libide/sourceview/ide-completion-words.h | 51 +++++++++++++++++++++
5 files changed, 128 insertions(+), 1 deletions(-)
---
diff --git a/libide/Makefile.am b/libide/Makefile.am
index cff9a9f..a2e8a42 100644
--- a/libide/Makefile.am
+++ b/libide/Makefile.am
@@ -127,6 +127,7 @@ libide_1_0_la_public_headers = \
sourceview/ide-completion-item.h \
sourceview/ide-completion-provider.h \
sourceview/ide-completion-results.h \
+ sourceview/ide-completion-words.h \
sourceview/ide-indenter.h \
sourceview/ide-language.h \
sourceview/ide-source-map.h \
@@ -305,6 +306,7 @@ libide_1_0_la_public_sources = \
sourceview/ide-completion-item.c \
sourceview/ide-completion-provider.c \
sourceview/ide-completion-results.c \
+ sourceview/ide-completion-words.c \
sourceview/ide-indenter.c \
sourceview/ide-language.c \
sourceview/ide-source-map.c \
diff --git a/libide/buffers/ide-buffer-manager.c b/libide/buffers/ide-buffer-manager.c
index fb98ce1..a2d3e97 100644
--- a/libide/buffers/ide-buffer-manager.c
+++ b/libide/buffers/ide-buffer-manager.c
@@ -39,6 +39,7 @@
#include "history/ide-back-forward-list.h"
#include "projects/ide-project-edit.h"
#include "projects/ide-project-edit-private.h"
+#include "sourceview/ide-completion-words.h"
#include "util/ide-doc-seq.h"
#include "util/ide-progress.h"
#include "vcs/ide-vcs.h"
@@ -1533,7 +1534,7 @@ ide_buffer_manager_init (IdeBufferManager *self)
self->buffers = g_ptr_array_new ();
self->max_file_size = MAX_FILE_SIZE_BYTES_DEFAULT;
self->timeouts = g_hash_table_new (g_direct_hash, g_direct_equal);
- self->word_completion = gtk_source_completion_words_new (_("Words"), NULL);
+ self->word_completion = g_object_new (IDE_TYPE_COMPLETION_WORDS, NULL);
self->settings = g_settings_new ("org.gnome.builder.editor");
}
diff --git a/libide/ide.h b/libide/ide.h
index d8f9f61..fd397e6 100644
--- a/libide/ide.h
+++ b/libide/ide.h
@@ -117,6 +117,7 @@ G_BEGIN_DECLS
#include "sourceview/ide-completion-item.h"
#include "sourceview/ide-completion-provider.h"
#include "sourceview/ide-completion-results.h"
+#include "sourceview/ide-completion-words.h"
#include "sourceview/ide-indenter.h"
#include "sourceview/ide-language.h"
#include "sourceview/ide-source-map.h"
diff --git a/libide/sourceview/ide-completion-words.c b/libide/sourceview/ide-completion-words.c
new file mode 100644
index 0000000..65fa47e
--- /dev/null
+++ b/libide/sourceview/ide-completion-words.c
@@ -0,0 +1,72 @@
+/* ide-completion-words.c
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#define G_LOG_DOMAIN "ide-completion-words"
+
+#include "ide-completion-provider.h"
+#include "ide-completion-words.h"
+
+struct _IdeCompletionWords
+{
+ GtkSourceCompletionWords parent_instance;
+};
+
+static void completion_provider_init (GtkSourceCompletionProviderIface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (IdeCompletionWords, ide_completion_words, GTK_SOURCE_TYPE_COMPLETION_WORDS,
+ G_IMPLEMENT_INTERFACE (GTK_SOURCE_TYPE_COMPLETION_PROVIDER,
completion_provider_init))
+
+static void
+ide_completion_words_class_init (IdeCompletionWordsClass *klass)
+{
+}
+
+static void
+ide_completion_words_init (IdeCompletionWords *self)
+{
+}
+
+static gboolean
+ide_completion_words_match (GtkSourceCompletionProvider *provider,
+ GtkSourceCompletionContext *context)
+{
+ GtkSourceCompletionActivation activation;
+ GtkTextIter iter;
+
+ g_assert (IDE_IS_COMPLETION_WORDS (provider));
+ g_assert (GTK_SOURCE_IS_COMPLETION_CONTEXT (context));
+
+ if (!gtk_source_completion_context_get_iter (context, &iter))
+ return FALSE;
+
+ activation = gtk_source_completion_context_get_activation (context);
+
+ if (activation == GTK_SOURCE_COMPLETION_ACTIVATION_INTERACTIVE)
+ {
+ if (ide_completion_provider_context_in_comment (context))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void
+completion_provider_init (GtkSourceCompletionProviderIface *iface)
+{
+ iface->match = ide_completion_words_match;
+}
diff --git a/libide/sourceview/ide-completion-words.h b/libide/sourceview/ide-completion-words.h
new file mode 100644
index 0000000..3e1daa0
--- /dev/null
+++ b/libide/sourceview/ide-completion-words.h
@@ -0,0 +1,51 @@
+/* ide-completion-words.h
+ *
+ * Copyright (C) 2016 Christian Hergert <chergert redhat com>
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef IDE_COMPLETION_WORDS_H
+#define IDE_COMPLETION_WORDS_H
+
+#include <gtksourceview/gtksource.h>
+
+G_BEGIN_DECLS
+
+#define IDE_TYPE_COMPLETION_WORDS (ide_completion_words_get_type())
+#define IDE_COMPLETION_WORDS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDE_TYPE_COMPLETION_WORDS,
IdeCompletionWords))
+#define IDE_COMPLETION_WORDS_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), IDE_TYPE_COMPLETION_WORDS,
IdeCompletionWords const))
+#define IDE_COMPLETION_WORDS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), IDE_TYPE_COMPLETION_WORDS,
IdeCompletionWordsClass))
+#define IDE_IS_COMPLETION_WORDS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IDE_TYPE_COMPLETION_WORDS))
+#define IDE_IS_COMPLETION_WORDS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), IDE_TYPE_COMPLETION_WORDS))
+#define IDE_COMPLETION_WORDS_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), IDE_TYPE_COMPLETION_WORDS,
IdeCompletionWordsClass))
+
+typedef struct _IdeCompletionWords IdeCompletionWords;
+typedef struct _IdeCompletionWordsClass IdeCompletionWordsClass;
+
+struct _IdeCompletionWordsClass
+{
+ GtkSourceCompletionWordsClass parent_class;
+
+ gpointer _reserved1;
+ gpointer _reserved2;
+ gpointer _reserved3;
+ gpointer _reserved4;
+};
+
+GType ide_completion_words_get_type (void);
+
+G_END_DECLS
+
+#endif /* IDE_COMPLETION_WORDS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]