[gnome-nibbles/arnaudb/kill-preferences-dialog: 9/27] Rework Preferences dialog.



commit ef57c30866a5dad8172a99d42288a729a30f9c03
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Jun 3 12:44:45 2020 +0200

    Rework Preferences dialog.

 data/preferences-dialog.ui  | 498 +++++++++++++++++++-------------------------
 src/nibbles-window.vala     |  28 +--
 src/preferences-dialog.vala |  62 ++++--
 3 files changed, 259 insertions(+), 329 deletions(-)
---
diff --git a/data/preferences-dialog.ui b/data/preferences-dialog.ui
index 6319960..5b9eb40 100644
--- a/data/preferences-dialog.ui
+++ b/data/preferences-dialog.ui
@@ -3,6 +3,7 @@
    This file is part of GNOME Nibbles.
 
    Copyright (C) 2015 Gabriel Ivascu
+   Copyright (C) 2020 Arnaud Bonatti
 
    GNOME Nibbles is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -18,32 +19,82 @@
    with this GNOME Nibbles.  If not, see <https://www.gnu.org/licenses/>.
 -->
 <interface>
-  <template class="PreferencesDialog" parent="GtkDialog">
+  <object class="GtkComboBoxText" id="worm_combobox">
+    <property name="visible">True</property>
+    <property name="active-id">worm1</property>
+    <items>
+      <item translatable="yes" id="worm1">Worm 1</item>
+      <item translatable="yes" id="worm2">Worm 2</item>
+      <item translatable="yes" id="worm3">Worm 3</item>
+      <item translatable="yes" id="worm4">Worm 4</item>
+    </items>
+    <signal name="changed" handler="on_worm_change"/>
+  </object>
+  <template class="PreferencesDialog" parent="GtkWindow">
     <property name="can_focus">False</property>
     <property name="border_width">5</property>
     <property name="modal">True</property>
-    <property name="title" translatable="yes">Preferences</property>
     <property name="icon_name">gnome-nibbles</property>
-    <child internal-child="vbox">
-      <object class="GtkBox">
+    <child type="titlebar">
+      <object class="GtkHeaderBar">
+        <property name="visible">True</property>
+        <property name="show-close-button">True</property>
+        <property name="custom-title">worm_combobox</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkStack" id="stack">
         <property name="visible">True</property>
-        <property name="orientation">vertical</property>
-        <property name="can_focus">False</property>
-        <property name="spacing">2</property>
         <child>
-          <object class="GtkNotebook" id="notebook">
+          <object class="GtkBox">
             <property name="visible">True</property>
-            <property name="can_focus">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">12</property>
+            <property name="spacing">6</property>
+            <property name="orientation">vertical</property>
             <child>
-              <object class="GtkBox">
+              <object class="GtkLabel">
+                <property name="label" translatable="yes">Controls</property>
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="border_width">12</property>
-                <property name="spacing">6</property>
-                <property name="orientation">vertical</property>
+                <property name="xalign">0.5</property>
+                <property name="yalign">0.5</property>
+                <property name="halign">start</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+            </child>
+            <child>
+              <object class="GtkListStore" id="list_store_1">
+                <columns>
+                  <column type="gchararray"/>
+                  <column type="gchararray"/>
+                  <column type="gint"/>
+                </columns>
+              </object>
+              <object class="GtkTreeView" id="tree_view_1">
+                <property name="model">list_store_1</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkSeparator">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="orientation">horizontal</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkGrid">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="row_spacing">0</property>
+                <property name="column_spacing">12</property>
+                <property name="border_width">0</property>
                 <child>
                   <object class="GtkLabel">
-                    <property name="label" translatable="yes">Controls</property>
+                    <property name="label" translatable="yes">Worm color</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0.5</property>
@@ -53,92 +104,71 @@
                       <attribute name="weight" value="bold"/>
                     </attributes>
                   </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkListStore" id="list_store_1">
-                    <columns>
-                      <column type="gchararray"/>
-                      <column type="gchararray"/>
-                      <column type="gint"/>
-                    </columns>
-                  </object>
-                  <object class="GtkTreeView" id="tree_view_1">
-                    <property name="model">list_store_1</property>
-                    <property name="visible">True</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkSeparator">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="orientation">horizontal</property>
-                  </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
                 </child>
                 <child>
-                  <object class="GtkGrid">
+                  <object class="GtkComboBoxText" id="combo_box_1">
                     <property name="visible">True</property>
