[gnome-text-editor] pagesettings: add indent-width separate from tab-width



commit 01f4567196fe601202754b3ff6bea58654a9fcc4
Author: Christian Hergert <chergert redhat com>
Date:   Wed Oct 27 07:09:59 2021 -0700

    pagesettings: add indent-width separate from tab-width
    
    Related #200

 src/editor-page-settings-provider.c | 22 ++++++++++++++++++++++
 src/editor-page-settings-provider.h |  4 ++++
 src/editor-page-settings.c          | 37 ++++++++++++++++++++++++++++++++++++-
 src/editor-page-settings.h          |  1 +
 src/editor-page.c                   |  3 +++
 5 files changed, 66 insertions(+), 1 deletion(-)
---
diff --git a/src/editor-page-settings-provider.c b/src/editor-page-settings-provider.c
index a534819..026c2b7 100644
--- a/src/editor-page-settings-provider.c
+++ b/src/editor-page-settings-provider.c
@@ -300,6 +300,28 @@ editor_page_settings_provider_get_tab_width (EditorPageSettingsProvider *self,
   return FALSE;
 }
 
+/**
+ * editor_page_settings_provider_get_indent_width:
+ * @self: a #EditorPageSettingsProvider
+ * @indent_width: (out) (optional): the width of indentation
+ *
+ * Returns: %TRUE if @indent_width was set by the provider.
+ */
+gboolean
+editor_page_settings_provider_get_indent_width (EditorPageSettingsProvider *self,
+                                                int                        *indent_width)
+{
+  g_return_val_if_fail (EDITOR_IS_PAGE_SETTINGS_PROVIDER (self), FALSE);
+
+  if (indent_width != NULL)
+    *indent_width = -1;
+
+  if (EDITOR_PAGE_SETTINGS_PROVIDER_GET_IFACE (self)->get_indent_width)
+    return EDITOR_PAGE_SETTINGS_PROVIDER_GET_IFACE (self)->get_indent_width (self, indent_width);
+
+  return FALSE;
+}
+
 /**
  * editor_page_settings_provider_get_right_margin_position:
  * @self: a #EditorPageSettingsProvider
diff --git a/src/editor-page-settings-provider.h b/src/editor-page-settings-provider.h
index 78a2a4d..cb2be17 100644
--- a/src/editor-page-settings-provider.h
+++ b/src/editor-page-settings-provider.h
@@ -63,6 +63,8 @@ struct _EditorPageSettingsProviderInterface
                                                   gboolean                   *highlight_current_line);
   gboolean  (*get_auto_indent)                   (EditorPageSettingsProvider *self,
                                                   gboolean                   *auto_indent);
+  gboolean  (*get_indent_width)                  (EditorPageSettingsProvider *self,
+                                                  int                        *indent_width);
 };
 
 void     editor_page_settings_provider_emit_changed                      (EditorPageSettingsProvider  *self);
@@ -92,6 +94,8 @@ gboolean editor_page_settings_provider_get_wrap_text                     (Editor
                                                                           gboolean                    
*wrap_text);
 gboolean editor_page_settings_provider_get_tab_width                     (EditorPageSettingsProvider  *self,
                                                                           guint                       
*tab_width);
+gboolean editor_page_settings_provider_get_indent_width                  (EditorPageSettingsProvider  *self,
+                                                                          int                         
*indent_width);
 gboolean editor_page_settings_provider_get_show_map                      (EditorPageSettingsProvider  *self,
                                                                           gboolean                    
*show_map);
 gboolean editor_page_settings_provider_get_show_grid                     (EditorPageSettingsProvider  *self,
diff --git a/src/editor-page-settings.c b/src/editor-page-settings.c
index 3db6c85..64d7937 100644
--- a/src/editor-page-settings.c
+++ b/src/editor-page-settings.c
@@ -45,6 +45,7 @@ struct _EditorPageSettings
 
   guint right_margin_position;
   guint tab_width;
+  int indent_width;
 
   guint highlight_current_line : 1;
   guint insert_spaces_instead_of_tabs : 1;
@@ -64,6 +65,7 @@ enum {
   PROP_STYLE_VARIANT,
   PROP_DOCUMENT,
   PROP_HIGHLIGHT_CURRENT_LINE,
+  PROP_INDENT_WIDTH,
   PROP_INSERT_SPACES_INSTEAD_OF_TABS,
   PROP_RIGHT_MARGIN_POSITION,
   PROP_SHOW_GRID,
@@ -102,6 +104,13 @@ cmp_uint (guint a,
   return a == b;
 }
 
+static inline gboolean
+cmp_int (int a,
+         int b)
+{
+  return a == b;
+}
+
 static void
 editor_page_settings_update (EditorPageSettings *self)
 {
@@ -115,10 +124,11 @@ editor_page_settings_update (EditorPageSettings *self)
         EditorPageSettingsProvider *p = g_ptr_array_index (self->providers, i);       \
         if (editor_page_settings_provider_get_##name (p, &name))                      \
           {                                                                           \
-            if (!cmp (self->name,  name))                                             \
+            if (!cmp (self->name, name))                                              \
               {                                                                       \
                 free_func (self->name);                                               \
                 self->name = dup_func (name);                                         \
+                g_debug ("using %s from %s\n", #name, G_OBJECT_TYPE_NAME (p));        \
                 g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_##NAME]); \
               }                                                                       \
             break;                                                                    \
@@ -136,6 +146,7 @@ editor_page_settings_update (EditorPageSettings *self)
   UPDATE_SETTING (gboolean, wrap_text, WRAP_TEXT, cmp_boolean, (void), (gboolean));
   UPDATE_SETTING (gboolean, auto_indent, AUTO_INDENT, cmp_boolean, (void), (gboolean));
   UPDATE_SETTING (guint, tab_width, TAB_WIDTH, cmp_uint, (void), (guint));
+  UPDATE_SETTING (int, indent_width, INDENT_WIDTH, cmp_int, (void), (int));
   UPDATE_SETTING (guint, right_margin_position, RIGHT_MARGIN_POSITION, cmp_uint, (void), (guint));
   UPDATE_SETTING (g_autofree gchar *, custom_font, CUSTOM_FONT, cmp_string, g_free, g_strdup);
   UPDATE_SETTING (g_autofree gchar *, style_scheme, STYLE_SCHEME, cmp_string, g_free, g_strdup);
@@ -299,6 +310,10 @@ editor_page_settings_get_property (GObject    *object,
       g_value_set_uint (value, editor_page_settings_get_tab_width (self));
       break;
 
+    case PROP_INDENT_WIDTH:
+      g_value_set_int (value, editor_page_settings_get_indent_width (self));
+      break;
+
     case PROP_USE_SYSTEM_FONT:
       g_value_set_boolean (value, editor_page_settings_get_use_system_font (self));
       break;
@@ -377,6 +392,10 @@ editor_page_settings_set_property (GObject      *object,
       self->tab_width = g_value_get_uint (value);
       break;
 
+    case PROP_INDENT_WIDTH:
+      self->indent_width = g_value_get_int (value);
+      break;
+
     case PROP_USE_SYSTEM_FONT:
       self->use_system_font = g_value_get_boolean (value);
       break;
@@ -485,6 +504,13 @@ editor_page_settings_class_init (EditorPageSettingsClass *klass)
                        1, 32, 8,
                        (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_INDENT_WIDTH] =
+    g_param_spec_int ("indent-width",
+                      "Indent Width",
+                      "The width to use for indentation, or -1 to use tab width",
+                      -1, 32, -1,
+                      (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_USE_SYSTEM_FONT] =
     g_param_spec_boolean ("use-system-font",
                           "Use System Font",
@@ -517,6 +543,7 @@ editor_page_settings_init (EditorPageSettings *self)
   self->use_system_font = TRUE;
   self->right_margin_position = 80;
   self->tab_width = 8;
+  self->indent_width = -1;
   self->settings = g_settings_new ("org.gnome.TextEditor");
 
   g_signal_connect_object (self->settings,
@@ -638,6 +665,14 @@ editor_page_settings_get_tab_width (EditorPageSettings *self)
   return self->tab_width;
 }
 
+int
+editor_page_settings_get_indent_width (EditorPageSettings *self)
+{
+  g_return_val_if_fail (EDITOR_IS_PAGE_SETTINGS (self), -1);
+
+  return self->indent_width;
+}
+
 gboolean
 editor_page_settings_get_highlight_current_line (EditorPageSettings *self)
 {
diff --git a/src/editor-page-settings.h b/src/editor-page-settings.h
index 8096bc2..bef0112 100644
--- a/src/editor-page-settings.h
+++ b/src/editor-page-settings.h
@@ -42,6 +42,7 @@ gboolean            editor_page_settings_get_show_right_margin             (Edit
 gboolean            editor_page_settings_get_use_system_font               (EditorPageSettings *self);
 gboolean            editor_page_settings_get_wrap_text                     (EditorPageSettings *self);
 guint               editor_page_settings_get_tab_width                     (EditorPageSettings *self);
+int                 editor_page_settings_get_indent_width                  (EditorPageSettings *self);
 gboolean            editor_page_settings_get_highlight_current_line        (EditorPageSettings *self);
 
 G_END_DECLS
diff --git a/src/editor-page.c b/src/editor-page.c
index 3cce26f..b8ff428 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -315,6 +315,9 @@ editor_page_constructed (GObject *object)
   editor_binding_group_bind (self->settings_bindings, "tab-width",
                              self->view, "tab-width",
                              G_BINDING_SYNC_CREATE);
+  editor_binding_group_bind (self->settings_bindings, "indent-width",
+                             self->view, "indent-width",
+                             G_BINDING_SYNC_CREATE);
   editor_binding_group_bind (self->settings_bindings, "auto-indent",
                              self->view, "auto-indent",
                              G_BINDING_SYNC_CREATE);


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