[gnome-nibbles/arnaudb/shortcuts-dialog: 3/7] Add hamburger menu toggle shortcut.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-nibbles/arnaudb/shortcuts-dialog: 3/7] Add hamburger menu toggle shortcut.
- Date: Wed, 8 Jul 2020 15:03:03 +0000 (UTC)
commit eed8b1777588a00bf4ce2a225f51d5dddddcd67a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Jul 6 16:05:55 2020 +0200
Add hamburger menu toggle shortcut.
Would be great to pause the game,
but that will be for another day.
data/ui/nibbles.ui | 2 +-
src/gnome-nibbles.vala | 11 ++++++-----
src/nibbles-window.vala | 13 ++++++++++++-
3 files changed, 19 insertions(+), 7 deletions(-)
---
diff --git a/data/ui/nibbles.ui b/data/ui/nibbles.ui
index 3cd4523..a284c33 100644
--- a/data/ui/nibbles.ui
+++ b/data/ui/nibbles.ui
@@ -85,7 +85,7 @@
</packing>
</child>
<child>
- <object class="GtkMenuButton">
+ <object class="GtkMenuButton" id="hamburger_menu">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="menu-model">app-menu</property>
diff --git a/src/gnome-nibbles.vala b/src/gnome-nibbles.vala
index 6cc6dad..78da960 100644
--- a/src/gnome-nibbles.vala
+++ b/src/gnome-nibbles.vala
@@ -89,11 +89,12 @@ private class Nibbles : Gtk.Application
add_action_entries (action_entries, this);
- set_accels_for_action ("win.new-game", {"<Primary>n"});
- 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.new-game", { "<Primary>n" });
+ 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);
}
diff --git a/src/nibbles-window.vala b/src/nibbles-window.vala
index 59f72af..b6976f1 100644
--- a/src/nibbles-window.vala
+++ b/src/nibbles-window.vala
@@ -37,6 +37,7 @@ private class NibblesWindow : ApplicationWindow
/* HeaderBar */
[GtkChild] private HeaderBar headerbar;
+ [GtkChild] private MenuButton hamburger_menu;
[GtkChild] private Button new_game_button;
[GtkChild] private Button pause_button;
@@ -76,6 +77,8 @@ private class NibblesWindow : ApplicationWindow
private const GLib.ActionEntry menu_entries[] =
{
+ { "hamburger", hamburger_cb },
+
{ "new-game", new_game_cb }, // the "New Game" button
{ "pause", pause_cb },
{ "preferences", preferences_cb, "i" },
@@ -234,7 +237,10 @@ private class NibblesWindow : ApplicationWindow
private EventControllerKey key_controller; // for keeping in memory
private bool key_press_event_cb (EventControllerKey _key_controller, uint keyval, uint keycode,
Gdk.ModifierType state)
{
- return game.handle_keypress (keyval);
+ if (hamburger_menu.active)
+ return false;
+ else
+ return game.handle_keypress (keyval);
}
private void size_allocate_cb (Allocation allocation)
@@ -381,6 +387,11 @@ private class NibblesWindow : ApplicationWindow
}
}
+ private void hamburger_cb ()
+ {
+ hamburger_menu.active = !hamburger_menu.active;
+ }
+
/*\
* * Settings changed events
\*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]