[gnome-tetravex] Improve shortcuts.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tetravex] Improve shortcuts.
- Date: Wed, 18 Sep 2019 22:03:28 +0000 (UTC)
commit 64750a6a15b7d53a36ddb24155eede50c5904730
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Wed Sep 18 23:24:27 2019 +0200
Improve shortcuts.
Improve Keyboard Shortucts
dialog; add two shortcuts,
for solving and displaying
scores; make the F1 stuff.
src/gnome-tetravex.vala | 142 +++++++++++++++++++++++++++++-------------------
src/help-overlay.ui | 81 ++++++++++++++++++++-------
2 files changed, 146 insertions(+), 77 deletions(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index 5af8fec..8b241f7 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -97,15 +97,17 @@ private class Tetravex : Gtk.Application
Window.set_default_icon_name ("org.gnome.Tetravex");
add_action_entries (action_entries, this);
+ set_accels_for_action ("app.solve", {"<Primary>h" });
+ set_accels_for_action ("app.scores", {"<Primary>i" });
set_accels_for_action ("app.new-game", {"<Primary>n" });
set_accels_for_action ("app.pause", {"<Primary>p",
"Pause" });
- set_accels_for_action ("app.help", { "F1" });
set_accels_for_action ("app.quit", {"<Primary>q" });
set_accels_for_action ("app.move-up", {"<Primary>Up" });
set_accels_for_action ("app.move-down", {"<Primary>Down" });
set_accels_for_action ("app.move-left", {"<Primary>Left" });
set_accels_for_action ("app.move-right", {"<Primary>Right" });
+ // F1 and friends are managed manually
Builder builder = new Builder.from_resource ("/org/gnome/Tetravex/gnome-tetravex.ui");
@@ -115,6 +117,7 @@ private class Tetravex : Gtk.Application
window = (ApplicationWindow) builder.get_object ("gnome-tetravex-window");
this.add_window (window);
+ window.key_press_event.connect (on_key_press_event);
window.size_allocate.connect (size_allocate_cb);
window.window_state_event.connect (window_state_event_cb);
window.set_default_size (settings.get_int ("window-width"), settings.get_int ("window-height"));
@@ -428,6 +431,87 @@ private class Tetravex : Gtk.Application
}
}
+ private void size_changed (SimpleAction action, Variant variant)
+ {
+ int size = ((string) variant)[0] - '0'; // FIXME that... is... horrible
+
+ if (size == settings.get_int (KEY_GRID_SIZE))
+ return;
+ if (view.game_in_progress)
+ {
+ MessageDialog dialog = new MessageDialog (window,
+ DialogFlags.MODAL,
+ MessageType.QUESTION,
+ ButtonsType.NONE,
+ /* Translators: popup dialog main text; appearing when user changes size from the hamburger menu
submenu, while a game is started; possible answers are "Keep playing"/"Start New Game" */
+ _("Are you sure you want to start a new game with a
different board size?"));
+
+ /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing
when user clicks the "Give up" button in the bottom bar; other possible answer is "_Start New Game" */
+ dialog.add_buttons (_("_Keep Playing"), ResponseType.REJECT,
+
+ /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing
when user clicks the "Give up" button in the bottom bar; other possible answer is "_Keep Playing" */
+ _("_Start New Game"), ResponseType.ACCEPT,
+ null);
+
+ int response = dialog.run ();
+ dialog.destroy ();
+
+ if (response != ResponseType.ACCEPT)
+ return;
+ }
+ settings.set_int (KEY_GRID_SIZE, size);
+ game_size = (int) size;
+ action.set_state (variant);
+ new_game ();
+ }
+
+ private void move_up () { puzzle.move_up (); }
+ private void move_down () { puzzle.move_down (); }
+ private void move_left () { puzzle.move_left (); }
+ private void move_right () { puzzle.move_right (); }
+
+ private void pause_cb (SimpleAction action, Variant? parameter)
+ {
+ puzzle.paused = !puzzle.paused;
+ update_button_states ();
+ }
+
+ private void update_button_states ()
+ {
+ solve_action.set_enabled (!puzzle.paused);
+ play_pause_stack.set_visible_child_name (puzzle.paused ? "play" : "pause");
+ }
+
+ private void radio_cb (SimpleAction action, Variant? parameter)
+ {
+ action.change_state (parameter);
+ }
+
+ /*\
+ * * help/about
+ \*/
+
+ private bool on_key_press_event (Widget widget, Gdk.EventKey event)
+ {
+ string name = (!) (Gdk.keyval_name (event.keyval) ?? "");
+
+ if (name == "F1") // TODO fix dance done with the F1 & <Primary>F1 shortcuts that show help overlay
+ {
+ // TODO close popovers
+ if ((event.state & Gdk.ModifierType.CONTROL_MASK) != 0)
+ return false; // help overlay
+ if ((event.state & Gdk.ModifierType.SHIFT_MASK) == 0)
+ {
+ help_cb ();
+ return true;
+ }
+ about_cb ();
+ return true;
+ }
+
+ return false;
+ }
+
private void help_cb ()
{
try
@@ -486,60 +570,4 @@ private class Tetravex : Gtk.Application
"website-label", website_label,
null);
}
-
- private void size_changed (SimpleAction action, Variant variant)
- {
- int size = ((string) variant)[0] - '0'; // FIXME that... is... horrible
-
- if (size == settings.get_int (KEY_GRID_SIZE))
- return;
- if (view.game_in_progress)
- {
- MessageDialog dialog = new MessageDialog (window,
- DialogFlags.MODAL,
- MessageType.QUESTION,
- ButtonsType.NONE,
- /* Translators: popup dialog main text; appearing when user changes size from the hamburger menu
submenu, while a game is started; possible answers are "Keep playing"/"Start New Game" */
- _("Are you sure you want to start a new game with a
different board size?"));
-
- /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing
when user clicks the "Give up" button in the bottom bar; other possible answer is "_Start New Game" */
- dialog.add_buttons (_("_Keep Playing"), ResponseType.REJECT,
-
- /* Translators: popup dialog possible answer (with a mnemonic that appears pressing Alt); appearing
when user clicks the "Give up" button in the bottom bar; other possible answer is "_Keep Playing" */
- _("_Start New Game"), ResponseType.ACCEPT,
- null);
-
- int response = dialog.run ();
- dialog.destroy ();
-
- if (response != ResponseType.ACCEPT)
- return;
- }
- settings.set_int (KEY_GRID_SIZE, size);
- game_size = (int) size;
- action.set_state (variant);
- new_game ();
- }
-
- private void move_up () { puzzle.move_up (); }
- private void move_down () { puzzle.move_down (); }
- private void move_left () { puzzle.move_left (); }
- private void move_right () { puzzle.move_right (); }
-
- private void pause_cb (SimpleAction action, Variant? parameter)
- {
- puzzle.paused = !puzzle.paused;
- update_button_states ();
- }
-
- private void update_button_states ()
- {
- solve_action.set_enabled (!puzzle.paused);
- play_pause_stack.set_visible_child_name (puzzle.paused ? "play" : "pause");
- }
-
- private void radio_cb (SimpleAction action, Variant? parameter)
- {
- action.change_state (parameter);
- }
}
diff --git a/src/help-overlay.ui b/src/help-overlay.ui
index 239e936..79f5d3e 100644
--- a/src/help-overlay.ui
+++ b/src/help-overlay.ui
@@ -6,9 +6,12 @@
<child>
<object class="GtkShortcutsSection">
<property name="visible">1</property>
+ <property name="max-height">5</property>
<child>
<object class="GtkShortcutsGroup">
<property name="visible">1</property>
+ <!-- Translators: title of a section in the Keyboard Shortcuts dialog; contains "New Game",
"Pause", "Scores"... -->
+ <property name="title" translatable="yes" context="shortcut window">Main functions</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
@@ -28,33 +31,32 @@
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
- <property name="accelerator"><Ctrl>Up</property>
- <!-- Translators: Ctrl-Up shortcut description in the Keyboard Shortcuts dialog -->
- <property name="title" translatable="yes" context="shortcut window">Move all the pieces in
the left box up by one</property>
- </object>
- </child>
- <child>
- <object class="GtkShortcutsShortcut">
- <property name="visible">1</property>
- <property name="accelerator"><Ctrl>Down</property>
- <!-- Translators: Ctrl-Down shortcut description in the Keyboard Shortcuts dialog -->
- <property name="title" translatable="yes" context="shortcut window">Move all the pieces in
the left box down by one</property>
+ <property name="accelerator"><Ctrl>H</property>
+ <!-- Translators: Ctrl-H shortcut description in the Keyboard Shortcuts dialog -->
+ <property name="title" translatable="yes" context="shortcut window">Solve the game</property>
</object>
</child>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
- <property name="accelerator"><Ctrl>Left</property>
- <!-- Translators: Ctrl-Left shortcut description in the Keyboard Shortcuts dialog -->
- <property name="title" translatable="yes" context="shortcut window">Move all the pieces in
the left box left by one</property>
+ <property name="accelerator"><Ctrl>I</property>
+ <!-- Translators: Ctrl-I shortcut description in the Keyboard Shortcuts dialog -->
+ <property name="title" translatable="yes" context="shortcut window">Show scores</property>
</object>
</child>
+ </object>
+ </child>
+ <child>
+ <object class="GtkShortcutsGroup">
+ <property name="visible">1</property>
+ <!-- Translators: title of a section in the Keyboard Shortcuts dialog; contains "Show Help",
"Show Keyboard Shortcuts", "Quit"... -->
+ <property name="title" translatable="yes" context="shortcut window">Generic</property>
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
- <property name="accelerator"><Ctrl>Right</property>
- <!-- Translators: Ctrl-Right shortcut description in the Keyboard Shortcuts dialog -->
- <property name="title" translatable="yes" context="shortcut window">Move all the pieces in
the left box right by one</property>
+ <property name="accelerator"><Primary>question <Primary>F1</property>
+ <!-- Translators: Ctrl-F1 shortcut description in the Keyboard Shortcuts dialog; displays
Keyboard Shortcuts dialog -->
+ <property name="title" translatable="yes" context="shortcut window">Show Keyboard
Shortcuts</property>
</object>
</child>
<child>
@@ -68,9 +70,9 @@
<child>
<object class="GtkShortcutsShortcut">
<property name="visible">1</property>
- <property name="accelerator"><Primary>question</property>
- <!-- Translators: Ctrl-F1 shortcut description in the Keyboard Shortcuts dialog; displays
Keyboard Shortcuts dialog -->
- <property name="title" translatable="yes" context="shortcut window">Show Keyboard
Shortcuts</property>
+ <property name="accelerator"><Shift>F1</property>
+ <!-- Translators: Shift-F1 shortcut description in the Keyboard Shortcuts dialog; shows
About dialog -->
+ <property name="title" translatable="yes" context="shortcut window">Show About</property>
</object>
</child>
<child>
@@ -83,6 +85,45 @@
</child>
</object>
</child>
+ <child>
+ <object class="GtkShortcutsGroup">
+ <property name="visible">1</property>
+ <!-- Translators: title of a section in the Keyboard Shortcuts dialog; contains four keyboard
shortcuts for functions that help playing, but are not doable by mouse, so the "advanced" note... -->
+ <property name="title" translatable="yes" context="shortcut window">Advanced gameplay</property>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
+ <property name="accelerator"><Ctrl>Up</property>
+ <!-- Translators: Ctrl-Up shortcut description in the Keyboard Shortcuts dialog -->
+ <property name="title" translatable="yes" context="shortcut window">Move all the pieces in
the left box up by one</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
+ <property name="accelerator"><Ctrl>Down</property>
+ <!-- Translators: Ctrl-Down shortcut description in the Keyboard Shortcuts dialog -->
+ <property name="title" translatable="yes" context="shortcut window">Move all the pieces in
the left box down by one</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
+ <property name="accelerator"><Ctrl>Left</property>
+ <!-- Translators: Ctrl-Left shortcut description in the Keyboard Shortcuts dialog -->
+ <property name="title" translatable="yes" context="shortcut window">Move all the pieces in
the left box left by one</property>
+ </object>
+ </child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
+ <property name="accelerator"><Ctrl>Right</property>
+ <!-- Translators: Ctrl-Right shortcut description in the Keyboard Shortcuts dialog -->
+ <property name="title" translatable="yes" context="shortcut window">Move all the pieces in
the left box right by one</property>
+ </object>
+ </child>
+ </object>
+ </child>
</object>
</child>
</object>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]