[gnome-clocks] Fix remaining shortcuts



commit 4e368510b3e7a267eb47e6fa00cccc0a471bf567
Author: Maximiliano Sandoval R <msandova gnome org>
Date:   Fri Dec 17 15:24:25 2021 +0100

    Fix remaining shortcuts

 data/gtk/help-overlay.ui | 40 ++++++++++++++--------------
 data/ui/header-bar.ui    |  2 +-
 src/application.vala     |  2 ++
 src/header-bar.vala      |  6 +++++
 src/timer-face.vala      | 12 +++++++++
 src/window.vala          | 69 +++++++++++++++++++++++++++++++++++++-----------
 6 files changed, 94 insertions(+), 37 deletions(-)
---
diff --git a/data/gtk/help-overlay.ui b/data/gtk/help-overlay.ui
index 4a6fdd24..1687ac63 100644
--- a/data/gtk/help-overlay.ui
+++ b/data/gtk/help-overlay.ui
@@ -11,62 +11,62 @@
             <property name="title" translatable="yes" context="shortcut window">General</property>
             <child>
               <object class="GtkShortcutsShortcut">
-                <property name="accelerator">F1</property>
-                <property name="title" translatable="yes" context="shortcut window">Show help</property>
+                <property name="action-name">win.help</property>
+                <property name="title" translatable="yes" context="shortcut window">Show Help</property>
               </object>
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
-                <property name="accelerator">F10</property>
-                <property name="title" translatable="yes" context="shortcut window">Open menu</property>
+                <property name="action-name">win.show-primary-menu</property>
+                <property name="title" translatable="yes" context="shortcut window">Open Menu</property>
               </object>
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
                 <property name="action-name">win.show-help-overlay</property>
-                <property name="title" translatable="yes" context="shortcut window">Keyboard 
shortcuts</property>
+                <property name="title" translatable="yes" context="shortcut window">Keyboard 
Shortcuts</property>
               </object>
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
-                <property name="accelerator">&lt;ctrl&gt;Q</property>
+                <property name="action-name">app.quit</property>
                 <property name="title" translatable="yes" context="shortcut window">Quit</property>
               </object>
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
-                <property name="accelerator">&lt;ctrl&gt;&lt;alt&gt;Page_Down</property>
-                <property name="title" translatable="yes" context="shortcut window">Go to the next 
section</property>
+                <property name="action-name">win.navigate-forward</property>
+                <property name="title" translatable="yes" context="shortcut window">Go to the Next 
Section</property>
               </object>
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
-                <property name="accelerator">&lt;ctrl&gt;&lt;alt&gt;Page_Up</property>
-                <property name="title" translatable="yes" context="shortcut window">Go to the previous 
section</property>
+                <property name="action-name">win.navigate-backward</property>
+                <property name="title" translatable="yes" context="shortcut window">Go to the Previous 
Section</property>
               </object>
             </child>
              <child>
               <object class="GtkShortcutsShortcut">
                 <property name="accelerator">&lt;alt&gt;1</property>
-                <property name="title" translatable="yes" context="shortcut window">Go to the World 
section</property>
+                <property name="title" translatable="yes" context="shortcut window">Go to the World 
Section</property>
               </object>
             </child>
              <child>
               <object class="GtkShortcutsShortcut">
                 <property name="accelerator">&lt;alt&gt;2</property>
-                <property name="title" translatable="yes" context="shortcut window">Go to the Alarms 
section</property>
+                <property name="title" translatable="yes" context="shortcut window">Go to the Alarms 
Section</property>
               </object>
             </child>
              <child>
               <object class="GtkShortcutsShortcut">
                 <property name="accelerator">&lt;alt&gt;3</property>
-                <property name="title" translatable="yes" context="shortcut window">Go to the Stopwatch 
section</property>
+                <property name="title" translatable="yes" context="shortcut window">Go to the Stopwatch 
Section</property>
               </object>
             </child>
              <child>
               <object class="GtkShortcutsShortcut">
                 <property name="accelerator">&lt;alt&gt;4</property>
