[gnome-text-editor] settings: add indent-style helper



commit 7dcbc85ed832557808fa2a1df5884d51d0809d4b
Author: Christian Hergert <chergert redhat com>
Date:   Mon Feb 21 17:42:09 2022 -0800

    settings: add indent-style helper
    
    This makes it easier to bind to actions with roles.

 src/editor-page-settings.c | 18 ++++++++++++++++++
 src/editor-page-settings.h |  1 +
 src/editor-types.h         |  6 ++++++
 src/meson.build            |  1 +
 4 files changed, 26 insertions(+)
---
diff --git a/src/editor-page-settings.c b/src/editor-page-settings.c
index 80af200..1fde707 100644
--- a/src/editor-page-settings.c
+++ b/src/editor-page-settings.c
@@ -23,6 +23,7 @@
 #include "config.h"
 
 #include "editor-document.h"
+#include "editor-enums.h"
 #include "editor-page-gsettings-private.h"
 #include "editor-page-settings.h"
 #include "editor-page-settings-provider.h"
@@ -66,6 +67,7 @@ enum {
   PROP_DOCUMENT,
   PROP_HIGHLIGHT_CURRENT_LINE,
   PROP_INDENT_WIDTH,
+  PROP_INDENT_STYLE,
   PROP_INSERT_SPACES_INSTEAD_OF_TABS,
   PROP_RIGHT_MARGIN_POSITION,
   PROP_SHOW_GRID,
@@ -286,6 +288,10 @@ editor_page_settings_get_property (GObject    *object,
       g_value_set_boolean (value, editor_page_settings_get_insert_spaces_instead_of_tabs (self));
       break;
 
+    case PROP_INDENT_STYLE:
+      g_value_set_enum (value, !!editor_page_settings_get_insert_spaces_instead_of_tabs (self));
+      break;
+
     case PROP_RIGHT_MARGIN_POSITION:
       g_value_set_uint (value, editor_page_settings_get_right_margin_position (self));
       break;
@@ -374,6 +380,12 @@ editor_page_settings_set_property (GObject      *object,
 
     case PROP_INSERT_SPACES_INSTEAD_OF_TABS:
       self->insert_spaces_instead_of_tabs = g_value_get_boolean (value);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_INDENT_STYLE]);
+      break;
+
+    case PROP_INDENT_STYLE:
+      self->insert_spaces_instead_of_tabs = !!g_value_get_enum (value);
+      g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_INSERT_SPACES_INSTEAD_OF_TABS]);
       break;
 
     case PROP_SHOW_LINE_NUMBERS:
@@ -466,6 +478,12 @@ editor_page_settings_class_init (EditorPageSettingsClass *klass)
                           FALSE,
                           (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_INDENT_STYLE] =
+    g_param_spec_enum ("indent-style", NULL, NULL,
+                       EDITOR_TYPE_INDENT_STYLE,
+                       EDITOR_INDENT_STYLE_TAB,
+                       (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_RIGHT_MARGIN_POSITION] =
     g_param_spec_uint ("right-margin-position",
                        "Right Margin Position",
diff --git a/src/editor-page-settings.h b/src/editor-page-settings.h
index bef0112..253fa9b 100644
--- a/src/editor-page-settings.h
+++ b/src/editor-page-settings.h
@@ -44,5 +44,6 @@ gboolean            editor_page_settings_get_wrap_text                     (Edit
 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);
+EditorIndentStyle   editor_page_settings_get_indent_style                  (EditorPageSettings *self);
 
 G_END_DECLS
diff --git a/src/editor-types.h b/src/editor-types.h
index c634328..a4bb462 100644
--- a/src/editor-types.h
+++ b/src/editor-types.h
@@ -47,4 +47,10 @@ typedef struct _EditorSpellProvider        EditorSpellProvider;
 typedef struct _EditorTab                  EditorTab;
 typedef struct _EditorWindow               EditorWindow;
 
+typedef enum
+{
+  EDITOR_INDENT_STYLE_TAB = 0,
+  EDITOR_INDENT_STYLE_SPACE,
+} EditorIndentStyle;
+
 G_END_DECLS
diff --git a/src/meson.build b/src/meson.build
index 2efd692..10056f4 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -70,6 +70,7 @@ editor_sources += gnome.compile_resources('editor-resources',
 
 editor_enums_headers = [
   'editor-search-bar-private.h',
+  'editor-types.h',
 ]
 
 editor_enums = gnome.mkenums_simple('editor-enums',


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