[four-in-a-row] Add a shortcut.



commit 92071b1b1f0ae874fdc850276a760be0e4f0a4eb
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Sun May 3 21:01:50 2020 +0200

    Add a shortcut.
    
    See #19.

 data/ui/help-overlay.ui | 24 ++++++++++++++++--------
 src/four-in-a-row.vala  | 34 +++++++++++++++++++++++++++-------
 src/game-window.vala    |  6 +++---
 3 files changed, 46 insertions(+), 18 deletions(-)
---
diff --git a/data/ui/help-overlay.ui b/data/ui/help-overlay.ui
index 0cf0332..bbf8efe 100644
--- a/data/ui/help-overlay.ui
+++ b/data/ui/help-overlay.ui
@@ -53,6 +53,14 @@
                 <property name="accelerator">&lt;Primary&gt;h</property>
               </object>
             </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: in the Keyboard Shortcuts window, section "During a game" -->
+                <property name="title" translatable="yes" context="shortcut window">Toggle game 
menu</property>
+                <property name="accelerator">&lt;Primary&gt;F10</property>
+              </object>
+            </child>
           </object>
         </child>
         <child>
@@ -114,6 +122,14 @@
             <property name="visible">True</property>
             <!-- Translators: section of the Keyboard Shortcuts window; contains "Help", "About", "Quit"... 
-->
             <property name="title" translatable="yes" context="shortcut window">Generic</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: in the Keyboard Shortcuts window, section "Generic" -->
+                <property name="title" translatable="yes" context="shortcut window">Toggle main 
menu</property>
+                <property name="accelerator">F10</property>
+              </object>
+            </child>
             <child>
               <object class="GtkShortcutsShortcut">
                 <property name="visible">True</property>
@@ -146,14 +162,6 @@
                 <property name="accelerator">&lt;Primary&gt;q</property>
               </object>
             </child>
-            <child>
-              <object class="GtkShortcutsShortcut">
-                <property name="visible">True</property>
-                <!-- Translators: in the Keyboard Shortcuts window, section "Generic" -->
-                <property name="title" translatable="yes" context="shortcut window">Toggle menu</property>
-                <property name="accelerator">F10</property>
-              </object>
-            </child>
           </object>
         </child>
       </object>
diff --git a/src/four-in-a-row.vala b/src/four-in-a-row.vala
index 622c314..1cb63dc 100644
--- a/src/four-in-a-row.vala
+++ b/src/four-in-a-row.vala
@@ -122,13 +122,14 @@ private class FourInARow : Gtk.Application
 
     private const GLib.ActionEntry app_entries [] =  // see also add_actions()
     {
-        { "game-type",      null,           "s", "'dark'", change_game_type },
-        { "next-round",     on_next_round           },
-        { "give-up",        on_give_up              },
-        { "scores",         on_game_scores          },
-        { "quit",           on_game_exit            },
-        { "help",           on_help_contents        },
-        { "about",          on_help_about           }
+        { "game-type",          null,       "s", "'dark'", change_game_type },
+        { "toggle-game-menu",   toggle_game_menu        },
+        { "next-round",         on_next_round           },
+        { "give-up",            on_give_up              },
+        { "scores",             on_game_scores          },
+        { "quit",               on_game_exit            },
+        { "help",               on_help_contents        },
+        { "about",              on_help_about           }
     };
 
     private static int main (string [] args)
@@ -341,6 +342,7 @@ private class FourInARow : Gtk.Application
      // set_accels_for_action ("ui.redo",               { "<Shift><Primary>z"       });
         set_accels_for_action ("ui.back",               {                 "Escape"  });
         set_accels_for_action ("ui.toggle-hamburger",   {                 "F10"     });
+     // set_accels_for_action ("app.toggle-game-menu",  {        "<Primary>F10"     });
      // set_accels_for_action ("app.help",              {                 "F1"      });
      // set_accels_for_action ("app.about",             {          "<Shift>F1"      });
 
@@ -1030,6 +1032,15 @@ private class FourInARow : Gtk.Application
             on_help_about ();
             return true;
         }
+        if (name == "F10") // TODO fix this dance also
+        {
+            if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0)
+            {
+                toggle_game_menu ();
+                return true;
+            }
+            return false;   // ui.toggle-hamburger
+        }
 
         return false;
     }
@@ -1288,4 +1299,13 @@ private class FourInARow : Gtk.Application
     {
         game_reset (/* reload settings */ false);
     }
+
+    private inline void toggle_game_menu (/* SimpleAction action, Variant? variant */)
+    {
+        window.close_hamburger ();
+        if (window.is_extra_thin)
+            history_button_2.active = !history_button_2.active;
+        else
+            history_button_1.active = !history_button_1.active;
+    }
 }
diff --git a/src/game-window.vala b/src/game-window.vala
index ce8abd1..0c47767 100644
--- a/src/game-window.vala
+++ b/src/game-window.vala
@@ -252,7 +252,7 @@ private class GameWindow : AdaptativeWindow, AdaptativeWidget
     * * adaptative stuff
     \*/
 
-    private bool is_extra_thin = false;
+    internal bool is_extra_thin { internal get; private set; default = false; }
     private bool is_quite_thin = false;
     protected override void set_window_size (AdaptativeWidget.WindowSize new_size)
     {
@@ -428,12 +428,12 @@ private class GameWindow : AdaptativeWindow, AdaptativeWidget
 
     [GtkChild] private MenuButton info_button;
 
-    private void toggle_hamburger (/* SimpleAction action, Variant? variant */)
+    private inline void toggle_hamburger (/* SimpleAction action, Variant? variant */)
     {
         info_button.active = !info_button.active;
     }
 
-    internal void close_hamburger () // TODO manage also the HistoryButton here?
+    internal inline void close_hamburger () // TODO manage also the HistoryButton here?
     {
         info_button.active = false;
     }


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