[gnome-builder/auto-indent] editor: stub out plumbing for auto indenting.
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/auto-indent] editor: stub out plumbing for auto indenting.
- Date: Tue, 16 Sep 2014 21:29:20 +0000 (UTC)
commit 6c177cb60d22af2662e4de0ca6cf51a869861f92
Author: Christian Hergert <christian hergert me>
Date: Tue Sep 16 14:01:16 2014 -0700
editor: stub out plumbing for auto indenting.
This requires patches from GtkSourceView bug 736727.
src/editor/gb-editor-tab-private.h | 7 ++
src/editor/gb-editor-tab.c | 36 +++++++++++
src/editor/gb-source-auto-indenter-c.c | 104 ++++++++++++++++++++++++++++++++
src/editor/gb-source-auto-indenter-c.h | 56 +++++++++++++++++
src/editor/gb-source-auto-indenter.c | 59 ++++++++++++++++++
src/editor/gb-source-auto-indenter.h | 67 ++++++++++++++++++++
src/gnome-builder.mk | 4 +
7 files changed, 333 insertions(+), 0 deletions(-)
---
diff --git a/src/editor/gb-editor-tab-private.h b/src/editor/gb-editor-tab-private.h
index c1c26b3..ad8b9ef 100644
--- a/src/editor/gb-editor-tab-private.h
+++ b/src/editor/gb-editor-tab-private.h
@@ -28,6 +28,8 @@
#include "gb-editor-settings.h"
#include "gb-markdown-preview.h"
#include "gb-notebook.h"
+#include "gb-source-auto-indenter.h"
+#include "gb-source-auto-indenter-c.h"
#include "gb-source-change-monitor.h"
#include "gb-source-search-highlighter.h"
#include "gb-source-snippet-completion-provider.h"
@@ -63,6 +65,11 @@ struct _GbEditorTabPrivate
GtkSourceGutterRenderer *change_renderer;
/*
+ * Auto-indentation support for a given language.
+ */
+ GbSourceAutoIndenter *auto_indenter;
+
+ /*
* Tab related settings.
*/
GbEditorSettings *settings;
diff --git a/src/editor/gb-editor-tab.c b/src/editor/gb-editor-tab.c
index 1c3dedc..1ee6282 100644
--- a/src/editor/gb-editor-tab.c
+++ b/src/editor/gb-editor-tab.c
@@ -861,6 +861,29 @@ on_source_view_push_snippet (GbSourceView *source_view,
}
}
+static gchar *
+on_source_view_query_auto_indent (GbSourceView *source_view,
+ GtkTextIter *iter,
+ GbEditorTab *tab)
+{
+ GtkTextBuffer *buffer;
+ GtkTextView *text_view = (GtkTextView *)source_view;
+ gchar *ret = NULL;
+
+ g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), NULL);
+ g_return_val_if_fail (GB_IS_EDITOR_TAB (tab), NULL);
+ g_return_val_if_fail (iter, NULL);
+
+ if (tab->priv->auto_indenter)
+ {
+ buffer = gtk_text_view_get_buffer (text_view);
+ ret = gb_source_auto_indenter_query (tab->priv->auto_indenter, text_view,
+ buffer, iter);
+ }
+
+ return ret;
+}
+
static gboolean
transform_file_to_language (GBinding *binding,
const GValue *src_value,
@@ -968,6 +991,11 @@ gb_editor_tab_constructed (GObject *object)
"push-snippet",
G_CALLBACK (on_source_view_push_snippet),
tab);
+ g_signal_connect (priv->source_view,
+ "query-auto-indent",
+ G_CALLBACK (on_source_view_query_auto_indent),
+ tab);
+ g_print ("Connected\n");
g_signal_connect_swapped (priv->go_down_button,
"clicked",
@@ -1043,6 +1071,8 @@ gb_editor_tab_constructed (GObject *object)
gtk_source_gutter_insert (gutter, priv->change_renderer, 0);
}
+ priv->auto_indenter = gb_source_auto_indenter_c_new ();
+
gb_editor_tab_cursor_moved (tab, priv->document);
EXIT;
@@ -1099,6 +1129,12 @@ gb_editor_tab_dispose (GObject *object)
g_clear_object (&tab->priv->document);
g_clear_object (&tab->priv->search_entry_tag);
g_clear_object (&tab->priv->file);
+ g_clear_object (&tab->priv->snippets_provider);
+ g_clear_object (&tab->priv->search_highlighter);
+ g_clear_object (&tab->priv->search_settings);
+ g_clear_object (&tab->priv->search_context);
+ g_clear_object (&tab->priv->auto_indenter);
+ g_clear_object (&tab->priv->settings);
EXIT;
}
diff --git a/src/editor/gb-source-auto-indenter-c.c b/src/editor/gb-source-auto-indenter-c.c
new file mode 100644
index 0000000..c80c562
--- /dev/null
+++ b/src/editor/gb-source-auto-indenter-c.c
@@ -0,0 +1,104 @@
+/* gb-source-auto-indenter-c.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file 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
+ * Lesser 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/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "gb-source-auto-indenter-c.h"
+
+struct _GbSourceAutoIndenterCPrivate
+{
+ gpointer foo;
+};
+
+enum
+{
+ PROP_0,
+ LAST_PROP
+};
+
+G_DEFINE_TYPE_WITH_PRIVATE (GbSourceAutoIndenterC, gb_source_auto_indenter_c,
+ GB_TYPE_SOURCE_AUTO_INDENTER)
+
+static GParamSpec *gParamSpecs [LAST_PROP];
+
+GbSourceAutoIndenter *
+gb_source_auto_indenter_c_new (void)
+{
+ return g_object_new (GB_TYPE_SOURCE_AUTO_INDENTER_C, NULL);
+}
+
+static gchar *
+gb_source_auto_indenter_c_query (GbSourceAutoIndenter *indenter,
+ GtkTextView *view,
+ GtkTextBuffer *buffer,
+ GtkTextIter *iter)
+{
+ GbSourceAutoIndenterC *c = (GbSourceAutoIndenterC *)indenter;
+
+ g_return_val_if_fail (GB_IS_SOURCE_AUTO_INDENTER_C (c), NULL);
+
+ g_printerr ("QUERY:\n");
+
+ return NULL;
+}
+
+static void
+gb_source_auto_indenter_c_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
+{
+ GbSourceAutoIndenterC *c = GB_SOURCE_AUTO_INDENTER_C (object);
+
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_source_auto_indenter_c_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
+{
+ GbSourceAutoIndenterC *c = GB_SOURCE_AUTO_INDENTER_C (object);
+
+ switch (prop_id) {
+ default:
+ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+ }
+}
+
+static void
+gb_source_auto_indenter_c_class_init (GbSourceAutoIndenterCClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GbSourceAutoIndenterClass *indenter_class = GB_SOURCE_AUTO_INDENTER_CLASS (klass);
+
+ object_class->get_property = gb_source_auto_indenter_c_get_property;
+ object_class->set_property = gb_source_auto_indenter_c_set_property;
+
+ indenter_class->query = gb_source_auto_indenter_c_query;
+}
+
+static void
+gb_source_auto_indenter_c_init (GbSourceAutoIndenterC *c)
+{
+ c->priv = gb_source_auto_indenter_c_get_instance_private (c);
+}
diff --git a/src/editor/gb-source-auto-indenter-c.h b/src/editor/gb-source-auto-indenter-c.h
new file mode 100644
index 0000000..4b3ec5c
--- /dev/null
+++ b/src/editor/gb-source-auto-indenter-c.h
@@ -0,0 +1,56 @@
+/* gb-source-auto-indenter-c.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file 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
+ * Lesser 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 GB_SOURCE_AUTO_INDENTER_C_H
+#define GB_SOURCE_AUTO_INDENTER_C_H
+
+#include "gb-source-auto-indenter.h"
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_SOURCE_AUTO_INDENTER_C (gb_source_auto_indenter_c_get_type())
+#define GB_SOURCE_AUTO_INDENTER_C(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_SOURCE_AUTO_INDENTER_C, GbSourceAutoIndenterC))
+#define GB_SOURCE_AUTO_INDENTER_C_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_SOURCE_AUTO_INDENTER_C, GbSourceAutoIndenterC const))
+#define GB_SOURCE_AUTO_INDENTER_C_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GB_TYPE_SOURCE_AUTO_INDENTER_C, GbSourceAutoIndenterCClass))
+#define GB_IS_SOURCE_AUTO_INDENTER_C(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GB_TYPE_SOURCE_AUTO_INDENTER_C))
+#define GB_IS_SOURCE_AUTO_INDENTER_C_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GB_TYPE_SOURCE_AUTO_INDENTER_C))
+#define GB_SOURCE_AUTO_INDENTER_C_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GB_TYPE_SOURCE_AUTO_INDENTER_C, GbSourceAutoIndenterCClass))
+
+typedef struct _GbSourceAutoIndenterC GbSourceAutoIndenterC;
+typedef struct _GbSourceAutoIndenterCClass GbSourceAutoIndenterCClass;
+typedef struct _GbSourceAutoIndenterCPrivate GbSourceAutoIndenterCPrivate;
+
+struct _GbSourceAutoIndenterC
+{
+ GbSourceAutoIndenter parent;
+
+ /*< private >*/
+ GbSourceAutoIndenterCPrivate *priv;
+};
+
+struct _GbSourceAutoIndenterCClass
+{
+ GbSourceAutoIndenterClass parent_class;
+};
+
+GbSourceAutoIndenter *gb_source_auto_indenter_c_new (void);
+GType gb_source_auto_indenter_c_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* GB_SOURCE_AUTO_INDENTER_C_H */
diff --git a/src/editor/gb-source-auto-indenter.c b/src/editor/gb-source-auto-indenter.c
new file mode 100644
index 0000000..45bfeed
--- /dev/null
+++ b/src/editor/gb-source-auto-indenter.c
@@ -0,0 +1,59 @@
+/* gb-source-auto-indenter.c
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file 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
+ * Lesser 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/>.
+ */
+
+#include <glib/gi18n.h>
+
+#include "gb-source-auto-indenter.h"
+
+G_DEFINE_ABSTRACT_TYPE (GbSourceAutoIndenter, gb_source_auto_indenter,
+ G_TYPE_OBJECT)
+
+static gchar *
+gb_source_auto_indenter_real_query (GbSourceAutoIndenter *indenter,
+ GtkTextView *view,
+ GtkTextBuffer *buffer,
+ GtkTextIter *iter)
+{
+ return NULL;
+}
+
+gchar *
+gb_source_auto_indenter_query (GbSourceAutoIndenter *indenter,
+ GtkTextView *view,
+ GtkTextBuffer *buffer,
+ GtkTextIter *iter)
+{
+ g_return_val_if_fail (GB_IS_SOURCE_AUTO_INDENTER (indenter), NULL);
+ g_return_val_if_fail (GTK_IS_TEXT_VIEW (view), NULL);
+ g_return_val_if_fail (GTK_IS_TEXT_BUFFER (buffer), NULL);
+ g_return_val_if_fail (iter, NULL);
+
+ return GB_SOURCE_AUTO_INDENTER_GET_CLASS (indenter)->query (indenter, view,
+ buffer, iter);
+}
+
+static void
+gb_source_auto_indenter_class_init (GbSourceAutoIndenterClass *klass)
+{
+ klass->query = gb_source_auto_indenter_real_query;
+}
+
+static void
+gb_source_auto_indenter_init (GbSourceAutoIndenter *indenter)
+{
+}
diff --git a/src/editor/gb-source-auto-indenter.h b/src/editor/gb-source-auto-indenter.h
new file mode 100644
index 0000000..9270ac2
--- /dev/null
+++ b/src/editor/gb-source-auto-indenter.h
@@ -0,0 +1,67 @@
+/* gb-source-auto-indenter.h
+ *
+ * Copyright (C) 2014 Christian Hergert <christian hergert me>
+ *
+ * This file is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This file 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
+ * Lesser 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 GB_SOURCE_AUTO_INDENTER_H
+#define GB_SOURCE_AUTO_INDENTER_H
+
+#include <gtk/gtk.h>
+#include <gtksourceview/gtksource.h>
+
+G_BEGIN_DECLS
+
+#define GB_TYPE_SOURCE_AUTO_INDENTER (gb_source_auto_indenter_get_type())
+#define GB_SOURCE_AUTO_INDENTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_SOURCE_AUTO_INDENTER, GbSourceAutoIndenter))
+#define GB_SOURCE_AUTO_INDENTER_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj),
GB_TYPE_SOURCE_AUTO_INDENTER, GbSourceAutoIndenter const))
+#define GB_SOURCE_AUTO_INDENTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass),
GB_TYPE_SOURCE_AUTO_INDENTER, GbSourceAutoIndenterClass))
+#define GB_IS_SOURCE_AUTO_INDENTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj),
GB_TYPE_SOURCE_AUTO_INDENTER))
+#define GB_IS_SOURCE_AUTO_INDENTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass),
GB_TYPE_SOURCE_AUTO_INDENTER))
+#define GB_SOURCE_AUTO_INDENTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj),
GB_TYPE_SOURCE_AUTO_INDENTER, GbSourceAutoIndenterClass))
+
+typedef struct _GbSourceAutoIndenter GbSourceAutoIndenter;
+typedef struct _GbSourceAutoIndenterClass GbSourceAutoIndenterClass;
+typedef struct _GbSourceAutoIndenterPrivate GbSourceAutoIndenterPrivate;
+
+struct _GbSourceAutoIndenter
+{
+ GObject parent;
+
+ /*< private >*/
+ GbSourceAutoIndenterPrivate *priv;
+};
+
+struct _GbSourceAutoIndenterClass
+{
+ GObjectClass parent_class;
+
+ gchar *(*query) (GbSourceAutoIndenter *indenter,
+ GtkTextView *view,
+ GtkTextBuffer *buffer,
+ GtkTextIter *iter);
+
+ gpointer padding[7];
+};
+
+GType gb_source_auto_indenter_get_type (void) G_GNUC_CONST;
+gchar *gb_source_auto_indenter_query (GbSourceAutoIndenter *indenter,
+ GtkTextView *view,
+ GtkTextBuffer *buffer,
+ GtkTextIter *iter);
+
+G_END_DECLS
+
+#endif /* GB_SOURCE_AUTO_INDENTER_H */
diff --git a/src/gnome-builder.mk b/src/gnome-builder.mk
index 332d6b7..0204ca6 100644
--- a/src/gnome-builder.mk
+++ b/src/gnome-builder.mk
@@ -28,6 +28,10 @@ gnome_builder_SOURCES = \
src/editor/gb-editor-workspace.c \
src/editor/gb-editor-workspace.h \
src/editor/gb-editor-workspace-private.h \
+ src/editor/gb-source-auto-indenter.c \
+ src/editor/gb-source-auto-indenter.h \
+ src/editor/gb-source-auto-indenter-c.c \
+ src/editor/gb-source-auto-indenter-c.h \
src/editor/gb-source-change-monitor.c \
src/editor/gb-source-change-monitor.h \
src/editor/gb-source-formatter.c \
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]