[gnome-builder] plugins/editorui: add tweaks for space drawing



commit 83785181b6296515512ad4caf594c85b35496c5a
Author: Christian Hergert <chergert redhat com>
Date:   Mon Sep 5 21:18:40 2022 -0700

    plugins/editorui: add tweaks for space drawing

 src/libide/editor/ide-editor-page-settings.c |  66 ++++++++++++++++++
 src/plugins/editorui/tweaks.ui               | 100 +++++++++++++++++++++++++++
 2 files changed, 166 insertions(+)
---
diff --git a/src/libide/editor/ide-editor-page-settings.c b/src/libide/editor/ide-editor-page-settings.c
index 40d8fac67..48fae58e6 100644
--- a/src/libide/editor/ide-editor-page-settings.c
+++ b/src/libide/editor/ide-editor-page-settings.c
@@ -139,6 +139,65 @@ notify_interactive_completion_cb (IdeEditorPage *self,
     }
 }
 
+static void
+on_draw_spaces_changed (IdeEditorPage *self,
+                        const char    *key,
+                        GSettings     *settings)
+{
+  GtkSourceSpaceDrawer *drawer;
+  GtkSourceView *source_view;
+  GtkSourceSpaceLocationFlags location_flags = GTK_SOURCE_SPACE_LOCATION_NONE;
+  GtkSourceSpaceTypeFlags type_flags = GTK_SOURCE_SPACE_TYPE_NONE;
+  guint flags;
+
+  g_assert (IDE_IS_EDITOR_PAGE (self));
+  g_assert (g_strcmp0 (key, "draw-spaces") == 0);
+  g_assert (G_IS_SETTINGS (settings));
+
+  source_view = GTK_SOURCE_VIEW (ide_editor_page_get_view (self));
+  drawer = gtk_source_view_get_space_drawer (source_view);
+  flags = g_settings_get_flags (settings, "draw-spaces");
+
+  if (flags == 0)
+    {
+      gtk_source_space_drawer_set_enable_matrix (drawer, FALSE);
+      return;
+    }
+
+  /* Reset the matrix before setting it */
+  gtk_source_space_drawer_set_types_for_locations (drawer, GTK_SOURCE_SPACE_LOCATION_ALL, 
GTK_SOURCE_SPACE_TYPE_NONE);
+
+  if (flags & 1)
+    type_flags |= GTK_SOURCE_SPACE_TYPE_SPACE;
+
+  if (flags & 2)
+    type_flags |= GTK_SOURCE_SPACE_TYPE_TAB;
+
+  if (flags & 4)
+    {
+      gtk_source_space_drawer_set_types_for_locations (drawer, GTK_SOURCE_SPACE_LOCATION_ALL, 
GTK_SOURCE_SPACE_TYPE_NEWLINE);
+      type_flags |= GTK_SOURCE_SPACE_TYPE_NEWLINE;
+    }
+
+  if (flags & 8)
+    type_flags |= GTK_SOURCE_SPACE_TYPE_NBSP;
+
+  if (flags & 16)
+    location_flags |= GTK_SOURCE_SPACE_LOCATION_LEADING;
+
+  if (flags & 32)
+    location_flags |= GTK_SOURCE_SPACE_LOCATION_INSIDE_TEXT;
+
+  if (flags & 64)
+    location_flags |= GTK_SOURCE_SPACE_LOCATION_TRAILING;
+
+  if (type_flags > 0 && location_flags == 0)
+    location_flags |= GTK_SOURCE_SPACE_LOCATION_ALL;
+
+  gtk_source_space_drawer_set_enable_matrix (drawer, TRUE);
+  gtk_source_space_drawer_set_types_for_locations (drawer, location_flags, type_flags);
+}
+
 void
 _ide_editor_page_settings_init (IdeEditorPage *self)
 {
@@ -247,6 +306,13 @@ _ide_editor_page_settings_init (IdeEditorPage *self)
                            G_CONNECT_SWAPPED);
   notify_interactive_completion_cb (self, NULL, editor_settings);
 
+  g_signal_connect_object (editor_settings,
+                           "changed::draw-spaces",
+                           G_CALLBACK (on_draw_spaces_changed),
+                           self,
+                           G_CONNECT_SWAPPED);
+  on_draw_spaces_changed (self, "draw-spaces", editor_settings);
+
   _ide_editor_page_settings_reload (self);
 
   IDE_EXIT;