+                    <property name="hexpand">True</property>
                     <property name="can_focus">False</property>
-                    <property name="row_spacing">0</property>
-                    <property name="column_spacing">12</property>
-                    <property name="border_width">0</property>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="label" translatable="yes">Worm color</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0.5</property>
-                        <property name="yalign">0.5</property>
-                        <property name="halign">start</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                      <packing>
-                        <property name="left-attach">0</property>
-                        <property name="top-attach">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkComboBoxText" id="combo_box_1">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </object>
-                      <packing>
-                        <property name="left-attach">1</property>
-                        <property name="top-attach">0</property>
-                      </packing>
-                    </child>
                   </object>
                 </child>
               </object>
             </child>
-            <child type="tab">
+          </object>
+          <packing>
+            <property name="name">worm1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">12</property>
+            <property name="spacing">6</property>
+            <property name="orientation">vertical</property>
+            <child>
               <object class="GtkLabel">
-                <property name="use-underline">True</property>
-                <property name="label" translatable="yes">Worm _1</property>
+                <property name="label" translatable="yes">Controls</property>
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="xalign">0.5</property>
+                <property name="yalign">0.5</property>
+                <property name="halign">start</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
               </object>
-              <packing>
-                <property name="tab_fill">False</property>
-              </packing>
             </child>
             <child>
-              <object class="GtkBox">
+              <object class="GtkListStore" id="list_store_2">
+                <columns>
+                  <column type="gchararray"/>
+                  <column type="gchararray"/>
+                  <column type="guint"/>
+                </columns>
+              </object>
+              <object class="GtkTreeView" id="tree_view_2">
+                <property name="model">list_store_2</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkSeparator">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="border_width">12</property>
-                <property name="spacing">6</property>
-                <property name="orientation">vertical</property>
+                <property name="orientation">horizontal</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkGrid">
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="row_spacing">0</property>
+                <property name="column_spacing">12</property>
+                <property name="border_width">0</property>
                 <child>
                   <object class="GtkLabel">
-                    <property name="label" translatable="yes">Controls</property>
+                    <property name="label" translatable="yes">Worm color</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0.5</property>
@@ -148,92 +178,71 @@
                       <attribute name="weight" value="bold"/>
                     </attributes>
                   </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkListStore" id="list_store_2">
-                    <columns>
-                      <column type="gchararray"/>
-                      <column type="gchararray"/>
-                      <column type="guint"/>
-                    </columns>
-                  </object>
-                  <object class="GtkTreeView" id="tree_view_2">
-                    <property name="model">list_store_2</property>
-                    <property name="visible">True</property>
-                  </object>
                 </child>
                 <child>
-                  <object class="GtkSeparator">
+                  <object class="GtkComboBoxText" id="combo_box_2">
                     <property name="visible">True</property>
+                    <property name="hexpand">True</property>
                     <property name="can_focus">False</property>
-                    <property name="orientation">horizontal</property>
-                  </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkGrid">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="row_spacing">0</property>
-                    <property name="column_spacing">12</property>
-                    <property name="border_width">0</property>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="label" translatable="yes">Worm color</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0.5</property>
-                        <property name="yalign">0.5</property>
-                        <property name="halign">start</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                      <packing>
-                        <property name="left-attach">0</property>
-                        <property name="top-attach">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkComboBoxText" id="combo_box_2">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </object>
-                      <packing>
-                        <property name="left-attach">1</property>
-                        <property name="top-attach">0</property>
-                      </packing>
-                    </child>
                   </object>
                 </child>
               </object>
             </child>
-            <child type="tab">
+          </object>
+          <packing>
+            <property name="name">worm2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">12</property>
+            <property name="spacing">6</property>
+            <property name="orientation">vertical</property>
+            <child>
               <object class="GtkLabel">
-                <property name="use-underline">True</property>
-                <property name="label" translatable="yes">Worm _2</property>
+                <property name="label" translatable="yes">Controls</property>
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0.5</property>
+                <property name="yalign">0.5</property>
+                <property name="halign">start</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+            </child>
+            <child>
+              <object class="GtkListStore" id="list_store_3">
+                <columns>
+                  <column type="gchararray"/>
+                  <column type="gchararray"/>
+                  <column type="guint"/>
+                </columns>
+              </object>
+              <object class="GtkTreeView" id="tree_view_3">
+                <property name="model">list_store_3</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkSeparator">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="orientation">horizontal</property>
               </object>
