[gnome-builder/wip/gtk4-port] plugins/editorui: allow toggling indent/tab widths



commit 28156edfd6743391a21ede16cd148713127647b4
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jun 1 15:23:14 2022 -0700

    plugins/editorui: allow toggling indent/tab widths

 .../editorui/gbp-editorui-workspace-addin.c        | 14 +++--
 src/plugins/editorui/gtk/menus.ui                  | 59 ++++++++++++++++------
 2 files changed, 54 insertions(+), 19 deletions(-)
---
diff --git a/src/plugins/editorui/gbp-editorui-workspace-addin.c 
b/src/plugins/editorui/gbp-editorui-workspace-addin.c
index 5d3cd1812..414502c85 100644
--- a/src/plugins/editorui/gbp-editorui-workspace-addin.c
+++ b/src/plugins/editorui/gbp-editorui-workspace-addin.c
@@ -506,6 +506,8 @@ gbp_editorui_workspace_addin_page_changed (IdeWorkspaceAddin *addin,
   /* Remove now invalid actions */
   g_action_map_remove_action (G_ACTION_MAP (self->actions), "encoding");
   g_action_map_remove_action (G_ACTION_MAP (self->actions), "newline-type");
+  g_action_map_remove_action (G_ACTION_MAP (self->actions), "indent-width");
+  g_action_map_remove_action (G_ACTION_MAP (self->actions), "tab-width");
 
   if (!IDE_IS_EDITOR_PAGE (page))
     page = NULL;
@@ -514,17 +516,21 @@ gbp_editorui_workspace_addin_page_changed (IdeWorkspaceAddin *addin,
     {
       g_autoptr(GPropertyAction) encoding_action = NULL;
       g_autoptr(GPropertyAction) newline_action = NULL;
+      g_autoptr(GPropertyAction) indent_width = NULL;
+      g_autoptr(GPropertyAction) tab_width = NULL;
 
       view = ide_editor_page_get_view (IDE_EDITOR_PAGE (page));
       buffer = ide_editor_page_get_buffer (IDE_EDITOR_PAGE (page));
 
-      /* Export charset control via action */
       encoding_action = g_property_action_new ("encoding", buffer, "charset");
-      g_action_map_add_action (G_ACTION_MAP (self->actions), G_ACTION (encoding_action));
-
-      /* Export newline-type via action */
       newline_action = g_property_action_new ("newline-type", buffer, "newline-type");
+      indent_width = g_property_action_new ("indent-width", view, "indent-width");
+      tab_width = g_property_action_new ("tab-width", view, "tab-width");
+
+      g_action_map_add_action (G_ACTION_MAP (self->actions), G_ACTION (encoding_action));
       g_action_map_add_action (G_ACTION_MAP (self->actions), G_ACTION (newline_action));
+      g_action_map_add_action (G_ACTION_MAP (self->actions), G_ACTION (tab_width));
+      g_action_map_add_action (G_ACTION_MAP (self->actions), G_ACTION (indent_width));
     }
 
   ide_binding_group_set_source (self->buffer_bindings, buffer);
diff --git a/src/plugins/editorui/gtk/menus.ui b/src/plugins/editorui/gtk/menus.ui
index 489217bf6..1b9a6cdaa 100644
--- a/src/plugins/editorui/gtk/menus.ui
+++ b/src/plugins/editorui/gtk/menus.ui
@@ -19,37 +19,66 @@
         <attribute name="label" translatable="yes">Spaces per Tab</attribute>
         <item>
           <attribute name="label" translatable="yes">2</attribute>
+          <attribute name="action">editorui.tab-width</attribute>
+          <attribute name="target" type="u">2</attribute>
         </item>
         <item>
           <attribute name="label" translatable="yes">3</attribute>
+          <attribute name="action">editorui.tab-width</attribute>
+          <attribute name="target" type="u">3</attribute>
         </item>
         <item>
           <attribute name="label" translatable="yes">4</attribute>
+          <attribute name="action">editorui.tab-width</attribute>
+          <attribute name="target" type="u">4</attribute>
         </item>
         <item>
           <attribute name="label" translatable="yes">5</attribute>
+          <attribute name="action">editorui.tab-width</attribute>
+          <attribute name="target" type="u">5</attribute>
         </item>
         <item>
           <attribute name="label" translatable="yes">8</attribute>
+          <attribute name="action">editorui.tab-width</attribute>
+          <attribute name="target" type="u">8</attribute>
         </item>
       </submenu>
       <submenu id="editorui-indent-submenu">
         <attribute name="label" translatable="yes">Indentation Size</attribute>
-        <item>
-          <attribute name="label" translatable="yes">2</attribute>
-        </item>
-        <item>
-          <attribute name="label" translatable="yes">3</attribute>
-        </item>
-        <item>
-          <attribute name="label" translatable="yes">4</attribute>
-        </item>
-        <item>
-          <attribute name="label" translatable="yes">5</attribute>
-        </item>
-        <item>
-          <attribute name="label" translatable="yes">8</attribute>
-        </item>
+        <section id="indent-inherit-size-section">
+          <item>
+            <attribute name="label" translatable="yes">Same as Tab Width</attribute>
+            <attribute name="action">editorui.indent-width</attribute>
+            <attribute name="target" type="i">-1</attribute>
+          </item>
+        </section>
+        <section id="indent-common-sizes-section">
+          <item>
+            <attribute name="label" translatable="yes">2</attribute>
+            <attribute name="action">editorui.indent-width</attribute>
+            <attribute name="target" type="i">2</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">3</attribute>
+            <attribute name="action">editorui.indent-width</attribute>
+            <attribute name="target" type="i">3</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">4</attribute>
+            <attribute name="action">editorui.indent-width</attribute>
+            <attribute name="target" type="i">4</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">5</attribute>
+            <attribute name="action">editorui.indent-width</attribute>
+            <attribute name="target" type="i">5</attribute>
+          </item>
+          <item>
+            <attribute name="label" translatable="yes">8</attribute>
+            <attribute name="action">editorui.indent-width</attribute>
+            <attribute name="target" type="i">8</attribute>
+          </item>
+        </section>
       </submenu>
     </section>
   </menu>


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