[swell-foop/arnaudb/event-controller-motion: 2/4] Add Keyboard Shortcuts dialog.



commit 3fabe57ac9ffb9188ecf8fb222363c093bdad41a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon May 4 19:50:56 2020 +0200

    Add Keyboard Shortcuts dialog.

 data/ui/help-overlay.ui               | 115 ++++++++++++++++++++++++++++++++++
 data/ui/swell-foop.ui                 |   7 ++-
 po/POTFILES.in                        |   1 +
 src/org.gnome.SwellFoop.gresource.xml |   3 +
 src/swell-foop.vala                   |   7 ++-
 src/window.vala                       |  11 +++-
 6 files changed, 138 insertions(+), 6 deletions(-)
---
diff --git a/data/ui/help-overlay.ui b/data/ui/help-overlay.ui
new file mode 100644
index 0000000..0c79e2c
--- /dev/null
+++ b/data/ui/help-overlay.ui
@@ -0,0 +1,115 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   This file is part of GNOME Tetravex.
+
+   Copyright (C) 2019 Arnaud Bonatti
+
+   GNOME Tetravex is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 2 of the License, or
+   (at your option) any later version.
+
+   GNOME Tetravex is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License along
+   with this GNOME Tetravex.  If not, see <https://www.gnu.org/licenses/>.
+-->
+<interface>
+  <requires lib="gtk+" version="3.24"/>
+  <object class="GtkShortcutsWindow" id="help_overlay">
+    <child>
+      <object class="GtkShortcutsSection">
+        <property name="visible">True</property>
+        <property name="max-height">5</property>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
+            <!-- Translators: title of a section in the Keyboard Shortcuts dialog; contains (only) "Start a 
new game" -->
+            <property name="title" translatable="yes" context="shortcut window">Main functions</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="accelerator">&lt;Ctrl&gt;N</property>
+                <!-- Translators: Ctrl-N shortcut description in the Keyboard Shortcuts dialog, section Main 
Functions -->
+                <property name="title" translatable="yes" context="shortcut window">Start a new 
game</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
+            <!-- Translators: title of a section in the Keyboard Shortcuts dialog; contains "Move keyboard 
highlight" and "Destroy selected block" -->
+            <property name="title" translatable="yes" context="shortcut window">Play with keyboard</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: Left/Right/Up/Down arrows actions description in the Keyboard Shortcuts 
dialog, section "Play with keyboard"; moves highlight -->
+                <property name="title" translatable="yes" context="shortcut window">Move keyboard 
highlight</property>
+                <property name="accelerator">Left Right Up Down</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: Return/space actions description in the Keyboard Shortcuts dialog, section 
"Play with keyboard"; does as a mouse click -->
+                <property name="title" translatable="yes" context="shortcut window">Destroy selected 
block</property>
+                <property name="accelerator">Return space</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
+            <!-- Translators: title of a section in the Keyboard Shortcuts dialog; contains "Help", "About", 
"Quit"... -->
+            <property name="title" translatable="yes" context="shortcut window">Generic</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: F10 shortcut description in the Keyboard Shortcuts dialog, section 
"Generic": toggles the hamburger menu -->
+                <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>
+                <!-- Translators: Ctrl-? shortcut description in the Keyboard Shortcuts dialog, section 
"Generic": opens Shortcuts dialog -->
+                <property name="title" translatable="yes" context="shortcut window">Keyboard 
shortcuts</property>
+                <property name="accelerator">&lt;Primary&gt;question</property> <!-- TODO &lt;Primary&gt;F1 
-->
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: F1 shortcut description in the Keyboard Shortcuts dialog, section 
"Generic": opens the application help -->
+                <property name="title" translatable="yes" context="shortcut window">Help</property>
+                <property name="accelerator">F1</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">False</property>
+                <!-- Translators: future shortcut description in the Keyboard Shortcuts dialog, section 
"Generic": shows the About dialog -->
+                <property name="title" translatable="yes" context="shortcut window">About</property>
+                <property name="accelerator">&lt;Shift&gt;F1</property> <!-- TODO add shortcut -->
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: Ctrl-Q shortcut description in the Keyboard Shortcuts dialog, section 
"Generic": quits the application -->
+                <property name="title" translatable="yes" context="shortcut window">Quit</property>
+                <property name="accelerator">&lt;Primary&gt;q</property>
+              </object>
+            </child>
+          </object>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/data/ui/swell-foop.ui b/data/ui/swell-foop.ui
index 9fe4b78..87ff3e3 100644
--- a/data/ui/swell-foop.ui
+++ b/data/ui/swell-foop.ui
@@ -39,6 +39,11 @@
         <attribute name="label" translatable="yes">_Preferences</attribute>
         <attribute name="action">app.preferences</attribute>
       </item>