-              <packing>
-                <property name="tab_fill">False</property>
-              </packing>
             </child>
             <child>
-              <object class="GtkBox">
+              <object class="GtkGrid">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="border_width">12</property>
-                <property name="spacing">6</property>
-                <property name="orientation">vertical</property>
+                <property name="row_spacing">0</property>
+                <property name="column_spacing">12</property>
+                <property name="border_width">0</property>
                 <child>
                   <object class="GtkLabel">
-                    <property name="label" translatable="yes">Controls</property>
+                    <property name="label" translatable="yes">Worm color</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0.5</property>
@@ -243,92 +252,71 @@
                       <attribute name="weight" value="bold"/>
                     </attributes>
                   </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
                 </child>
                 <child>
-                  <object class="GtkListStore" id="list_store_3">
-                    <columns>
-                      <column type="gchararray"/>
-                      <column type="gchararray"/>
-                      <column type="guint"/>
-                    </columns>
-                  </object>
-                  <object class="GtkTreeView" id="tree_view_3">
-                    <property name="model">list_store_3</property>
-                    <property name="visible">True</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkSeparator">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="orientation">horizontal</property>
-                  </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkGrid">
+                  <object class="GtkComboBoxText" id="combo_box_3">
                     <property name="visible">True</property>
+                    <property name="hexpand">True</property>
                     <property name="can_focus">False</property>
-                    <property name="row_spacing">0</property>
-                    <property name="column_spacing">12</property>
-                    <property name="border_width">0</property>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="label" translatable="yes">Worm color</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0.5</property>
-                        <property name="yalign">0.5</property>
-                        <property name="halign">start</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                      <packing>
-                        <property name="left-attach">0</property>
-                        <property name="top-attach">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkComboBoxText" id="combo_box_3">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </object>
-                      <packing>
-                        <property name="left-attach">1</property>
-                        <property name="top-attach">0</property>
-                      </packing>
-                    </child>
                   </object>
                 </child>
               </object>
             </child>
-            <child type="tab">
+          </object>
+          <packing>
+            <property name="name">worm3</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkBox">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="border_width">12</property>
+            <property name="spacing">6</property>
+            <property name="orientation">vertical</property>
+            <child>
               <object class="GtkLabel">
-                <property name="use-underline">True</property>
-                <property name="label" translatable="yes">Worm _3</property>
+                <property name="label" translatable="yes">Controls</property>
+                <property name="visible">True</property>
+                <property name="can_focus">False</property>
+                <property name="xalign">0.5</property>
+                <property name="yalign">0.5</property>
+                <property name="halign">start</property>
+                <attributes>
+                  <attribute name="weight" value="bold"/>
+                </attributes>
+              </object>
+            </child>
+            <child>
+              <object class="GtkListStore" id="list_store_4">
+                <columns>
+                  <column type="gchararray"/>
+                  <column type="gchararray"/>
+                  <column type="guint"/>
+                </columns>
+              </object>
+              <object class="GtkTreeView" id="tree_view_4">
+                <property name="model">list_store_4</property>
+                <property name="visible">True</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkSeparator">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
+                <property name="orientation">horizontal</property>
               </object>
-              <packing>
-                <property name="tab_fill">False</property>
-              </packing>
             </child>
             <child>
-              <object class="GtkBox">
+              <object class="GtkGrid">
                 <property name="visible">True</property>
                 <property name="can_focus">False</property>
-                <property name="border_width">12</property>
-                <property name="spacing">6</property>
-                <property name="orientation">vertical</property>
+                <property name="row_spacing">0</property>
+                <property name="column_spacing">12</property>
+                <property name="border_width">0</property>
                 <child>
                   <object class="GtkLabel">
-                    <property name="label" translatable="yes">Controls</property>
+                    <property name="label" translatable="yes">Worm color</property>
                     <property name="visible">True</property>
                     <property name="can_focus">False</property>
                     <property name="xalign">0.5</property>
@@ -338,87 +326,19 @@
                       <attribute name="weight" value="bold"/>
                     </attributes>
                   </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
