[gnome-builder/wip/gtk4-port: 343/343] libide/editor: wire up various file settings




commit 32cc0ad754d8bfca939fed52730675324246c446
Author: Christian Hergert <chergert redhat com>
Date:   Mon Apr 4 13:01:19 2022 -0700

    libide/editor: wire up various file settings
    
    There are still more of these we will want to bind, but this gets a few
    of the basics in place so others can help out.

 src/libide/editor/ide-editor-page-private.h  |   7 ++
 src/libide/editor/ide-editor-page-settings.c | 117 +++++++++++++++++++++++++++
 src/libide/editor/ide-editor-page.c          |  14 +++-
 src/libide/editor/ide-editor-page.ui         |   2 +
 src/libide/editor/meson.build                |   2 +
 5 files changed, 141 insertions(+), 1 deletion(-)
---
diff --git a/src/libide/editor/ide-editor-page-private.h b/src/libide/editor/ide-editor-page-private.h
index ba2758dd0..38a624b69 100644
--- a/src/libide/editor/ide-editor-page-private.h
+++ b/src/libide/editor/ide-editor-page-private.h
@@ -31,6 +31,10 @@ struct _IdeEditorPage
   /* Owned references */
   IdeBuffer         *buffer;
 
+  /* Settings Management */
+  IdeBindingGroup   *buffer_file_settings;
+  IdeBindingGroup   *view_file_settings;
+
   /* Template widgets */
   IdeSourceView     *view;
   GtkScrolledWindow *scroller;
@@ -38,4 +42,7 @@ struct _IdeEditorPage
   GtkRevealer       *map_revealer;
 };
 
+void _ide_editor_page_settings_init   (IdeEditorPage *self);
+void _ide_editor_page_settings_reload (IdeEditorPage *self);
+
 G_END_DECLS
diff --git a/src/libide/editor/ide-editor-page-settings.c b/src/libide/editor/ide-editor-page-settings.c
new file mode 100644
index 000000000..16338e578
--- /dev/null
+++ b/src/libide/editor/ide-editor-page-settings.c
@@ -0,0 +1,117 @@
+/* ide-editor-page-settings.c
+ *
+ * Copyright 2022 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/>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-or-later
+ */
+
+#define G_LOG_DOMAIN "ide-editor-page-settings"
+
+#include "config.h"
+
+#include "ide-editor-page-private.h"
+
+static gboolean
+indent_style_to_insert_spaces (GBinding     *binding,
+                               const GValue *from,
+                               GValue       *to,
+                               gpointer      user_data)
+{
+  g_assert (G_IS_BINDING (binding));
+  g_assert (G_VALUE_HOLDS_ENUM (from));
+  g_assert (G_VALUE_HOLDS_BOOLEAN (to));
+  g_assert (user_data == NULL);
+
+  if (g_value_get_enum (from) == IDE_INDENT_STYLE_TABS)
+    g_value_set_boolean (to, FALSE);
+  else
+    g_value_set_boolean (to, TRUE);
+
+  return TRUE;
+}
+
+void
+_ide_editor_page_settings_reload (IdeEditorPage *self)
+{
+  IdeFileSettings *file_settings;
+
+  IDE_ENTRY;
+
+  g_return_if_fail (IDE_IS_MAIN_THREAD ());
+  g_return_if_fail (IDE_IS_EDITOR_PAGE (self));
+  g_return_if_fail (IDE_IS_BUFFER (self->buffer));
+  g_return_if_fail (IDE_IS_SOURCE_VIEW (self->view));
+  g_return_if_fail (IDE_IS_BINDING_GROUP (self->buffer_file_settings));
+
+  file_settings = ide_buffer_get_file_settings (self->buffer);
+
+  ide_binding_group_set_source (self->buffer_file_settings, file_settings);
+  ide_binding_group_set_source (self->view_file_settings, file_settings);
+
+  IDE_EXIT;
+}
+
+void
+_ide_editor_page_settings_init (IdeEditorPage *self)
+{
+  IDE_ENTRY;
+
+  g_return_if_fail (IDE_IS_MAIN_THREAD ());
+  g_return_if_fail (IDE_IS_EDITOR_PAGE (self));
+  g_return_if_fail (IDE_IS_SOURCE_VIEW (self->view));
+  g_return_if_fail (IDE_IS_BUFFER (self->buffer));
+  g_return_if_fail (self->buffer_file_settings == NULL);
+  g_return_if_fail (self->view_file_settings == NULL);
+
+  self->buffer_file_settings = ide_binding_group_new ();
+  ide_binding_group_bind (self->buffer_file_settings,
+                          "insert-trailing-newline", self->buffer, "implicit-trailing-newline",
+                          G_BINDING_SYNC_CREATE);
+
+  self->view_file_settings = ide_binding_group_new ();
+  ide_binding_group_bind (self->view_file_settings,
+                          "auto-indent", self->view, "auto-indent",
+                          G_BINDING_SYNC_CREATE);
+  ide_binding_group_bind_full (self->view_file_settings,
+                               "indent-style", self->view, "insert-spaces-instead-of-tabs",
+                               G_BINDING_SYNC_CREATE,
+                               indent_style_to_insert_spaces, NULL, NULL, NULL);
+  ide_binding_group_bind (self->view_file_settings,
+                          "indent-width", self->view, "indent-width",
+                          G_BINDING_SYNC_CREATE);
+  ide_binding_group_bind (self->view_file_settings,
+                          "right-margin-position", self->view, "right-margin-position",
+                          G_BINDING_SYNC_CREATE);
+  ide_binding_group_bind (self->view_file_settings,
+                          "show-right-margin", self->view, "show-right-margin",
+                          G_BINDING_SYNC_CREATE);
+  ide_binding_group_bind (self->view_file_settings,
+                          "tab-width", self->view, "tab-width",
+                          G_BINDING_SYNC_CREATE);
+
+#if 0
+  ide_binding_group_bind (self->view_file_settings,
+                          "insert-matching-brace", self->view, "insert-matching-brace",
+                          G_BINDING_SYNC_CREATE);
+  ide_binding_group_bind (self->view_file_settings,
+                          "overwrite-braces", self->view, "overwrite-braces",
+                          G_BINDING_SYNC_CREATE);
+#endif
+
+  _ide_editor_page_settings_reload (self);
+
+  IDE_EXIT;
+}
diff --git a/src/libide/editor/ide-editor-page.c b/src/libide/editor/ide-editor-page.c
index 4999113ad..5ae1e3873 100644
--- a/src/libide/editor/ide-editor-page.c
+++ b/src/libide/editor/ide-editor-page.c
@@ -69,8 +69,18 @@ ide_editor_page_set_buffer (IdeEditorPage *self,
                                self,
                                G_CONNECT_SWAPPED);
 
