[gnome-text-editor] settings: add support for highlighting the current line



commit 9925a5474c494c9bfc09985b323054b7e1ca9487
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 30 09:43:35 2021 -0700

    settings: add support for highlighting the current line
    
    For now, this can go in appearance in preferences. But should we want to,
    we can move it elsewhere.
    
    Fixes #106

 data/org.gnome.TextEditor.gschema.xml |  5 +++++
 src/editor-page-gsettings.c           |  2 ++
 src/editor-page-settings-provider.c   | 22 ++++++++++++++++++++++
 src/editor-page-settings-provider.h   |  4 ++++
 src/editor-page-settings.c            | 26 ++++++++++++++++++++++++++
 src/editor-page-settings.h            |  1 +
 src/editor-page.c                     |  3 +++
 src/editor-preferences-window.ui      |  6 ++++++
 8 files changed, 69 insertions(+)
---
diff --git a/data/org.gnome.TextEditor.gschema.xml b/data/org.gnome.TextEditor.gschema.xml
index 15af4eb..7195118 100644
--- a/data/org.gnome.TextEditor.gschema.xml
+++ b/data/org.gnome.TextEditor.gschema.xml
@@ -56,6 +56,11 @@
       <summary>Show Background Grid</summary>
       <description>If enabled, a blueprint style grid is printed on the editor background.</description>
     </key>
+    <key name="highlight-current-line" type="b">
+      <default>false</default>
+      <summary>Highlight current line</summary>
+      <description>If enabled, the current line will be highlighted.</description>
+    </key>
     <key name="wrap-text" type="b">
       <default>true</default>
       <summary>Text Wrapping</summary>
diff --git a/src/editor-page-gsettings.c b/src/editor-page-gsettings.c
index 096e726..9ae459e 100644
--- a/src/editor-page-gsettings.c
+++ b/src/editor-page-gsettings.c
@@ -48,6 +48,7 @@ GSETTINGS_GETTER (gboolean, boolean, use_system_font, "use-system-font")
 GSETTINGS_GETTER (gboolean, boolean, wrap_text, "wrap-text")
 GSETTINGS_GETTER (gboolean, boolean, show_map, "show-map")
 GSETTINGS_GETTER (gboolean, boolean, show_grid, "show-grid")
+GSETTINGS_GETTER (gboolean, boolean, highlight_current_line, "highlight-current-line")
 GSETTINGS_GETTER (guint, uint, right_margin_position, "right-margin-position")
 
 static gboolean
@@ -159,6 +160,7 @@ page_settings_provider_iface_init (EditorPageSettingsProviderInterface *iface)
   iface->get_wrap_text = editor_page_gsettings_get_wrap_text;
   iface->get_style_scheme = editor_page_gsettings_get_style_scheme;
   iface->get_style_variant = editor_page_gsettings_get_style_variant;
+  iface->get_highlight_current_line = editor_page_gsettings_get_highlight_current_line;
 }
 
 G_DEFINE_TYPE_WITH_CODE (EditorPageGsettings, editor_page_gsettings, G_TYPE_OBJECT,
diff --git a/src/editor-page-settings-provider.c b/src/editor-page-settings-provider.c
index 7d1bc0e..c990fd8 100644
--- a/src/editor-page-settings-provider.c
+++ b/src/editor-page-settings-provider.c
@@ -343,3 +343,25 @@ editor_page_settings_provider_get_show_grid (EditorPageSettingsProvider *self,
 
   return FALSE;
 }
+
+/**
+ * editor_page_settings_provider_get_highlight_current_line:
+ * @self: a #EditorPageSettingsProvider
+ * @highlight_current_line: (out) (optional): a location to store the setting
+ *
+ * Returns: %TRUE if @highlight_current_line was set by the provider.
+ */
+gboolean
+editor_page_settings_provider_get_highlight_current_line (EditorPageSettingsProvider *self,
+                                                          gboolean                   *highlight_current_line)
+{
+  g_return_val_if_fail (EDITOR_IS_PAGE_SETTINGS_PROVIDER (self), FALSE);
+
+  if (highlight_current_line != NULL)
+    *highlight_current_line = FALSE;
+
+  if (EDITOR_PAGE_SETTINGS_PROVIDER_GET_IFACE (self)->get_highlight_current_line)
+    return EDITOR_PAGE_SETTINGS_PROVIDER_GET_IFACE (self)->get_highlight_current_line (self, 
highlight_current_line);
+
+  return FALSE;
+}
diff --git a/src/editor-page-settings-provider.h b/src/editor-page-settings-provider.h
index fdfd25d..18becfb 100644
--- a/src/editor-page-settings-provider.h
+++ b/src/editor-page-settings-provider.h
@@ -59,6 +59,8 @@ struct _EditorPageSettingsProviderInterface
                                                   gboolean                   *show_map);
   gboolean  (*get_show_grid)                     (EditorPageSettingsProvider *self,
                                                   gboolean                   *show_grid);
+  gboolean  (*get_highlight_current_line)        (EditorPageSettingsProvider *self,
+                                                  gboolean                   *highlight_current_line);
 };
 
 void     editor_page_settings_provider_emit_changed                      (EditorPageSettingsProvider  *self);
@@ -90,5 +92,7 @@ gboolean editor_page_settings_provider_get_show_map                      (Editor
                                                                           gboolean                    
*show_map);
 gboolean editor_page_settings_provider_get_show_grid                     (EditorPageSettingsProvider  *self,
                                                                           gboolean                    
*show_grid);
+gboolean editor_page_settings_provider_get_highlight_current_line        (EditorPageSettingsProvider  *self,
+                                                                          gboolean                    
*highlight_current_line);
 
 G_END_DECLS
