[gnome-taquin] Add help overlay.



commit 4f730a9b7650b4e41d07ae3c263145c9285caf06
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Wed Jan 23 13:23:27 2019 +0100

    Add help overlay.

 data/help-overlay.ui     | 156 +++++++++++++++++++++++++++++++++++++++++++++++
 po/POTFILES.in           |   1 +
 src/base-headerbar.vala  |   2 +-
 src/base-window.vala     |  27 +++++++-
 src/game-headerbar.vala  |   2 +-
 src/taquin-main.vala     |  25 +++-----
 src/taquin.gresource.xml |   3 +
 7 files changed, 195 insertions(+), 21 deletions(-)
---
diff --git a/data/help-overlay.ui b/data/help-overlay.ui
new file mode 100644
index 0000000..71f4073
--- /dev/null
+++ b/data/help-overlay.ui
@@ -0,0 +1,156 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  This file is part of GNOME Taquin
+
+  GNOME Taquin 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 Taquin 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 GNOME Taquin.  If not, see <https://www.gnu.org/licenses/>.
+-->
+<interface domain="gnome-taquin">
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkShortcutsWindow" id="help_overlay">
+    <child>
+      <object class="GtkShortcutsSection">
+        <property name="visible">True</property>
+        <property name="max-height">11</property>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
+            <property name="title" translatable="yes" context="shortcut window">During game 
selection</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes" context="shortcut window">Start new game</property>
+                <property name="accelerator">&lt;Primary&gt;&lt;Shift&gt;n</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes" context="shortcut window">Go back</property>
+                <property name="accelerator">Escape</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
+            <property name="title" translatable="yes" context="shortcut window">During a game</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes" context="shortcut window">New game</property>
+                <property name="accelerator">&lt;Primary&gt;n</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes" context="shortcut window">Undo last move</property>
+                <property name="accelerator">&lt;Primary&gt;z</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
+            <property name="title" translatable="yes" context="shortcut window">15-Puzzle</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes" context="shortcut window">Select tile to push 
on</property>
+                <property name="accelerator">Left Right Up Down</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes" context="shortcut window">Push on selected 
tile</property>
+                <property name="accelerator">Escape Return</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
+            <property name="title" translatable="yes" context="shortcut window">16-Puzzle</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes" context="shortcut window">Change selected 
column</property>
+                <property name="accelerator">Left Right</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes" context="shortcut window">Change selected 
row</property>
+                <property name="accelerator">Up Down</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes" context="shortcut window">Swipe selected 
row</property>
+                <property name="accelerator">&lt;Shift&gt;Left &lt;Shift&gt;Right</property>
+              </object>
+            </child>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <property name="title" translatable="yes" context="shortcut window">Swipe selected 
column</property>
+                <property name="accelerator">&lt;Shift&gt;Up &lt;Shift&gt;Down</property>
+              </object>
+            </child>
+          </object>
+        </child>
+        <child>
+          <object class="GtkShortcutsGroup">
+            <property name="visible">True</property>
+            <property name="title" translatable="yes" context="shortcut window">Generic</property>
+            <child>
+              <object class="GtkShortcutsShortcut">
+                <property name="visible">True</property>
+                <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>
+                <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>
+                <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>
+                <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/po/POTFILES.in b/po/POTFILES.in
index e529df7..ffaec99 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,6 +5,7 @@ data/org.gnome.Taquin.desktop.in
 data/org.gnome.Taquin.gschema.xml
 data/base-headerbar.ui
 data/game-headerbar.ui
+data/help-overlay.ui
 data/taquin-screens.ui
 src/about-list.vala
 src/adaptative-window.vala
diff --git a/src/base-headerbar.vala b/src/base-headerbar.vala
index 0ee225a..8cb5774 100644
--- a/src/base-headerbar.vala
+++ b/src/base-headerbar.vala
@@ -122,7 +122,7 @@ private class BaseHeaderBar : NightTimeAwareHeaderBar, AdaptativeWidget
             return;
 
         /* Translators: usual menu entry of the hamburger menu (with a mnemonic that appears pressing Alt) */
-        section.append (_("_Help"), "app.help");
+        section.append (_("_Help"), "base.help");
     }
 
     private static inline void append_about_entry (string about_action_label, ref GLib.Menu section)
diff --git a/src/base-window.vala b/src/base-window.vala
index b061c79..7f37a54 100644
--- a/src/base-window.vala
+++ b/src/base-window.vala
@@ -103,6 +103,8 @@ private class BaseWindow : AdaptativeWindow, AdaptativeWidget
         { "menu",               menu_pressed        },  // Menu
 
         { "show-default-view",  show_default_view   },
