[gnome-builder/wip/gtk4-port] libide/editor: allow setting a gutter on an editor page
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/gtk4-port] libide/editor: allow setting a gutter on an editor page
- Date: Tue, 26 Apr 2022 23:09:44 +0000 (UTC)
commit a7998df7eecfff097165f06d310dc25becfa4e30
Author: Christian Hergert <chergert redhat com>
Date: Tue Apr 26 16:01:09 2022 -0700
libide/editor: allow setting a gutter on an editor page
src/libide/editor/ide-editor-page-private.h | 11 +++-
src/libide/editor/ide-editor-page-settings.c | 54 +++++++++++++--
src/libide/editor/ide-editor-page.c | 98 ++++++++++++++++++++++++++++
src/libide/editor/ide-editor-page.h | 5 ++
4 files changed, 158 insertions(+), 10 deletions(-)
---
diff --git a/src/libide/editor/ide-editor-page-private.h b/src/libide/editor/ide-editor-page-private.h
index f9d409947..b9aca73b8 100644
--- a/src/libide/editor/ide-editor-page-private.h
+++ b/src/libide/editor/ide-editor-page-private.h
@@ -33,6 +33,7 @@ struct _IdeEditorPage
/* Owned references */
IdeExtensionSetAdapter *addins;
IdeBuffer *buffer;
+ IdeGutter *gutter;
/* Settings Management */
IdeBindingGroup *buffer_file_settings;
@@ -47,8 +48,12 @@ struct _IdeEditorPage
guint completion_blocked : 1;
};
-void _ide_editor_page_class_actions_init (IdeEditorPageClass *klass);
-void _ide_editor_page_settings_init (IdeEditorPage *self);
-void _ide_editor_page_settings_reload (IdeEditorPage *self);
+void _ide_editor_page_class_actions_init (IdeEditorPageClass *klass);
+void _ide_editor_page_settings_init (IdeEditorPage *self);
+void _ide_editor_page_settings_reload (IdeEditorPage *self);
+void _ide_editor_page_settings_connect_gutter (IdeEditorPage *self,
+ IdeGutter *gutter);
+void _ide_editor_page_settings_disconnect_gutter (IdeEditorPage *self,
+ IdeGutter *gutter);
G_END_DECLS
diff --git a/src/libide/editor/ide-editor-page-settings.c b/src/libide/editor/ide-editor-page-settings.c
index 5fbbbc49f..56ecb7a81 100644
--- a/src/libide/editor/ide-editor-page-settings.c
+++ b/src/libide/editor/ide-editor-page-settings.c
@@ -24,6 +24,8 @@
#include "ide-editor-page-private.h"
+static GSettings *editor_settings;
+
static gboolean
indent_style_to_insert_spaces (GBinding *binding,
const GValue *from,
@@ -95,16 +97,16 @@ font_name_to_font_desc (GValue *value,
static void
notify_interactive_completion_cb (IdeEditorPage *self,
const char *key,
- GSettings *editor_settings)
+ GSettings *settings)
{
GtkSourceCompletion *completion;
g_assert (IDE_IS_EDITOR_PAGE (self));
- g_assert (G_IS_SETTINGS (editor_settings));
+ g_assert (G_IS_SETTINGS (settings));
completion = gtk_source_view_get_completion (GTK_SOURCE_VIEW (self->view));
- if (g_settings_get_boolean (editor_settings, "interactive-completion"))
+ if (g_settings_get_boolean (settings, "interactive-completion"))
{
if (self->completion_blocked)
{
@@ -125,7 +127,6 @@ notify_interactive_completion_cb (IdeEditorPage *self,
void
_ide_editor_page_settings_init (IdeEditorPage *self)
{
- static GSettings *editor_settings;
GtkSourceCompletion *completion;
IDE_ENTRY;
@@ -170,9 +171,6 @@ _ide_editor_page_settings_init (IdeEditorPage *self)
"tab-width", self->view, "tab-width",
G_BINDING_SYNC_CREATE);
- g_settings_bind (editor_settings, "show-line-numbers",
- self->view, "show-line-numbers",
- G_SETTINGS_BIND_GET);
g_settings_bind (editor_settings, "show-map",
self->map_revealer, "reveal-child",
G_SETTINGS_BIND_GET);
@@ -222,3 +220,45 @@ _ide_editor_page_settings_init (IdeEditorPage *self)
IDE_EXIT;
}
+
+void
+_ide_editor_page_settings_connect_gutter (IdeEditorPage *self,
+ IdeGutter *gutter)
+{
+ IDE_ENTRY;
+
+ g_return_if_fail (IDE_IS_EDITOR_PAGE (self));
+ g_return_if_fail (IDE_IS_GUTTER (gutter));
+
+ g_settings_bind (editor_settings, "show-line-numbers",
+ gutter, "show-line-numbers",
+ G_SETTINGS_BIND_GET);
+ g_settings_bind (editor_settings, "show-line-changes",
+ gutter, "show-line-changes",
+ G_SETTINGS_BIND_GET);
+ g_settings_bind (editor_settings, "show-relative-line-numbers",
+ gutter, "show-relative-line-numbers",
+ G_SETTINGS_BIND_GET);
+ g_settings_bind (editor_settings, "show-line-diagnostics",
+ gutter, "show-line-diagnostics",
+ G_SETTINGS_BIND_GET);
+
+ IDE_EXIT;
+}
+
+void
+_ide_editor_page_settings_disconnect_gutter (IdeEditorPage *self,
+ IdeGutter *gutter)
+{
+ IDE_ENTRY;
+
+ g_return_if_fail (IDE_IS_EDITOR_PAGE (self));
+ g_return_if_fail (IDE_IS_GUTTER (gutter));
+
+ g_settings_unbind (gutter, "show-line-changes");
+ g_settings_unbind (gutter, "show-line-numbers");
+ g_settings_unbind (gutter, "show-relative-line-numbers");
+ g_settings_unbind (gutter, "show-line-diagnostics");
+
+ IDE_EXIT;
+}
diff --git a/src/libide/editor/ide-editor-page.c b/src/libide/editor/ide-editor-page.c
index b980ae0a4..43174343e 100644
--- a/src/libide/editor/ide-editor-page.c
+++ b/src/libide/editor/ide-editor-page.c
@@ -33,6 +33,7 @@
enum {
PROP_0,
PROP_BUFFER,
+ PROP_GUTTER,
PROP_VIEW,
N_PROPS
};
@@ -56,6 +57,18 @@ ide_editor_page_modified_changed_cb (IdeEditorPage *self,
IDE_EXIT;
}
+static void
+ide_editor_page_style_scheme_changed_cb (IdeEditorPage *self,
+ GParamSpec *pspec,
+ IdeBuffer *buffer)
+{
+ g_assert (IDE_IS_EDITOR_PAGE (self));
+ g_assert (IDE_IS_BUFFER (buffer));
+
+ if (self->gutter != NULL)
+ ide_gutter_style_changed (self->gutter);
+}
+
static void
ide_editor_page_set_buffer (IdeEditorPage *self,
IdeBuffer *buffer)
@@ -83,6 +96,12 @@ ide_editor_page_set_buffer (IdeEditorPage *self,
self,
G_CONNECT_SWAPPED);
+ g_signal_connect_object (buffer,
+ "notify::style-scheme",
+ G_CALLBACK (ide_editor_page_style_scheme_changed_cb),
+ self,
+ G_CONNECT_SWAPPED);
+
g_object_bind_property (buffer, "title",
self, "title",
G_BINDING_SYNC_CREATE);
@@ -252,6 +271,8 @@ ide_editor_page_dispose (GObject *object)
{
IdeEditorPage *self = (IdeEditorPage *)object;
+ ide_editor_page_set_gutter (self, NULL);
+
ide_clear_and_destroy_object (&self->addins);
g_clear_object (&self->buffer_file_settings);
@@ -280,6 +301,10 @@ ide_editor_page_get_property (GObject *object,
g_value_set_object (value, ide_editor_page_get_buffer (self));
break;
+ case PROP_GUTTER:
+ g_value_set_object (value, ide_editor_page_get_gutter (self));
+ break;
+
case PROP_VIEW:
g_value_set_object (value, ide_editor_page_get_view (self));
break;
@@ -303,6 +328,10 @@ ide_editor_page_set_property (GObject *object,
ide_editor_page_set_buffer (self, g_value_get_object (value));
break;
+ case PROP_GUTTER:
+ ide_editor_page_set_gutter (self, g_value_get_object (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
}
@@ -337,6 +366,22 @@ ide_editor_page_class_init (IdeEditorPageClass *klass)
IDE_TYPE_BUFFER,
(G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
+ /**
+ * IdeEditorPage:gutter:
+ *
+ * The "gutter" property contains an #IdeGutter or %NULL, which is a
+ * specialized renderer for the sourceview which can bring together a number
+ * of types of content which needs to be displayed, in a single renderer.
+ */
+ properties [PROP_GUTTER] =
+ g_param_spec_object ("gutter",
+ "Gutter",
+ "The primary gutter renderer in the left gutter window",
+ IDE_TYPE_GUTTER,
+ (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS));
+
+ g_object_class_install_properties (object_class, N_PROPS, properties);
+
/**
* IdeEditorPage:view:
*
@@ -686,3 +731,56 @@ ide_editor_page_discard_changes_finish (IdeEditorPage *self,
IDE_RETURN (ret);
}
+
+/**
+ * ide_editor_page_get_gutter:
+ * @self: a #IdeEditorPage
+ *
+ * Gets the #IdeGutter displayed in the editor page.
+ *
+ * Returns: (transfer none) (nullable): an #IdeGutter or %NULL
+ */
+IdeGutter *
+ide_editor_page_get_gutter (IdeEditorPage *self)
+{
+ g_return_val_if_fail (IDE_IS_EDITOR_PAGE (self), NULL);
+
+ return self->gutter;
+}
+
+void
+ide_editor_page_set_gutter (IdeEditorPage *self,
+ IdeGutter *gutter)
+{
+ GtkSourceGutter *container;
+
+ IDE_ENTRY;
+
+ g_return_if_fail (IDE_IS_EDITOR_PAGE (self));
+ g_return_if_fail (!gutter || IDE_IS_GUTTER (self));
+
+ if (gutter == self->gutter)
+ IDE_EXIT;
+
+ container = gtk_source_view_get_gutter (GTK_SOURCE_VIEW (self->view),
+ GTK_TEXT_WINDOW_LEFT);
+
+ if (self->gutter)
+ {
+ gtk_source_gutter_remove (container, GTK_SOURCE_GUTTER_RENDERER (self->gutter));
+ _ide_editor_page_settings_disconnect_gutter (self, self->gutter);
+ g_clear_object (&self->gutter);
+ }
+
+ if (gutter)
+ {
+ g_set_object (&self->gutter, gutter);
+ gtk_source_gutter_insert (container, GTK_SOURCE_GUTTER_RENDERER (self->gutter), 0);
+ _ide_editor_page_settings_connect_gutter (self, self->gutter);
+ ide_gutter_style_changed (self->gutter);
+ }
+
+ g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_GUTTER]);
+
+ IDE_EXIT;
+}
diff --git a/src/libide/editor/ide-editor-page.h b/src/libide/editor/ide-editor-page.h
index 7ee1d6b7c..8722b616e 100644
--- a/src/libide/editor/ide-editor-page.h
+++ b/src/libide/editor/ide-editor-page.h
@@ -43,6 +43,11 @@ IdeBuffer *ide_editor_page_get_buffer (IdeEditorPage *sel
IDE_AVAILABLE_IN_ALL
IdeSourceView *ide_editor_page_get_view (IdeEditorPage *self);
IDE_AVAILABLE_IN_ALL
+IdeGutter *ide_editor_page_get_gutter (IdeEditorPage *self);
+IDE_AVAILABLE_IN_ALL
+void ide_editor_page_set_gutter (IdeEditorPage *self,
+ IdeGutter *gutter);
+IDE_AVAILABLE_IN_ALL
void ide_editor_page_discard_changes_async (IdeEditorPage *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]