[gnome-builder] plugins/editorui: use radio for space settings



commit 070a997a797b12ad67e5087d7ba55a3f33c4c4b1
Author: Christian Hergert <chergert redhat com>
Date:   Fri Aug 26 14:33:23 2022 -0700

    plugins/editorui: use radio for space settings
    
    We no longer need to use custom code for this, as the radio tweaks can
    handle the strv/flags type situation correctly.

 src/plugins/editorui/gbp-editorui-tweaks-addin.c | 80 ------------------------
 src/plugins/editorui/tweaks-language.ui          | 58 ++++++++++++++++-
 2 files changed, 56 insertions(+), 82 deletions(-)
---
diff --git a/src/plugins/editorui/gbp-editorui-tweaks-addin.c 
b/src/plugins/editorui/gbp-editorui-tweaks-addin.c
index 2c759239a..4c721fd86 100644
--- a/src/plugins/editorui/gbp-editorui-tweaks-addin.c
+++ b/src/plugins/editorui/gbp-editorui-tweaks-addin.c
@@ -84,85 +84,6 @@ create_language_caption (IdeTweaks       *tweaks,
                        NULL);
 }
 
-static GtkWidget *
-create_spaces_style (IdeTweaks       *tweaks,
-                     IdeTweaksWidget *widget,
-                     IdeTweaksWidget *instance)
-{
-  static const struct {
-    const char *nick;
-    const char *title;
-  } flags[] = {
-    { "before-left-paren", N_("Space before opening parentheses") },
-    { "before-left-bracket", N_("Space before opening brackets") },
-    { "before-left-brace", N_("Space before opening braces") },
-    { "before-left-angle", N_("Space before opening angles") },
-    { "before-colon", N_("Prefer a space before colon") },
-    { "before-comma", N_("Prefer a space before commas") },
-    { "before-semicolon", N_("Prefer a space before semicolons") },
-  };
-  IdeTweaksItem *page;
-  IdeTweaksSettings *found_settings = NULL;
-  g_autoptr(GSimpleActionGroup) group = NULL;
-  GtkListBox *list_box;
-
-  list_box = g_object_new (GTK_TYPE_LIST_BOX,
-                           "css-classes", IDE_STRV_INIT ("boxed-list"),
-                           "selection-mode", GTK_SELECTION_NONE,
-                           NULL);
-  group = g_simple_action_group_new ();
-  gtk_widget_insert_action_group (GTK_WIDGET (list_box),
-                                  "spaces-style",
-                                  G_ACTION_GROUP (group));
-  page = ide_tweaks_item_get_ancestor (IDE_TWEAKS_ITEM (widget), IDE_TYPE_TWEAKS_PAGE);
-
-  for (IdeTweaksItem *child = ide_tweaks_item_get_first_child (page);
-       child != NULL;
-       child = ide_tweaks_item_get_next_sibling (child))
-    {
-      if (IDE_IS_TWEAKS_SETTINGS (child))
-        {
-          IdeTweaksSettings *settings = IDE_TWEAKS_SETTINGS (child);
-
-          if (ide_str_equal0 ("org.gnome.builder.editor.language",
-                              ide_tweaks_settings_get_schema_id (settings)))
-            {
-              found_settings = settings;
-              break;
-            }
-        }
-    }
-
-  for (guint i = 0; i < G_N_ELEMENTS (flags); i++)
-    {
-      g_autoptr(IdeSettingsFlagAction) action = NULL;
-      const char *schema_id = ide_tweaks_settings_get_schema_id (found_settings);
-      const char *schema_path = ide_tweaks_settings_get_schema_path (found_settings);
-      g_autofree char *action_name = g_strdup_printf ("spaces-style.%s", flags[i].nick);
-      GtkCheckButton *button = NULL;
-      AdwActionRow *row;
-
-      action = ide_settings_flag_action_new (schema_id, "spaces-style", schema_path, flags[i].nick);
-      g_action_map_add_action (G_ACTION_MAP (group), G_ACTION (action));
-
-      button = g_object_new (GTK_TYPE_CHECK_BUTTON,
-                             "action-name", action_name,
-                             "can-target", FALSE,
-                             "valign", GTK_ALIGN_CENTER,
-                             NULL);
-      gtk_widget_add_css_class (GTK_WIDGET (button), "checkimage");
-
-      row = g_object_new (ADW_TYPE_ACTION_ROW,
-                          "title", g_dgettext (GETTEXT_PACKAGE, flags[i].title),
-                          "activatable-widget", button,
-                          NULL);
-      adw_action_row_add_suffix (row, GTK_WIDGET (button));
-      gtk_list_box_append (list_box, GTK_WIDGET (row));
-    }
-
-  return GTK_WIDGET (list_box);
-}
-
 static int
 compare_by_section (gconstpointer a,
                     gconstpointer b,
@@ -206,7 +127,6 @@ gbp_editorui_tweaks_addin_load (IdeTweaksAddin *addin,
   ide_tweaks_addin_bind_callback (IDE_TWEAKS_ADDIN (self), editorui_create_style_scheme_preview);
   ide_tweaks_addin_bind_callback (IDE_TWEAKS_ADDIN (self), editorui_create_style_scheme_selector);
   ide_tweaks_addin_bind_callback (IDE_TWEAKS_ADDIN (self), create_language_caption);
-  ide_tweaks_addin_bind_callback (IDE_TWEAKS_ADDIN (self), create_spaces_style);
   ide_tweaks_expose_object (tweaks, "GtkSourceLanguages", G_OBJECT (store));
 
   IDE_TWEAKS_ADDIN_CLASS (gbp_editorui_tweaks_addin_parent_class)->load (addin, tweaks);
diff --git a/src/plugins/editorui/tweaks-language.ui b/src/plugins/editorui/tweaks-language.ui
index 99a922177..1680544cf 100644
--- a/src/plugins/editorui/tweaks-language.ui
+++ b/src/plugins/editorui/tweaks-language.ui
@@ -194,8 +194,62 @@
                           <object class="IdeTweaksGroup" id="language_spaces_style_group">
                             <property name="title" translatable="yes">Spaces</property>
                             <child>
-                              <object class="IdeTweaksWidget">
-                                <signal name="create-for-item" handler="create_spaces_style" swapped="true" 
object="IdeTweaks"/>
+                              <object class="IdeTweaksRadio">
+                                <property name="title" translatable="yes">Space before opening 
parentheses</property>
+                                <property name="value">'before-left-paren'</property>
+                                <property name="binding">
+                                  <object class="IdeTweaksSetting" id="language_spaces_style_setting">
+                                    <property name="schema-id">org.gnome.builder.editor.language</property>
+                                    <property name="schema-key">spaces-style</property>
+                                    <binding name="path-suffix">
+                                      <lookup name="id" type="GtkSourceLanguage">
+                                        <lookup name="item">language_page_factory</lookup>
+                                      </lookup>
+                                    </binding>
+                                  </object>
+                                </property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="IdeTweaksRadio">
+                                <property name="title" translatable="yes">Space before opening 
brackets</property>
+                                <property name="value">'before-left-bracket'</property>
+                                <property name="binding">language_spaces_style_setting</property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="IdeTweaksRadio">
+                                <property name="title" translatable="yes">Space before opening 
braces</property>
+                                <property name="value">'before-left-brace'</property>
+                                <property name="binding">language_spaces_style_setting</property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="IdeTweaksRadio">
+                                <property name="title" translatable="yes">Space before opening 
angles</property>
+                                <property name="value">'before-left-angle'</property>
+                                <property name="binding">language_spaces_style_setting</property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="IdeTweaksRadio">
+                                <property name="title" translatable="yes">Prefer a space before 
colon</property>
+                                <property name="value">'before-colon'</property>
+                                <property name="binding">language_spaces_style_setting</property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="IdeTweaksRadio">
+                                <property name="title" translatable="yes">Prefer a space before 
commas</property>
+                                <property name="value">'before-comma'</property>
+                                <property name="binding">language_spaces_style_setting</property>
+                              </object>
+                            </child>
+                            <child>
+                              <object class="IdeTweaksRadio">
+                                <property name="title" translatable="yes">Prefer a space before 
simicolons</property>
+                                <property name="value">'before-semicolon'</property>
+                                <property name="binding">language_spaces_style_setting</property>
                               </object>
                             </child>
                           </object>


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