-                <property name="title" translatable="yes" context="shortcut window">Go to the Timer 
section</property>
+                <property name="title" translatable="yes" context="shortcut window">Go to the Timer 
Section</property>
               </object>
             </child>
           </object>
@@ -77,8 +77,8 @@
             <property name="title" translatable="yes" context="shortcut window">World Clocks</property>
             <child>
               <object class="GtkShortcutsShortcut">
-                <property name="accelerator">&lt;ctrl&gt;N</property>
-                <property name="title" translatable="yes" context="shortcut window">Add a world 
clock</property>
+                <property name="action-name">win.new</property>
+                <property name="title" translatable="yes" context="shortcut window">Add a World 
Clock</property>
               </object>
             </child>
           </object>
@@ -89,8 +89,8 @@
             <property name="title" translatable="yes" context="shortcut window">Alarm</property>
             <child>
               <object class="GtkShortcutsShortcut">
-                <property name="accelerator">&lt;ctrl&gt;N</property>
-                <property name="title" translatable="yes" context="shortcut window">Add an alarm</property>
+                <property name="action-name">win.new</property>
+                <property name="title" translatable="yes" context="shortcut window">Add an Alarm</property>
               </object>
             </child>
           </object>
@@ -102,7 +102,7 @@
             <child>
               <object class="GtkShortcutsShortcut">
                 <property name="accelerator">Escape</property>
-                <property name="title" translatable="yes" context="shortcut window">Stop / Reset</property>
+                <property name="title" translatable="yes" context="shortcut window">Pause All</property>
               </object>
             </child>
           </object>
@@ -119,7 +119,7 @@
             </child>
             <child>
               <object class="GtkShortcutsShortcut">
-                <property name="accelerator">&lt;primary&gt;N</property>
+                <property name="action-name">win.new</property>
                 <property name="title" translatable="yes" context="shortcut window">New Timer</property>
               </object>
             </child>
diff --git a/data/ui/header-bar.ui b/data/ui/header-bar.ui
index d1f1ca47..40473f25 100644
--- a/data/ui/header-bar.ui
+++ b/data/ui/header-bar.ui
@@ -64,7 +64,7 @@
           </object>
         </child>
         <child type="end">
-          <object class="GtkMenuButton">
+          <object class="GtkMenuButton" id="menu_button">
             <property name="tooltip-text" translatable="yes">Menu</property>
             <property name="menu_model">primary-menu</property>
             <property name="icon_name">open-menu-symbolic</property>
diff --git a/src/application.vala b/src/application.vala
index 5626a22d..6c1e39af 100644
--- a/src/application.vala
+++ b/src/application.vala
@@ -107,6 +107,8 @@ public class Application : Adw.Application {
         set_accels_for_action ("win.show-primary-menu", { "F10" });
         set_accels_for_action ("win.help", { "F1" });
         set_accels_for_action ("app.quit", { "<Control>q" });
+        set_accels_for_action ("win.navigate-backward", { "<Control><Alt>Page_Up" });
+        set_accels_for_action ("win.navigate-forward", { "<Control><Alt>Page_Down" });
     }
 
     protected override int handle_local_options (GLib.VariantDict options) {
diff --git a/src/header-bar.vala b/src/header-bar.vala
index 3eb8f9ba..18db6096 100644
--- a/src/header-bar.vala
+++ b/src/header-bar.vala
@@ -53,4 +53,10 @@ public class Clocks.HeaderBar : Adw.Bin {
 
     [GtkChild]
     private unowned Adw.ViewStack start_button_stack;
+    [GtkChild]
+    private unowned Gtk.MenuButton menu_button;
+
+    public void show_primary_menu () {
+        menu_button.activate ();
+    }
 }
diff --git a/src/timer-face.vala b/src/timer-face.vala
index 09bc6b47..18d15c84 100644
--- a/src/timer-face.vala
+++ b/src/timer-face.vala
@@ -144,6 +144,18 @@ public class Face : Adw.Bin, Clocks.Clock {
 
         return false;
     }
+
+    public bool escape_pressed () {
+        var res = false;
+        this.timers.foreach ((item) => {
+                var timer = (Item) item;
+                if (timer.state == Item.State.RUNNING) {
+                    timer.pause ();
+                    res = true;
+                }
+            });
+        return res;
+    }
 }
 
 } // namespace Timer
