[gnome-nibbles/arnaudb/shortcuts-dialog: 5/5] Make F1 and friends work.



commit 58b22641df0825fbc434b80ff37d4d0448356fbb
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Mon Jul 6 17:45:58 2020 +0200

    Make F1 and friends work.

 data/ui/help-overlay.ui |  8 ++++----
 data/ui/nibbles.ui      |  1 -
 src/gnome-nibbles.vala  | 15 ++++++++++++++-
 src/nibbles-window.vala |  2 ++
 4 files changed, 20 insertions(+), 6 deletions(-)
---
diff --git a/data/ui/help-overlay.ui b/data/ui/help-overlay.ui
index 6f0838b..3101e85 100644
--- a/data/ui/help-overlay.ui
+++ b/data/ui/help-overlay.ui
@@ -88,7 +88,7 @@
                 <property name="visible">True</property>
                 <!-- Translators: shortcut that opens Keyboard Shortcuts window -->
                 <property name="title" translatable="yes" context="shortcut window">Keyboard 
shortcuts</property>
-                <property name="accelerator">&lt;Primary&gt;question</property> <!-- TODO make 
&lt;Primary&gt;F1 work -->
+                <property name="accelerator">&lt;Primary&gt;F1 &lt;Primary&gt;question</property>
               </object>
             </child>
             <child>
@@ -101,10 +101,10 @@
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
-                <property name="visible">False</property>
-                <!-- Translators: shortcut (disabled for now) that opens About dialog -->
+                <property name="visible">True</property>
+                <!-- Translators: shortcut that opens About dialog -->
                 <property name="title" translatable="yes" context="shortcut window">About</property>
-                <property name="accelerator">&lt;Shift&gt;F1</property> <!-- TODO implement shortcut -->
+                <property name="accelerator">&lt;Shift&gt;F1</property>
               </object>
             </child>
             <child>
diff --git a/data/ui/nibbles.ui b/data/ui/nibbles.ui
index 94a94d4..c879f3c 100644
--- a/data/ui/nibbles.ui
+++ b/data/ui/nibbles.ui
@@ -44,7 +44,6 @@
         <!-- Translators: entry of the hamburger menu (with a mnemonic that appears when pressing Alt); 
opens the help of the application -->
         <attribute name="label" translatable="yes">_Help</attribute>
         <attribute name="action">app.help</attribute>
-        <attribute name="accel">F1</attribute>
       </item>
       <item>
         <!-- Translators: entry of the hamburger menu (with a mnemonic that appears when pressing Alt); 
opens the About dialog -->
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 33af594..1882581 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -89,17 +89,30 @@ private class Nibbles : Gtk.Application
 
         add_action_entries (action_entries, this);
 
+        // F1 and friends are managed manually
         set_accels_for_action ("win.new-game",  { "<Primary>n"      });
         set_accels_for_action ("win.pause",     { "<Primary>p",
                                                            "Pause"  });
         set_accels_for_action ("app.quit",      { "<Primary>q"      });
         set_accels_for_action ("win.back",      {          "Escape" });
-        set_accels_for_action ("app.help",      {          "F1"     });
         set_accels_for_action ("win.hamburger", {          "F10",
                                                            "Menu"   });
         window = new NibblesWindow ();
         add_window (window);
     }
+    internal bool on_f1_pressed (Gdk.ModifierType state)
+    {
+        // TODO close popovers
+        if ((state & Gdk.ModifierType.CONTROL_MASK) != 0)
+            return false;                           // help overlay
+        if ((state & Gdk.ModifierType.SHIFT_MASK) == 0)
+        {
+            help_cb ();
+            return true;
+        }
+        about_cb ();
+        return true;
+    }
 
     protected override void activate ()
     {
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 1dd3d9d..144fc29 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -239,6 +239,8 @@ private class NibblesWindow : ApplicationWindow
     {
         if (hamburger_menu.active)
             return false;
+        else if ((!) (Gdk.keyval_name (keyval) ?? "") == "F1")
+            return ((Nibbles) application).on_f1_pressed (state);   // TODO fix dance done with the F1 & 
<Control>F1 shortcuts that show help overlay
         else
             return game.handle_keypress (keyval);
     }


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