[gnome-klotski] Add Shortcuts dialog.



commit 1cb95e82931625b79e8531f6124e6b2ba20c8b56
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed May 6 15:47:57 2020 +0200

    Add Shortcuts dialog.

 data/ui/help-overlay.ui   | 162 ++++++++++++++++++++++++++++++++++++++++++++++
 data/ui/klotski.ui        |   9 ++-
 po/POTFILES.in            |   1 +
 src/gnome-klotski.vala    |  72 ++-------------------
 src/klotski-window.vala   |  83 +++++++++++++++++++++++-
 src/klotski.gresource.xml |   3 +
 6 files changed, 259 insertions(+), 71 deletions(-)
---
diff --git a/data/ui/help-overlay.ui b/data/ui/help-overlay.ui
new file mode 100644
index 0000000..29193ac
--- /dev/null
+++ b/data/ui/help-overlay.ui
@@ -0,0 +1,162 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   This file is part of GNOME Klotski.
+
+   Copyright (C) 2020 Arnaud Bonatti
+
+   GNOME Klotski 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 3 of the License, or
+   (at your option) any later version.
+
+   GNOME Klotski 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 Klotski.  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">8</property>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
+            <!-- Translators: title of a section in the Keyboard Shortcuts dialog; contains "Toggle game 
menu" and "Restart" -->
+            <property name="title" translatable="yes" context="shortcut window">Puzzle-related</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">False</property>
+                <!-- Translators: Ctrl-Shift-N shortcut description in the Keyboard Shortcuts dialog, 
section "Puzzle-related"; toggles the game menu -->
+                <property name="title" translatable="yes" context="shortcut window">Toggle game 
menu</property>
+                <property name="accelerator">&lt;Primary&gt;F10</property> <!-- show if there is more than 
one thing in it -->
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: Ctrl-Shift-N shortcut description in the Keyboard Shortcuts dialog, 
section "Puzzle-related"; restarts the current puzzle -->
+                <property name="title" translatable="yes" context="shortcut window">Restart</property>
+                <property name="accelerator">&lt;Primary&gt;&lt;Shift&gt;N</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 the actions for 
selecting a new puzzle -->
+            <property name="title" translatable="yes" context="shortcut window">Change Puzzle 
popover</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: Ctrl-S shortcut description in the Keyboard Shortcuts dialog, section 
"Headerbar"; toggles the Change Puzzle menu -->
+                <property name="title" translatable="yes" context="shortcut window">Select new 
puzzle</property>
+                <property name="accelerator">&lt;Primary&gt;N</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: Up action description in the Keyboard Shortcuts dialog, section "Change 
Puzzle popover"; switch to previous puzzle -->
+                <property name="title" translatable="yes" context="shortcut window">Previous 
puzzle</property>
+                <property name="accelerator">Up</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: Down shortcut description in the Keyboard Shortcuts dialog, section 
"Change Puzzle popover"; switch to next puzzle -->
+                <property name="title" translatable="yes" context="shortcut window">Next puzzle</property>
+                <property name="accelerator">Down</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: Page_Up action description in the Keyboard Shortcuts dialog, section 
"Change Puzzle popover"; switch to previous puzzles group -->
+                <property name="title" translatable="yes" context="shortcut window">Previous puzzles 
group</property>
+                <property name="accelerator">Page_Up</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: Page_Down shortcut description in the Keyboard Shortcuts dialog, section 
"Change Puzzle popover"; switch to next puzzles group -->
+                <property name="title" translatable="yes" context="shortcut window">Next puzzles 
group</property>
+                <property name="accelerator">Page_Down</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 (only) "Scores 
dialog" -->
+            <property name="title" translatable="yes" context="shortcut window">Scores</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <!-- Translators: Ctrl-S shortcut description in the Keyboard Shortcuts dialog, section 
"Scores" -->
+                <property name="title" translatable="yes" context="shortcut window">Scores dialog</property>
+                <property name="accelerator">&lt;Primary&gt;S</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 &lt;Primary&gt;F1</property>
+              </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">True</property>
+                <!-- Translators: Shift-F1 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>
+              </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/klotski.ui b/data/ui/klotski.ui
index b2ce510..62b6fe9 100644
--- a/data/ui/klotski.ui
+++ b/data/ui/klotski.ui
@@ -26,15 +26,20 @@
       </item>
     </section>
     <section>
+      <item>
+        <!-- Translators: label of an entry in the Hamburger menu (with a mnemonic that appears pressing 
Alt); opens the Keyboard Shortcuts dialog -->
+        <attribute name="label" translatable="yes">_Keyboard Shortcuts</attribute>
+        <attribute name="action">win.show-help-overlay</attribute>
+      </item>
       <item>
         <!-- Translators: label of an entry in the Hamburger menu (with a mnemonic that appears pressing 
Alt); opens the help of the application -->
         <attribute name="label" translatable="yes">_Help</attribute>
