[four-in-a-row] Move theme choice in hamburger menu.



commit ba8fcd2b91d2c000a02967e3367d4a7d9616af98
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Tue Aug 20 13:36:24 2019 +0200

    Move theme choice in hamburger menu.
    
    More work is needed,
    notably for adding a
    default theme that'd
    depend on GTK theme.

 data/org.gnome.Four-in-a-row.gschema.xml |  1 +
 src/four-in-a-row.vala                   | 11 +++++++++++
 src/prefs-box.vala                       | 28 +---------------------------
 src/theme.vala                           |  2 +-
 4 files changed, 14 insertions(+), 28 deletions(-)
---
diff --git a/data/org.gnome.Four-in-a-row.gschema.xml b/data/org.gnome.Four-in-a-row.gschema.xml
index 7db6906..ee5e69e 100644
--- a/data/org.gnome.Four-in-a-row.gschema.xml
+++ b/data/org.gnome.Four-in-a-row.gschema.xml
@@ -7,6 +7,7 @@
     </key>
     <key name="theme-id" type="i">
       <default>4</default>
+      <range min="0" max="4"/>
       <summary>Theme ID</summary>
       <description>A number specifying the preferred theme.</description>
     </key>
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index 5f8ee31..7957786 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -160,6 +160,7 @@ private class FourInARow : Gtk.Application {
 
     private inline void add_actions() {
         add_action (Prefs.instance.settings.create_action ("sound"));
+        add_action (Prefs.instance.settings.create_action ("theme-id"));
 
         new_game_action = new SimpleAction("new-game", null);
         new_game_action.activate.connect(this.on_game_new);
@@ -714,7 +715,16 @@ private class FourInARow : Gtk.Application {
         menu_button = builder.get_object ("menu_button") as Gtk.MenuButton;
         app_menu = new GLib.Menu ();
 
+        GLib.Menu appearance_menu = new GLib.Menu ();
+        for (uint8 i = 0; i < theme.length; i++)     // TODO default theme
+            appearance_menu.append (theme_get_title (i), @"app.theme-id($i)");
+        appearance_menu.freeze ();
+
         section = new GLib.Menu ();
+        /* Translators: hamburger menu entry; "Appearance" submenu (with a mnemonic that appears pressing 
Alt) */
+        section.append_submenu (_("A_ppearance"), (!) appearance_menu);
+
+
         section.append (_("Sound"), "app.sound");
         section.freeze ();
         app_menu.append_section (null, section);
@@ -731,6 +741,7 @@ private class FourInARow : Gtk.Application {
         section.freeze ();
         app_menu.append_section (null, section);
 
+        app_menu.freeze ();
         menu_button.set_menu_model (app_menu);
 
         frame = builder.get_object("frame") as Gtk.AspectFrame;
diff --git a/src/prefs-box.vala b/src/prefs-box.vala
index e12b3a5..b719860 100644
--- a/src/prefs-box.vala
+++ b/src/prefs-box.vala
@@ -29,7 +29,6 @@ private class PrefsBox : Dialog {
     internal PrefsBox(Window parent) {
         Notebook notebook;
         ComboBox combobox;
-        ComboBoxText combobox_theme;
 
         Grid grid;
         GamesControlsList controls_list;
@@ -59,7 +58,7 @@ private class PrefsBox : Dialog {
         label = new Label(_("Game"));
         notebook.append_page(grid, label);
 
-        label = new Label(_("Opponent:"));  // TODO add a mnemonic, like for _Theme:
+        label = new Label(_("Opponent:"));  // TODO add a mnemonic?
         label.set_xalign((float)0.0);
         label.set_yalign((float)0.5);
         label.set_hexpand(true);
@@ -91,19 +90,6 @@ private class PrefsBox : Dialog {
         combobox.changed.connect(on_select_opponent);
         grid.attach(combobox, 1, 0, 1, 1);
 
-        label = new Label.with_mnemonic(_("_Theme:"));
-        label.set_xalign((float)0.0);
-        label.set_yalign((float)0.5);
-        label.set_hexpand(true);
-        grid.attach(label, 0, 1, 1, 1);
-
-        combobox_theme = new ComboBoxText();
-        for (int i = 0; i < theme.length; i++) {
-            combobox_theme.append_text(_(theme_get_title(i)));
-        }
-        label.set_mnemonic_widget(combobox_theme);
-        grid.attach(combobox_theme, 1, 1, 1, 1);
-
         /* keyboard tab */
         label = new Label.with_mnemonic(_("Keyboard Controls"));
 
@@ -113,13 +99,6 @@ private class PrefsBox : Dialog {
                                    "key-drop",  _("Drop marble"),   DEFAULT_KEY_DROP);
         controls_list.border_width = 12;
         notebook.append_page(controls_list, label);
-
-        /* fill in initial values */
-        combobox_theme.set_active(Prefs.instance.theme_id);
-
-        /* connect signals */
-        combobox_theme.changed.connect(on_select_theme);
-        Prefs.instance.theme_changed.connect((theme_id) => combobox_theme.set_active(theme_id));
     }
 
     protected override bool delete_event(Gdk.EventAny event) {  // TODO use hide_on_delete (Gtk3) or 
hide-on-close (Gtk4) 2/2
@@ -127,11 +106,6 @@ private class PrefsBox : Dialog {
         return true;
     }
 
-    private static inline void on_select_theme(ComboBox combobox) {
-        int id = combobox.get_active();
-        Prefs.instance.theme_id = id;
-    }
-
     private inline void on_select_opponent(ComboBox combobox) {
         FourInARow app = (FourInARow)application;
         TreeIter iter;
diff --git a/src/theme.vala b/src/theme.vala
index da3f270..e91b5be 100644
--- a/src/theme.vala
+++ b/src/theme.vala
@@ -40,7 +40,7 @@ private struct Theme {
 private const string theme_gettext_package = GETTEXT_PACKAGE;
 
 private static string theme_get_title(int id) {
-    return theme[id].title;
+    return _(theme [id].title); // FIXME this gettext call feels horrible
 }
 
 private static string theme_get_player_turn(PlayerID who) {


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