+
+        { "help",               help                },
         { "about",              about               }
     };
 
@@ -295,8 +297,10 @@ private class BaseWindow : AdaptativeWindow, AdaptativeWidget
 
             _this.headerbar.close_popovers ();
             _this.main_view.close_popovers ();
+            if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0)
+                return false;                           // help overlay
             if ((event.state & Gdk.ModifierType.SHIFT_MASK) == 0)
-                return false;   // help overlay
+                return show_application_help (_this);   // fallback on help overlay (TODO test)
             _this.about ();
             return true;
         }
@@ -304,6 +308,27 @@ private class BaseWindow : AdaptativeWindow, AdaptativeWidget
         return false;
     }
 
+    private void help (/* SimpleAction action, Variant? variant */)
+    {
+        show_application_help (this);
+    }
+
+    private static inline bool show_application_help (BaseWindow _this)
+    {
+        bool success;
+        try
+        {
+            show_uri (_this.get_screen (), "help:gnome-taquin", get_current_event_time ());
+            success = true;
+        }
+        catch (Error e)
+        {
+            warning ("Failed to show help: %s", e.message);
+            success = false;
+        }
+        return success;
+    }
+
     /*\
     * * adaptative stuff
     \*/
diff --git a/src/game-headerbar.vala b/src/game-headerbar.vala
index 58a6a7d..e7871c2 100644
--- a/src/game-headerbar.vala
+++ b/src/game-headerbar.vala
@@ -48,7 +48,7 @@ private class GameHeaderBar : BaseHeaderBar
         Object (about_action_label:     _("About Taquin"),
                 night_light_monitor:    _night_light_monitor,
                 has_help:               true,
-                has_keyboard_shortcuts: false,
+                has_keyboard_shortcuts: true,
                 window_name:            _window_name);
 
 /*        if (GameWindowFlags.SHOW_UNDO in flags)
diff --git a/src/taquin-main.vala b/src/taquin-main.vala
index 05f0743..627599e 100644
--- a/src/taquin-main.vala
+++ b/src/taquin-main.vala
@@ -77,7 +77,6 @@ private class Taquin : Gtk.Application, BaseApplication
         {"change-theme", change_theme_cb, "s"},
 
         {"set-use-night-mode", set_use_night_mode, "b"},
-        {"help", help_cb},
         {"quit", quit}
     };
 
@@ -172,7 +171,13 @@ private class Taquin : Gtk.Application, BaseApplication
         set_accels_for_action ("base.escape",           {                 "Escape"  });
         set_accels_for_action ("base.toggle-hamburger", {                 "F10",
                                                                           "Menu"    });
-        set_accels_for_action ("app.help",              {                 "F1"      });
+//        set_accels_for_action ("app.help",              {                 "F1"      });
+//        set_accels_for_action ("base.about",            {          "<Shift>F1"      });
+        set_accels_for_action ("win.show-help-overlay", {                 "F1", // TODO test: if showing 
Yelp fails, should fallback there
+                                                                 "<Primary>F1",
+                                                          "<Shift><Primary>F1",
+                                                                 "<Primary>question",
+                                                          "<Shift><Primary>question"});
 
         /* New-game screen signals */
         settings.changed ["size"].connect (() => {
@@ -260,22 +265,6 @@ private class Taquin : Gtk.Application, BaseApplication
         ((!) game).move.connect (move_cb);
     }
 
-    /*\
-    * * App-menu callbacks
-    \*/
-
-    private void help_cb ()
-    {
-        try
-        {
-            show_uri (window.get_screen (), "help:gnome-taquin", get_current_event_time ());
-        }
-        catch (Error e)
-        {
-            warning ("Failed to show help: %s", e.message);
-        }
-    }
-
     /*\
     * * Signals from window
     \*/
diff --git a/src/taquin.gresource.xml b/src/taquin.gresource.xml
index aa68947..98dd612 100644
--- a/src/taquin.gresource.xml
+++ b/src/taquin.gresource.xml
@@ -17,4 +17,7 @@
     <file preprocess="xml-stripblanks" alias="taquin-screens.ui">../data/taquin-screens.ui</file>
     <file alias="taquin.css">../data/taquin.css</file>
   </gresource>
+  <gresource prefix="/org/gnome/Taquin/gtk">
+    <file preprocess="xml-stripblanks" alias="help-overlay.ui">../data/help-overlay.ui</file>
+  </gresource>
 </gresources>


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