-        <attribute name="action">app.help</attribute>
+        <attribute name="action">win.help</attribute>
       </item>
       <item>
         <!-- Translators: label of an entry in the Hamburger menu (with a mnemonic that appears pressing 
Alt); opens the About dialog -->
         <attribute name="label" translatable="yes">_About Klotski</attribute>
-        <attribute name="action">app.about</attribute>
+        <attribute name="action">win.about</attribute>
       </item>
     </section>
   </menu>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 76d7ee9..5bb178f 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -1,5 +1,6 @@
 # List of source files containing translatable strings.
 # Please keep this file in alphabetical order.
+data/ui/help-overlay.ui
 data/ui/klotski.ui
 data/org.gnome.Klotski.appdata.xml.in
 data/org.gnome.Klotski.desktop.in
diff --git a/src/gnome-klotski.vala b/src/gnome-klotski.vala
index 7b90ff2..cafb198 100644
--- a/src/gnome-klotski.vala
+++ b/src/gnome-klotski.vala
@@ -22,7 +22,7 @@ using Gtk;
 private class Klotski : Gtk.Application
 {
     /* Translators: application name, as used in the window manager, the window title, the about dialog... */
-    internal const string PROGRAM_NAME = _("Klotski");
+    internal static string PROGRAM_NAME = _("Klotski");
 
     private KlotskiWindow window;
 
@@ -35,9 +35,7 @@ private class Klotski : Gtk.Application
 
     private const GLib.ActionEntry action_entries [] =
     {
-        { "help",   help_cb  },
-        { "about",  about_cb },
-        { "quit",   quit     }
+        { "quit", quit }
     };
 
     /*\
@@ -95,8 +93,8 @@ private class Klotski : Gtk.Application
 
         set_accels_for_action ("win.show-scores",   {        "<Primary>s",      // TODO that's a weird 
shortcut
                                                       "<Shift><Primary>s"   });
-        set_accels_for_action ("app.help",          {                 "F1"  });
-        set_accels_for_action ("app.about",         {          "<Shift>F1"  });
+     // set_accels_for_action ("win.help",          {                 "F1"  }); // TODO fix dance with
+     // set_accels_for_action ("win.about",         {          "<Shift>F1"  }); // the shortcuts dialog
         set_accels_for_action ("app.quit",          {        "<Primary>q",
                                                       "<Shift><Primary>q"   });
     }
@@ -111,66 +109,4 @@ private class Klotski : Gtk.Application
         window.destroy ();
         base.shutdown ();
     }
-
-    /*\
-    * * help and about
-    \*/
-
-    private void help_cb ()
-    {
-        try
-        {
-            show_uri_on_window (window, "help:gnome-klotski", get_current_event_time ());
-        }
-        catch (Error e)
-        {
-            warning ("Failed to show help: %s", e.message);
-        }
-    }
-
-    private void about_cb ()
-    {
-        string [] authors = {
-        /* Translators: text crediting an author, in the about dialog */
-            _("Lars Rydlinge (original author)"),
-
-
-        /* Translators: text crediting an author, in the about dialog */
-            _("Robert Ancell (port to vala)"),
-
-
-        /* Translators: text crediting an author, in the about dialog */
-            _("John Cheetham (port to vala)")
-        };
-
-        /* Translators: text crediting a documenter, in the about dialog */
-        string [] documenters = { _("Andrew Sobala") };
-
-        show_about_dialog (window,
-                           /* Translators: name of the program, seen in the About dialog */
-                           "program-name", PROGRAM_NAME,
-
-                           "version", VERSION,
-                           /* Translators: small description of the game, seen in the About dialog */
-                           "comments", _("Sliding block puzzles"),
-
-                           "copyright",
-                             /* Translators: text crediting a maintainer, seen in the About dialog */
-                             _("Copyright \xc2\xa9 1999-2008 – Lars Rydlinge") + "\n"+
-
-
-                             /* Translators: text crediting a maintainer, seen in the About dialog; the %u 
are replaced with the years of start and end */
-                             _("Copyright \xc2\xa9 %u-%u – Michael Catanzaro").printf (2014, 2016) + "\n"+
-
-
-                             /* Translators: text crediting a maintainer, seen in the About dialog; the %u 
are replaced with the years of start and end */
-                             _("Copyright \xc2\xa9 %u-%u – Arnaud Bonatti").printf (2015, 2020),
-                           "license-type", License.GPL_3_0, // means "GNU General Public License, version 
3.0 or later"
-                           "authors", authors,
-                           "documenters", documenters,
-                           "logo-icon-name", "org.gnome.Klotski",
-                           /* Translators: about dialog text; this string should be replaced by a text 
crediting yourselves and your translation team, or should be left empty. Do not translate literally! */
-                           "translator-credits", _("translator-credits"),
-                           "website", "https://wiki.gnome.org/Apps/Klotski";);
-    }
 }