+      <item>
+        <!-- Translators: entry of the hamburger menu (with a mnemonic that appears when pressing Alt); 
starts a new game -->
+        <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
+        <attribute name="action">win.show-help-overlay</attribute>
+      </item>
       <item>
         <!-- Translators: entry of the hamburger menu (with a mnemonic that appears when pressing Alt); 
starts a new game -->
         <attribute name="label" translatable="yes">_Help</attribute>
@@ -64,7 +69,7 @@
         <!-- Translators: title of the window displayed on the headerbar; name of the application -->
         <property name="title" translatable="yes">Swell Foop</property>
         <child>
-          <object class="GtkMenuButton">
+          <object class="GtkMenuButton" id="hamburger_button">
             <property name="visible">True</property>
             <property name="menu-model">hamburger-menu</property>
             <style>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4705608..e4b3ea5 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -4,6 +4,7 @@ data/org.gnome.SwellFoop.appdata.xml.in
 data/org.gnome.SwellFoop.desktop.in
 data/org.gnome.swell-foop.gschema.xml
 data/ui/first-run-stack.ui
+data/ui/help-overlay.ui
 data/ui/preferences.ui
 data/ui/swell-foop.ui
 src/game.vala
diff --git a/src/org.gnome.SwellFoop.gresource.xml b/src/org.gnome.SwellFoop.gresource.xml
index 87e726b..d9ce6a1 100644
--- a/src/org.gnome.SwellFoop.gresource.xml
+++ b/src/org.gnome.SwellFoop.gresource.xml
@@ -6,4 +6,7 @@
     <file alias="swell-foop.css">../data/swell-foop.css</file>
     <file preprocess="xml-stripblanks" alias="swell-foop.ui">../data/ui/swell-foop.ui</file>
   </gresource>
+  <gresource prefix="/org/gnome/SwellFoop/gtk">
+    <file preprocess="xml-stripblanks" alias="help-overlay.ui">../data/ui/help-overlay.ui</file>
+  </gresource>
 </gresources>
diff --git a/src/swell-foop.vala b/src/swell-foop.vala
index 2ae9cdb..f45610a 100644
--- a/src/swell-foop.vala
+++ b/src/swell-foop.vala
@@ -59,9 +59,10 @@ public class SwellFoop : Gtk.Application
         settings = new Settings ("org.gnome.swell-foop");
 
         add_action_entries (action_entries, this);
-        set_accels_for_action ("win.new-game",  { "<Primary>n"  });
-        set_accels_for_action ("app.help",      {          "F1" });
-        set_accels_for_action ("app.quit",      { "<Primary>q"  });
+        set_accels_for_action ("win.new-game",          { "<Primary>n"      });
+        set_accels_for_action ("app.help",              {          "F1"     });
+        set_accels_for_action ("win.toggle-hamburger",  {          "F10"    });
+        set_accels_for_action ("app.quit",              { "<Primary>q"      });
 
         /* Create the main window */
         window = new SwellFoopWindow (this, settings);
diff --git a/src/window.vala b/src/window.vala
index c7161bd..f68cf0c 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -24,6 +24,7 @@ private class SwellFoopWindow : ApplicationWindow
 {
     [GtkChild] private HeaderBar    headerbar;
     [GtkChild] private Box          main_box;
+    [GtkChild] private MenuButton   hamburger_button;
 
     public GLib.Settings settings { private get; protected construct; }
 
@@ -40,8 +41,9 @@ private class SwellFoopWindow : ApplicationWindow
 
     private const GLib.ActionEntry[] win_actions =
     {
-        { "new-game",   new_game_cb },
-        { "scores",     scores_cb   }
+        { "new-game",           new_game_cb         },
+        { "scores",             scores_cb           },
+        { "toggle-hamburger",   toggle_hamburger    }
     };
 
     construct
@@ -249,6 +251,11 @@ private class SwellFoopWindow : ApplicationWindow
             new_game ();
     }
 
+    private inline void toggle_hamburger (/* SimpleAction action, Variant? variant */)
+    {
+        hamburger_button.active = !hamburger_button.active;
+    }
+
     /*\
     * * keyboard
     \*/


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