diff --git a/src/editor-page-settings.c b/src/editor-page-settings.c
index b80ff65..0ebb93f 100644
--- a/src/editor-page-settings.c
+++ b/src/editor-page-settings.c
@@ -46,6 +46,7 @@ struct _EditorPageSettings
   guint right_margin_position;
   guint tab_width;
 
+  guint highlight_current_line : 1;
   guint insert_spaces_instead_of_tabs : 1;
   guint show_line_numbers : 1;
   guint show_grid : 1;
@@ -60,6 +61,7 @@ enum {
   PROP_CUSTOM_FONT,
   PROP_STYLE_VARIANT,
   PROP_DOCUMENT,
+  PROP_HIGHLIGHT_CURRENT_LINE,
   PROP_INSERT_SPACES_INSTEAD_OF_TABS,
   PROP_RIGHT_MARGIN_POSITION,
   PROP_SHOW_GRID,
@@ -127,6 +129,7 @@ editor_page_settings_update (EditorPageSettings *self)
   UPDATE_SETTING (gboolean, show_grid, SHOW_GRID, cmp_boolean, (void), (gboolean));
   UPDATE_SETTING (gboolean, show_map, SHOW_MAP, cmp_boolean, (void), (gboolean));
   UPDATE_SETTING (gboolean, show_right_margin, SHOW_RIGHT_MARGIN, cmp_boolean, (void), (gboolean));
+  UPDATE_SETTING (gboolean, highlight_current_line, HIGHLIGHT_CURRENT_LINE, cmp_boolean, (void), (gboolean));
   UPDATE_SETTING (gboolean, use_system_font, USE_SYSTEM_FONT, cmp_boolean, (void), (gboolean));
   UPDATE_SETTING (gboolean, wrap_text, WRAP_TEXT, cmp_boolean, (void), (gboolean));
   UPDATE_SETTING (guint, tab_width, TAB_WIDTH, cmp_uint, (void), (guint));
@@ -261,6 +264,10 @@ editor_page_settings_get_property (GObject    *object,
       g_value_set_string (value, editor_page_settings_get_style_variant (self));
       break;
 
+    case PROP_HIGHLIGHT_CURRENT_LINE:
+      g_value_set_boolean (value, editor_page_settings_get_highlight_current_line (self));
+      break;
+
     case PROP_INSERT_SPACES_INSTEAD_OF_TABS:
       g_value_set_boolean (value, editor_page_settings_get_insert_spaces_instead_of_tabs (self));
       break;
@@ -335,6 +342,10 @@ editor_page_settings_set_property (GObject      *object,
       self->style_variant = g_value_dup_string (value);
       break;
 
+    case PROP_HIGHLIGHT_CURRENT_LINE:
+      self->highlight_current_line = g_value_get_boolean (value);
+      break;
+
     case PROP_INSERT_SPACES_INSTEAD_OF_TABS:
       self->insert_spaces_instead_of_tabs = g_value_get_boolean (value);
       break;
@@ -411,6 +422,13 @@ editor_page_settings_class_init (EditorPageSettingsClass *klass)
                          EDITOR_TYPE_DOCUMENT,
                          (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS));
 
+  properties [PROP_HIGHLIGHT_CURRENT_LINE] =
+    g_param_spec_boolean ("highlight-current-line",
+                          "Highlight Current Line",
+                          "Highlight Current Line",
+                          FALSE,
+                          (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+
   properties [PROP_INSERT_SPACES_INSTEAD_OF_TABS] =
     g_param_spec_boolean ("insert-spaces-instead-of-tabs",
                           "Insert Spaces Instead of Tabs",
@@ -596,3 +614,11 @@ editor_page_settings_get_tab_width (EditorPageSettings *self)
 
   return self->tab_width;
 }
+
+gboolean
+editor_page_settings_get_highlight_current_line (EditorPageSettings *self)
+{
+  g_return_val_if_fail (EDITOR_IS_PAGE_SETTINGS (self), FALSE);
+
+  return self->highlight_current_line;
+}
diff --git a/src/editor-page-settings.h b/src/editor-page-settings.h
index 7bcdfb9..29b1ad9 100644
--- a/src/editor-page-settings.h
+++ b/src/editor-page-settings.h
@@ -41,5 +41,6 @@ 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);
+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 7915daf..3b43357 100644
--- a/src/editor-page.c
+++ b/src/editor-page.c
@@ -258,6 +258,9 @@ editor_page_constructed (GObject *object)
   editor_binding_group_bind (self->settings_bindings, "show-right-margin",
                              self->view, "show-right-margin",
                              G_BINDING_SYNC_CREATE);
+  editor_binding_group_bind (self->settings_bindings, "highlight-current-line",
+                             self->view, "highlight-current-line",
+                             G_BINDING_SYNC_CREATE);
   editor_binding_group_bind_full (self->settings_bindings, "show-grid",
                                   self->view, "background-pattern",
                                   G_BINDING_SYNC_CREATE,
diff --git a/src/editor-preferences-window.ui b/src/editor-preferences-window.ui
index 48cd588..a4f782d 100644
--- a/src/editor-preferences-window.ui
+++ b/src/editor-preferences-window.ui
@@ -45,6 +45,12 @@
                 <property name="schema-key">show-grid</property>
               </object>
             </child>
+            <child>
+              <object class="EditorPreferencesSwitch" id="highlight_current_line">
+                <property name="title" translatable="yes">Highlight Current Line</property>
+                <property name="schema-key">highlight-current-line</property>
+              </object>
+            </child>
             <child>
               <object class="EditorPreferencesSwitch" id="map">
                 <property name="title" translatable="yes">Display Overview Map</property>


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