-                </child>
-                <child>
-                  <object class="GtkListStore" id="list_store_4">
-                    <columns>
-                      <column type="gchararray"/>
-                      <column type="gchararray"/>
-                      <column type="guint"/>
-                    </columns>
-                  </object>
-                  <object class="GtkTreeView" id="tree_view_4">
-                    <property name="model">list_store_4</property>
-                    <property name="visible">True</property>
-                  </object>
-                </child>
-                <child>
-                  <object class="GtkSeparator">
-                    <property name="visible">True</property>
-                    <property name="can_focus">False</property>
-                    <property name="orientation">horizontal</property>
-                  </object>
-                  <packing>
-                    <property name="pack-type">start</property>
-                  </packing>
                 </child>
                 <child>
-                  <object class="GtkGrid">
+                  <object class="GtkComboBoxText" id="combo_box_4">
                     <property name="visible">True</property>
+                    <property name="hexpand">True</property>
                     <property name="can_focus">False</property>
-                    <property name="row_spacing">0</property>
-                    <property name="column_spacing">12</property>
-                    <property name="border_width">0</property>
-                    <child>
-                      <object class="GtkLabel">
-                        <property name="label" translatable="yes">Worm color</property>
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                        <property name="xalign">0.5</property>
-                        <property name="yalign">0.5</property>
-                        <property name="halign">start</property>
-                        <attributes>
-                          <attribute name="weight" value="bold"/>
-                        </attributes>
-                      </object>
-                      <packing>
-                        <property name="left-attach">0</property>
-                        <property name="top-attach">0</property>
-                      </packing>
-                    </child>
-                    <child>
-                      <object class="GtkComboBoxText" id="combo_box_4">
-                        <property name="visible">True</property>
-                        <property name="can_focus">False</property>
-                      </object>
-                      <packing>
-                        <property name="left-attach">1</property>
-                        <property name="top-attach">0</property>
-                      </packing>
-                    </child>
                   </object>
                 </child>
               </object>
             </child>
-            <child type="tab">
-              <object class="GtkLabel">
-                <property name="use-underline">True</property>
-                <property name="label" translatable="yes">Worm _4</property>
-                <property name="visible">True</property>
-                <property name="can_focus">False</property>
-              </object>
-              <packing>
-                <property name="tab_fill">False</property>
-              </packing>
-            </child>
           </object>
           <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-            <property name="position">2</property>
+            <property name="name">worm4</property>
           </packing>
         </child>
       </object>
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 0283d61..4d5d3fc 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -51,9 +51,6 @@ private class NibblesWindow : ApplicationWindow
     [GtkChild] private Scoreboard scoreboard;
     private Gdk.Pixbuf scoreboard_life;
 
-    /* Preferences dialog */
-    private PreferencesDialog preferences_dialog = null;
-
     /* Rendering of the game */
     private NibblesView? view;
 
@@ -776,27 +773,22 @@ private class NibblesWindow : ApplicationWindow
             pause_action.activate (null);
             should_unpause = true;
         }
-
-        if (preferences_dialog != null)
+        else if (countdown_id != 0)
         {
-            preferences_dialog.present ();
-
-            if (should_unpause)
-                pause_action.activate (null);
-
-            return;
+            Source.remove (countdown_id);
+            countdown_id = 0;
         }
 
-        preferences_dialog = new PreferencesDialog (this, settings, worm_settings);
+        PreferencesDialog preferences_dialog = new PreferencesDialog (this, settings, worm_settings);
 
         preferences_dialog.destroy.connect (() => {
-            preferences_dialog = null;
-
-            if (should_unpause)
-                pause_action.activate (null);
-        });
+                if (should_unpause)
+                    pause_action.activate (null);
+                else if (seconds != 0)
+                    countdown_id = Timeout.add_seconds (1, countdown_cb);
+            });
 
-        preferences_dialog.run ();
+        preferences_dialog.present ();
     }
 
     private void game_over (int score, long lowest_high_score, int level_reached)
diff --git a/src/preferences-dialog.vala b/src/preferences-dialog.vala
index 85838eb..ff91f9a 100644
--- a/src/preferences-dialog.vala
+++ b/src/preferences-dialog.vala
@@ -19,14 +19,15 @@
 using Gtk;
 
 [GtkTemplate (ui = "/org/gnome/nibbles/ui/preferences-dialog.ui")]