diff --git a/src/plugins/editorui/tweaks.ui b/src/plugins/editorui/tweaks.ui
index 1feaa8ba4..e985a67a4 100644
--- a/src/plugins/editorui/tweaks.ui
+++ b/src/plugins/editorui/tweaks.ui
@@ -249,6 +249,106 @@
                         </child>
                       </object>
                     </child>
+                    <child>
+                      <object class="IdeTweaksGroup">
+                        <property name="title" translatable="yes">Draw Spaces</property>
+                        <child>
+                          <object class="IdeTweaksRadio">
+                            <property name="title" translatable="yes">Spaces</property>
+                            <property name="subtitle" translatable="yes">Draw a mark representing normal 
spaces</property>
+                            <property name="value">'space'</property>
+                            <property name="binding">
+                              <object class="IdeTweaksSetting">
+                                <property name="schema-id">org.gnome.builder.editor</property>
+                                <property name="schema-key">draw-spaces</property>
+                              </object>
+                            </property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="IdeTweaksRadio">
+                            <property name="title" translatable="yes">Tabs</property>
+                            <property name="subtitle" translatable="yes">Draw a mark representing 
tabs</property>
+                            <property name="value">'tab'</property>
+                            <property name="binding">
+                              <object class="IdeTweaksSetting">
+                                <property name="schema-id">org.gnome.builder.editor</property>
+                                <property name="schema-key">draw-spaces</property>
+                              </object>
+                            </property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="IdeTweaksRadio">
+                            <property name="title" translatable="yes">Newlines</property>
+                            <property name="subtitle" translatable="yes">Draw a mark at the end of 
lines</property>
+                            <property name="value">'newline'</property>
+                            <property name="binding">
+                              <object class="IdeTweaksSetting">
+                                <property name="schema-id">org.gnome.builder.editor</property>
+                                <property name="schema-key">draw-spaces</property>
+                              </object>
+                            </property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="IdeTweaksRadio">
+                            <property name="title" translatable="yes">Non-breaking spaces</property>
+                            <property name="subtitle" translatable="yes">Draw a mark at non-breaking space 
characters</property>
+                            <property name="value">'nbsp'</property>
+                            <property name="binding">
+                              <object class="IdeTweaksSetting">
+                                <property name="schema-id">org.gnome.builder.editor</property>
+                                <property name="schema-key">draw-spaces</property>
+                              </object>
+                            </property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
+                    <child>
+                      <object class="IdeTweaksGroup">
+                        <child>
+                          <object class="IdeTweaksRadio">
+                            <property name="title" translatable="yes">Leading</property>
+                            <property name="subtitle" translatable="yes">Draw marks for leading spaces 
only</property>
+                            <property name="value">'leading'</property>
+                            <property name="binding">
+                              <object class="IdeTweaksSetting">
+                                <property name="schema-id">org.gnome.builder.editor</property>
+                                <property name="schema-key">draw-spaces</property>
+                              </object>
+                            </property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="IdeTweaksRadio">
+                            <property name="title" translatable="yes">Inside Text</property>
+                            <property name="subtitle" translatable="yes">Draw marks inside a line of text 
only</property>
+                            <property name="value">'text'</property>
+                            <property name="binding">
+                              <object class="IdeTweaksSetting">
+                                <property name="schema-id">org.gnome.builder.editor</property>
+                                <property name="schema-key">draw-spaces</property>
+                              </object>
+                            </property>
+                          </object>
+                        </child>
+                        <child>
+                          <object class="IdeTweaksRadio">
+                            <property name="title" translatable="yes">Trailing</property>
+                            <property name="subtitle" translatable="yes">Draw marks for trailing spaces 
only</property>
+                            <property name="value">'trailing'</property>
+                            <property name="binding">
+                              <object class="IdeTweaksSetting">
+                                <property name="schema-id">org.gnome.builder.editor</property>
+                                <property name="schema-key">draw-spaces</property>
+                              </object>
+                            </property>
+                          </object>
+                        </child>
+                      </object>
+                    </child>
                   </object>
                 </child>
                 <child>


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