[swell-foop/arnaudb/kill-preferences-dialog: 1/2] Create an Appearance submenu.



commit 9c8d88a19f0978d5de72680f5a69e2318354c7ce
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sat May 9 16:37:30 2020 +0200

    Create an Appearance submenu.

 data/ui/preferences.ui | 174 +------------------------------------------------
 data/ui/swell-foop.ui  |  25 +++++++
 src/swell-foop.vala    |  45 +------------
 src/window.vala        |  30 ++++++---
 4 files changed, 48 insertions(+), 226 deletions(-)
---
diff --git a/data/ui/preferences.ui b/data/ui/preferences.ui
index 6290b74..4104320 100644
--- a/data/ui/preferences.ui
+++ b/data/ui/preferences.ui
@@ -12,7 +12,7 @@
     <property name="border_width">5</property>
     <property name="use_header_bar">1</property>
     <!-- Translators: title of the Preferences dialog -->
-    <property name="title" translatable="yes">Preferences</property>
+    <property name="title" translatable="yes">Setup</property>
     <property name="icon_name">gnome-swell-foop</property>
     <child internal-child="vbox">
       <object class="GtkBox">
@@ -119,177 +119,13 @@
                     </child>
                   </object>
                 </child>
-                <child type="label">
-                  <object class="GtkLabel">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="margin_top">5</property>
-                    <property name="margin_bottom">5</property>
-                    <!-- Translators: in the Preferences dialog, name of the section in which there are 
settings for board size and number of colors -->
-                    <property name="label" translatable="yes">Setup</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                    </attributes>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkFrame">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label_xalign">0</property>
-                <property name="shadow_type">none</property>
-                <child>
-                  <object class="GtkAlignment">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="margin_start">12</property>
-                    <child>
-                      <object class="GtkBox">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="orientation">vertical</property>
-                        <child>
-                          <object class="GtkBox">
-                            <property name="visible">True</property>
-                            <property name="can_focus">False</property>
-                            <property name="spacing">6</property>
-                            <child>
-                              <object class="GtkLabel">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <!-- Translators: in the Preferences dialog, text of the label that 
introduces the combobox for choosing the theme -->
-                                <property name="label" translatable="yes">_Theme:</property>
-                                <property name="use_underline">True</property>
-                                <property name="mnemonic_widget">theme-selector</property>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">True</property>
-                                <property name="position">0</property>
-                              </packing>
-                            </child>
-                            <child>
-                              <object class="GtkComboBox" id="theme-selector">
-                                <property name="visible">True</property>
-                                <property name="can_focus">False</property>
-                                <property name="model">theme-model</property>
-                                <signal name="changed" handler="select_theme" swapped="no"/>
-                                <child>
-                                  <object class="GtkCellRendererText"/>
-                                  <attributes>
-                                    <attribute name="text">0</attribute>
-                                  </attributes>
-                                </child>
-                              </object>
-                              <packing>
-                                <property name="expand">False</property>
-                                <property name="fill">True</property>
-                                <property name="padding">8</property>
-                                <property name="position">1</property>
-                              </packing>
-                            </child>
-                          </object>
-                          <packing>
-                            <property name="expand">True</property>
-                            <property name="fill">True</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-                <child type="label">
-                  <object class="GtkLabel">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="margin_top">5</property>
-                    <property name="margin_bottom">5</property>
-                    <!-- Translators: in the Preferences dialog, name of the section in which there is the 
theme option -->
-                    <property name="label" translatable="yes">Appearance</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                    </attributes>
-                  </object>
-                </child>
               </object>
               <packing>
                 <property name="expand">False</property>
                 <property name="fill">True</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkFrame">
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-                <property name="label_xalign">0</property>
-                <property name="shadow_type">none</property>
-                <child>
-                  <object class="GtkAlignment">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="margin_start">12</property>
-                    <child>
-                      <object class="GtkBox">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="orientation">vertical</property>
-                        <child>
-                          <object class="GtkCheckButton" id="zealous-checkbox">
-                            <!-- Translators: in the Preferences dialog, text of the fast-animation checkbox 
-->
-                            <property name="label" translatable="yes">_Zealous Animation</property>
-                            <property name="use_action_appearance">False</property>
-                            <property name="visible">True</property>
-                            <property name="can_focus">True</property>
-                            <property name="receives_default">False</property>
-                            <property name="use_underline">True</property>
-                            <property name="draw_indicator">True</property>
-                            <signal name="toggled" handler="set_zealous_animation" swapped="no"/>
-                          </object>
-                          <packing>
-                            <property name="expand">True</property>
-                            <property name="fill">True</property>
-                            <property name="position">0</property>
-                          </packing>
-                        </child>
-                      </object>
-                    </child>
-                  </object>
-                </child>
-                <child type="label">
-                  <object class="GtkLabel">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="margin_top">5</property>
-                    <property name="margin_bottom">5</property>
-                    <!-- Translators: in the Preferences dialog, name of the section in which there is the 
fast-animation option -->
-                    <property name="label" translatable="yes">Operation</property>
-                    <attributes>
-                      <attribute name="weight" value="bold"/>
-                    </attributes>
-                  </object>
-                </child>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">True</property>
-                <property name="position">2</property>
               </packing>
             </child>
           </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
         </child>
       </object>
     </child>