diff --git a/src/klotski-window.vala b/src/klotski-window.vala
index 1542705..cc16261 100644
--- a/src/klotski-window.vala
+++ b/src/klotski-window.vala
@@ -467,7 +467,10 @@ private class KlotskiWindow : ApplicationWindow
         { "prev-puzzle",    prev_puzzle_cb      },
         { "next-puzzle",    next_puzzle_cb      },
         { "start-game",     start_puzzle_cb     },
-        { "unfullscreen",   unfullscreen        }
+        { "unfullscreen",   unfullscreen        },
+
+        { "help",           help_cb             },
+        { "about",          about_cb            }
     };
 
     private static string normalize_map_name (string name)
@@ -1058,6 +1061,22 @@ private class KlotskiWindow : ApplicationWindow
     {
         string name = (!) (Gdk.keyval_name (keyval) ?? "");
 
+        if (name == "F1")   // Gtk handles badly having F1 or Shift-F1 as action shortcut while using 
Ctrl-F1 automatically
+        {
+            if ((state & Gdk.ModifierType.CONTROL_MASK) != 0)
+                return false;   // help overlay
+            if ((state & Gdk.ModifierType.SHIFT_MASK) == 0)
+            {
+                help_cb ();
+                return true;
+            }
+            else
+            {
+                about_cb ();
+                return true;
+            }
+            return false;
+        }
         if (name == "F10")  // Gtk handles badly having F10 and Ctrl-F10 as actions shortcuts
         {
             if (state == 0)
@@ -1075,4 +1094,66 @@ private class KlotskiWindow : ApplicationWindow
         }
         return false;
     }
+
+    /*\
+    * * help and about
+    \*/
+
+    private inline void help_cb ()
+    {
+        try
+        {
+            show_uri_on_window (this, "help:gnome-klotski", get_current_event_time ());
+        }
+        catch (Error e)
+        {
+            warning ("Failed to show help: %s", e.message);
+        }
+    }
+
+    private inline void about_cb ()
+    {
+        string [] authors = {
+        /* Translators: text crediting an author, in the about dialog */
+            _("Lars Rydlinge (original author)"),
+
+
+        /* Translators: text crediting an author, in the about dialog */
+            _("Robert Ancell (port to vala)"),
+
+
+        /* Translators: text crediting an author, in the about dialog */
+            _("John Cheetham (port to vala)")
+        };
+
+        /* Translators: text crediting a documenter, in the about dialog */
+        string [] documenters = { _("Andrew Sobala") };
+
+        show_about_dialog (this,
+                           /* Translators: name of the program, seen in the About dialog */
+                           "program-name", Klotski.PROGRAM_NAME,
+
+                           "version", VERSION,
+                           /* Translators: small description of the game, seen in the About dialog */
+                           "comments", _("Sliding block puzzles"),
+
+                           "copyright",
+                             /* Translators: text crediting a maintainer, seen in the About dialog */
+                             _("Copyright \xc2\xa9 1999-2008 – Lars Rydlinge") + "\n"+
+
+
+                             /* Translators: text crediting a maintainer, seen in the About dialog; the %u 
are replaced with the years of start and end */
+                             _("Copyright \xc2\xa9 %u-%u – Michael Catanzaro").printf (2014, 2016) + "\n"+
+
+
+                             /* Translators: text crediting a maintainer, seen in the About dialog; the %u 
are replaced with the years of start and end */
+                             _("Copyright \xc2\xa9 %u-%u – Arnaud Bonatti").printf (2015, 2020),
+                           "license-type", License.GPL_3_0, // means "GNU General Public License, version 
3.0 or later"
+                           "authors", authors,
+                           "documenters", documenters,
+                           "logo-icon-name", "org.gnome.Klotski",
+                           /* Translators: about dialog text; this string should be replaced by a text 
crediting yourselves and your translation team, or should be left empty. Do not translate literally! */
+                           "translator-credits", _("translator-credits"),
+                           "website", "https://wiki.gnome.org/Apps/Klotski";);
+    }
 }
diff --git a/src/klotski.gresource.xml b/src/klotski.gresource.xml
index 3abbd63..8f264ed 100644
--- a/src/klotski.gresource.xml
+++ b/src/klotski.gresource.xml
@@ -5,4 +5,7 @@
     <file preprocess="xml-stripblanks" alias="klotski.ui">../data/ui/klotski.ui</file>
     <file alias="klotski.css">../data/klotski.css</file>
   </gresource>
+  <gresource prefix="/org/gnome/Klotski/gtk">
+    <file preprocess="xml-stripblanks" alias="help-overlay.ui">../data/ui/help-overlay.ui</file>
+  </gresource>
 </gresources>


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