-private class PreferencesDialog : Dialog
+private class PreferencesDialog : Window
 {
     private ApplicationWindow window;
 
     private GLib.Settings settings;
     private Gee.ArrayList<GLib.Settings> worm_settings;
 
-    [GtkChild] private Notebook         notebook;
+    [GtkChild] private Stack            stack;
+    [GtkChild] private ComboBoxText     worm_combobox;
     [GtkChild] private Gtk.ListStore    list_store_1;
     [GtkChild] private Gtk.ListStore    list_store_2;
     [GtkChild] private Gtk.ListStore    list_store_3;
@@ -44,19 +45,13 @@ private class PreferencesDialog : Dialog
     private Gee.ArrayList<TreeView>         tree_views;
     private Gee.ArrayList<ComboBoxText>     combo_boxes;
 
-    internal PreferencesDialog (ApplicationWindow window, GLib.Settings settings, 
Gee.ArrayList<GLib.Settings> worm_settings)
-    {
-        Object (use_header_bar: 1);
-
-        this.settings = settings;
-        this.worm_settings = worm_settings;
-        this.window = window;
-
-        this.delete_event.connect (hide_on_delete);
+    private EventControllerKey key_controller;          // for keeping in memory
 
-        this.set_transient_for (window);
+    construct
+    {
+        key_controller = new EventControllerKey (this);
+        key_controller.key_pressed.connect (on_key_pressed);
 
-        /* Control keys */
         tree_views = new Gee.ArrayList<TreeView> ();
         tree_views.add (tree_view_1);
         tree_views.add (tree_view_2);
@@ -69,6 +64,22 @@ private class PreferencesDialog : Dialog
         list_stores.add (list_store_3);
         list_stores.add (list_store_4);
 
+        combo_boxes = new Gee.ArrayList<ComboBoxText> ();
+        combo_boxes.add (combo_box_1);
+        combo_boxes.add (combo_box_2);
+        combo_boxes.add (combo_box_3);
+        combo_boxes.add (combo_box_4);
+    }
+
+    internal PreferencesDialog (ApplicationWindow window, GLib.Settings settings, 
Gee.ArrayList<GLib.Settings> worm_settings)
+    {
+        Object (transient_for: window);
+
+        this.settings = settings;
+        this.worm_settings = worm_settings;
+        this.window = window;
+
+        /* Control keys */
         foreach (var list_store in list_stores)
         {
             var id = list_stores.index_of (list_store);
@@ -103,16 +114,9 @@ private class PreferencesDialog : Dialog
             key_renderer.accel_cleared.connect (accel_cleared_cb);
             /* Translators: in the Preferences dialog, label of a column in a table for changing the keys to 
move the given worm (available for each playable worm); are listed there all the keys a player can use with 
its worm; the other column is "Action" */
             tree_view.insert_column_with_attributes (-1, _("Key"), key_renderer, "accel-key", 2);
-
         }
 
         /* Worm color */
-        combo_boxes = new Gee.ArrayList<ComboBoxText> ();
-        combo_boxes.add (combo_box_1);
-        combo_boxes.add (combo_box_2);
-        combo_boxes.add (combo_box_3);
-        combo_boxes.add (combo_box_4);
-
         foreach (var combo_box in combo_boxes)
         {
             for (int i = 0; i < NibblesView.NUM_COLORS; i++)
@@ -126,6 +130,20 @@ private class PreferencesDialog : Dialog
         }
     }
 
+    private inline bool on_key_pressed (EventControllerKey _key_controller, uint keyval, uint keycode, 
Gdk.ModifierType state)
+    {
+        string name = (!) (Gdk.keyval_name (keyval) ?? "");
+        if (name == "Escape")
+            destroy ();
+        return false;
+    }
+
+    [GtkCallback]
+    private inline void on_worm_change (ComboBox _worm_combobox)
+    {
+        stack.set_visible_child_name (((ComboBoxText) _worm_combobox).get_active_id ());
+    }
+
     private void accel_edited_cb (CellRendererAccel cell, string path_string, uint keyval,
                                   Gdk.ModifierType mask, uint hardware_keycode)
     {
@@ -133,7 +151,7 @@ private class PreferencesDialog : Dialog
         if (path == null)
             return;
 
-        var id = notebook.get_current_page () - 1;
+        var id = worm_combobox.get_active ();
         var list_store = list_stores[id];
 
         TreeIter it;
@@ -185,7 +203,7 @@ private class PreferencesDialog : Dialog
         if (path == null)
             return;
 
-        var id = notebook.get_current_page () - 1;
+        var id = worm_combobox.get_active ();
         var list_store = list_stores[id];
 
         TreeIter it;


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