diff --git a/src/window.vala b/src/window.vala
index 709edd9c..29b3b8d9 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -22,10 +22,12 @@ namespace Clocks {
 public class Window : Adw.ApplicationWindow {
     private const GLib.ActionEntry[] ACTION_ENTRIES = {
         // primary menu
-        { "show-primary-menu", on_show_primary_menu_activate, null, "false", null },
+        { "show-primary-menu", on_show_primary_menu_activate },
         { "new", on_new_activate },
         { "back", on_back_activate },
         { "help", on_help_activate },
+        { "navigate-forward", on_navigate_forward },
+        { "navigate-backward", on_navigate_backward },
         { "about", on_about_activate },
     };
 
@@ -61,27 +63,20 @@ public class Window : Adw.ApplicationWindow {
     private bool inited = false;
 
     construct {
-        // plain ctrl+page_up/down is easten by the scrolled window...
-        add_binding_action (Gdk.Key.Page_Up,
-                            Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.ALT_MASK,
-                            "change-page", "(i)", 0);
-
-        add_binding_action (Gdk.Key.Page_Down,
-                            Gdk.ModifierType.CONTROL_MASK | Gdk.ModifierType.ALT_MASK,
-                            "change-page", "(i)", 1);
+        install_action ("set-page", "s", (Gtk.WidgetActionActivateFunc) on_set_page);
 
         add_binding_action (Gdk.Key.@1,
                             Gdk.ModifierType.ALT_MASK,
-                            "set-page", "(s)", "world");
+                            "set-page", "s", "world");
         add_binding_action (Gdk.Key.@2,
                             Gdk.ModifierType.ALT_MASK,
-                            "set-page", "(s)", "alarm");
+                            "set-page", "s", "alarm");
         add_binding_action (Gdk.Key.@3,
                             Gdk.ModifierType.ALT_MASK,
-                            "set-page", "(s)", "stopwatch");
+                            "set-page", "s", "stopwatch");
         add_binding_action (Gdk.Key.@4,
                             Gdk.ModifierType.ALT_MASK,
-                            "set-page", "(s)", "timer");
+                            "set-page", "s", "timer");
     }
 
     public Window (Application app) {
@@ -182,9 +177,8 @@ public class Window : Adw.ApplicationWindow {
         stack.visible_child_name = page;
     }
 
-    private void on_show_primary_menu_activate (SimpleAction action) {
-        var state = ((!) action.get_state ()).get_boolean ();
-        action.set_state (new Variant.boolean (!state));
+    private void on_show_primary_menu_activate () {
+        header_bar.show_primary_menu ();
     }
 
     private void on_new_activate () {
@@ -355,6 +349,49 @@ public class Window : Adw.ApplicationWindow {
     private void close_standalone () {
         world_leaflet.visible_child = main_view;
     }
+
+    private void on_navigate_forward () {
+        var current = stack.visible_child_name;
+        switch (current) {
+        case "world":
+            stack.visible_child_name = "alarm";
+            break;
+        case "alarm":
+            stack.visible_child_name = "stopwatch";
+            break;
+        case "stopwatch":
+            stack.visible_child_name = "timer";
+            break;
+        case "timer":
+            stack.visible_child_name = "world";
+            break;
+        }
+    }
+
+    private void on_navigate_backward () {
+        var current = stack.visible_child_name;
+        switch (current) {
+        case "world":
+            stack.visible_child_name = "timer";
+            break;
+        case "alarm":
+            stack.visible_child_name = "world";
+            break;
+        case "stopwatch":
+            stack.visible_child_name = "alarm";
+            break;
+        case "timer":
+            stack.visible_child_name = "stopwatch";
+            break;
+        }
+    }
+
+    private void on_set_page (string action_name, Variant? param) {
+        if (param != null) {
+            var page = param.get_string ();
+            stack.visible_child_name = page;
+        }
+    }
 }
 
 } // namespace Clocks


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