-      g_object_bind_property (buffer, "title", self, "title", G_BINDING_SYNC_CREATE);
+      g_signal_connect_object (buffer,
+                               "notify::file-settings",
+                               G_CALLBACK (_ide_editor_page_settings_reload),
+                               self,
+                               G_CONNECT_SWAPPED);
+
+      g_object_bind_property (buffer, "title",
+                              self, "title",
+                              G_BINDING_SYNC_CREATE);
+
       ide_editor_page_modified_changed_cb (self, buffer);
+      _ide_editor_page_settings_init (self);
     }
 
   IDE_EXIT;
@@ -87,6 +97,8 @@ ide_editor_page_dispose (GObject *object)
 {
   IdeEditorPage *self = (IdeEditorPage *)object;
 
+  g_clear_object (&self->buffer_file_settings);
+  g_clear_object (&self->view_file_settings);
   g_clear_object (&self->buffer);
 
   G_OBJECT_CLASS (ide_editor_page_parent_class)->dispose (object);
diff --git a/src/libide/editor/ide-editor-page.ui b/src/libide/editor/ide-editor-page.ui
index 88d87eb0c..e196b00e1 100644
--- a/src/libide/editor/ide-editor-page.ui
+++ b/src/libide/editor/ide-editor-page.ui
@@ -16,6 +16,8 @@
                         <property name="monospace">true</property>
                         <property name="hexpand">true</property>
                         <property name="vexpand">true</property>
+                        <!-- until we have custom gutter renderer ported -->
+                        <property name="show-line-numbers">true</property>
                       </object>
                     </child>
                   </object>
diff --git a/src/libide/editor/meson.build b/src/libide/editor/meson.build
index 42317d764..5fbfb8ff7 100644
--- a/src/libide/editor/meson.build
+++ b/src/libide/editor/meson.build
@@ -17,6 +17,7 @@ libide_editor_public_headers = [
 ]
 
 libide_editor_private_headers = [
+  'ide-editor-page-private.h',
 ]
 
 install_headers(libide_editor_public_headers, subdir: libide_editor_header_subdir)
@@ -33,6 +34,7 @@ libide_editor_public_sources = [
 
 libide_editor_private_sources = [
   'ide-editor-init.c',
+  'ide-editor-page-settings.c',
 ]
 
 libide_editor_sources += libide_editor_public_sources


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]