@@ -302,12 +138,4 @@
       <column type="gchararray"/>
     </columns>
   </object>
-  <object class="GtkListStore" id="theme-model">
-    <columns>
-      <!-- column-name label -->
-      <column type="gchararray"/>
-      <!-- column-name id -->
-      <column type="gchararray"/>
-    </columns>
-  </object>
 </interface>
diff --git a/data/ui/swell-foop.ui b/data/ui/swell-foop.ui
index 87ff3e3..06b71fd 100644
--- a/data/ui/swell-foop.ui
+++ b/data/ui/swell-foop.ui
@@ -32,6 +32,31 @@
         <attribute name="label" translatable="yes">High _Scores</attribute>
         <attribute name="action">win.scores</attribute>
       </item>
+      <submenu>
+        <!-- Translators: submenu of the hamburger menu (with a mnemonic that appears when pressing Alt); 
allows to change the theme -->
+        <attribute name="label" translatable="yes">A_ppearance</attribute>
+        <section>
+          <item>
+            <!-- Translators: entry of the Appearance submenu of the hamburger menu (with a mnemonic that 
appears when pressing Alt); change theme; other possible theme is "_Shapes and Colors" -->
+            <attribute name="label" translatable="yes">_Colors</attribute>
+            <attribute name="action">win.change-theme</attribute>
+            <attribute name="target">colors</attribute>
+          </item>
+          <item>
+            <!-- Translators: entry of the Appearance submenu of the hamburger menu (with a mnemonic that 
appears when pressing Alt); change theme; other possible theme is "_Colors" -->
+            <attribute name="label" translatable="yes">_Shapes and Colors</attribute>
+            <attribute name="action">win.change-theme</attribute>
+            <attribute name="target">shapesandcolors</attribute>
+          </item>
+        </section>
+        <section>
+          <item>
+            <!-- Translators: entry of the Appearance submenu of the hamburger menu (with a mnemonic that 
appears when pressing Alt); makes animation faster -->
+            <attribute name="label" translatable="yes">_Zealous Animation</attribute>
+            <attribute name="action">win.zealous</attribute>
+          </item>
+        </section>
+      </submenu>
     </section>
     <section>
       <item>
diff --git a/src/swell-foop.vala b/src/swell-foop.vala
index 39c8c3f..945f4d2 100644
--- a/src/swell-foop.vala
+++ b/src/swell-foop.vala
@@ -95,24 +95,10 @@ public class SwellFoop : Gtk.Application
         preferences_dialog.transient_for = window;
         preferences_dialog.modal = true;
 
-        /* Theme */
-        var theme_combo = (Gtk.ComboBox) preferences_builder.get_object ("theme-selector");
-        var model = (Gtk.ListStore) theme_combo.model;
-        Gtk.TreeIter iter;
-        model.append (out iter);
-        /* Translators: name of a possible theme, as seen in the Preferences dialog “theme” combobox */
-        model.set (iter, 0, _("Colors"), 1, "colors", -1);
-        if (settings.get_string ("theme") == "colors")
-            theme_combo.set_active_iter (iter);
-        model.append (out iter);
-        /* Translators: name of a possible theme, as seen in the Preferences dialog “theme” combobox */
-        model.set (iter, 0, _("Shapes and Colors"), 1, "shapesandcolors", -1);
-        if (settings.get_string ("theme") == "shapesandcolors")
-            theme_combo.set_active_iter (iter);
-
         /* Board size */
         var size_combo = (Gtk.ComboBox) preferences_builder.get_object ("size-selector");
-        model = (Gtk.ListStore) size_combo.model;
+        var model = (Gtk.ListStore) size_combo.model;
+        Gtk.TreeIter iter;
         for (int i = 0; i < sizes.length; i++)
         {
             model.append (out iter);
@@ -124,38 +110,11 @@ public class SwellFoop : Gtk.Application
         /* Number of colors */
         ((Gtk.SpinButton) preferences_builder.get_object ("colors-spinner")).value = settings.get_int 
("colors");
 
-        /* Zealous moves */
-        ((Gtk.CheckButton) preferences_builder.get_object ("zealous-checkbox")).active = 
settings.get_boolean ("zealous");
-
         preferences_builder.connect_signals (this);
         preferences_dialog.response.connect (preferences_response_cb);
         preferences_dialog.present ();
     }
 
-    [CCode (cname = "G_MODULE_EXPORT select_theme", instance_pos = -1)]
-    public void select_theme (Gtk.ComboBox theme_combo)
-    {
-        Gtk.TreeIter iter;
-        if (!theme_combo.get_active_iter (out iter))
-            return;
-        string new_theme;
-        theme_combo.model.get (iter, 1, out new_theme, -1);
-
-        if (new_theme == settings.get_string ("theme"))
-            return;
-
-        settings.set_string ("theme", new_theme);
-
-        window.set_theme_name (new_theme);
-    }
-
-    [CCode (cname = "G_MODULE_EXPORT set_zealous_animation", instance_pos = -1)]
-    public void set_zealous_animation (Gtk.CheckButton button)
-    {
-        settings.set_boolean ("zealous", button.active);
-        window.set_is_zealous (settings.get_boolean ("zealous"));
-    }
-
     [CCode (cname = "G_MODULE_EXPORT update_size", instance_pos = -1)]
     public void update_size (Gtk.ComboBox size_combo)
     {
diff --git a/src/window.vala b/src/window.vala
index aabb6cf..74de345 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -41,6 +41,7 @@ private class SwellFoopWindow : ApplicationWindow
 
     private const GLib.ActionEntry[] win_actions =
     {
+        { "change-theme",       null,       "s", "'shapesandcolors'",   change_theme_cb },  // cannot be 
done via create_action as long as it’s an open form
         { "new-game",           new_game_cb         },
         { "scores",             scores_cb           },
         { "toggle-hamburger",   toggle_hamburger    }
@@ -50,6 +51,15 @@ private class SwellFoopWindow : ApplicationWindow
     {
         add_action_entries (win_actions, this);
 
+        add_action (settings.create_action ("zealous"));
+        settings.changed ["zealous"].connect ((_settings, _key_name) => { view.is_zealous = 
_settings.get_boolean (_key_name); });
+
+        string theme = settings.get_string ("theme");
+        if (theme != "colors" && theme != "shapesandcolors")
+            theme = "shapesandcolors";
+        SimpleAction theme_action = (SimpleAction) lookup_action ("change-theme");
+        theme_action.set_state (new Variant.@string (theme));
+
         add_events (Gdk.EventMask.KEY_PRESS_MASK | Gdk.EventMask.KEY_RELEASE_MASK);
 
         init_scores ();
@@ -194,16 +204,6 @@ private class SwellFoopWindow : ApplicationWindow
         update_score_cb (0);
     }
 
-    internal inline void set_theme_name (string new_theme)
-    {
-        view.theme_name = new_theme;
-    }
-
-    internal inline void set_is_zealous (bool is_zealous)
-    {
-        view.is_zealous = is_zealous;
-    }
-
     private bool being_destroyed = false;
     protected override void destroy ()
     {
@@ -218,6 +218,16 @@ private class SwellFoopWindow : ApplicationWindow
     * * actions
     \*/
 
+    private inline void change_theme_cb (SimpleAction action, Variant? variant)
+        requires (variant != null)
+    {
+        string new_theme = ((!) variant).get_string ();
+        action.set_state ((!) variant);
+        view.theme_name = new_theme;
+        if (settings.get_string ("theme") != new_theme)
+            settings.set_string ("theme", new_theme);
+    }
+
     private inline void scores_cb (/* SimpleAction action, Variant? variant */)
     {
         scores_context.run_dialog ();


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