[gnome-tetravex] Add reload shortcut.
- From: Arnaud B. <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-tetravex] Add reload shortcut.
- Date: Fri, 12 Jun 2020 16:12:46 +0000 (UTC)
commit bab79e0ff3fce11266b0f9b7caec343e0e64f91e
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri Jun 12 18:10:36 2020 +0200
Add reload shortcut.
src/gnome-tetravex.vala | 10 ++++++++++
src/help-overlay.ui | 10 +++++++++-
src/puzzle-view.vala | 6 ++++++
src/puzzle.vala | 25 +++++++++++++++++++++++++
4 files changed, 50 insertions(+), 1 deletion(-)
---
diff --git a/src/gnome-tetravex.vala b/src/gnome-tetravex.vala
index 7f888f7..b6d70d4 100644
--- a/src/gnome-tetravex.vala
+++ b/src/gnome-tetravex.vala
@@ -123,6 +123,7 @@ private class Tetravex : Gtk.Application
{ "move-right-r", move_right_r },
{ "undo", undo_cb },
{ "redo", redo_cb },
+ { "reload", reload_cb },
{ "size", null, "s", "'2'", size_changed },
{ "help", help_cb },
{ "about", about_cb },
@@ -284,6 +285,7 @@ private class Tetravex : Gtk.Application
set_accels_for_action ("app.move-right-r", { "<Shift><Primary>Right" });
set_accels_for_action ("app.undo", { "<Primary>z" });
set_accels_for_action ("app.redo", { "<Shift><Primary>z" });
+ set_accels_for_action ("app.reload", { "<Shift><Primary>r" });
set_accels_for_action ("app.hamburger", { "F10" });
// F1 and friends are managed manually
@@ -901,6 +903,14 @@ private class Tetravex : Gtk.Application
view.redo ();
}
+ private void reload_cb ()
+ {
+ if (view.tile_selected)
+ view.release_selected_tile ();
+ else
+ view.reload ();
+ }
+
private void pause_cb (/* SimpleAction action, Variant? parameter */)
{
puzzle.paused = !puzzle.paused;
diff --git a/src/help-overlay.ui b/src/help-overlay.ui
index 230c3c4..274270f 100644
--- a/src/help-overlay.ui
+++ b/src/help-overlay.ui
@@ -2,7 +2,7 @@
<!--
This file is part of GNOME Tetravex.
- Copyright (C) 2019 Arnaud Bonatti
+ Copyright (C) 2019-2020 Arnaud Bonatti
GNOME Tetravex is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -101,6 +101,14 @@
<property name="title" translatable="yes" context="shortcut window">Redo</property>
</object>
</child>
+ <child>
+ <object class="GtkShortcutsShortcut">
+ <property name="visible">1</property>
+ <property name="accelerator"><Shift><Primary>r</property>
+ <!-- Translators: Shift-Ctrl-R shortcut description in the Keyboard Shortcuts dialog,
section History; undoes all the moves -->
+ <property name="title" translatable="yes" context="shortcut window">Reload initial
position</property>
+ </object>
+ </child>
</object>
</child>
<child>
diff --git a/src/puzzle-view.vala b/src/puzzle-view.vala
index 6903bb8..4d75d6f 100644
--- a/src/puzzle-view.vala
+++ b/src/puzzle-view.vala
@@ -858,6 +858,12 @@ private class PuzzleView : Gtk.DrawingArea
puzzle.redo ();
}
+ internal void reload ()
+ {
+ last_selected_tile = null;
+ puzzle.reload ();
+ }
+
/*\
* * final animation
\*/
diff --git a/src/puzzle.vala b/src/puzzle.vala
index 1666381..218b590 100644
--- a/src/puzzle.vala
+++ b/src/puzzle.vala
@@ -745,6 +745,31 @@ private class Puzzle : Object
_switch_tiles (x0, y0, x1, y1, animation_duration, /* no log */ true, /* garbage */ 0);
}
+ internal void reload ()
+ {
+ if (!can_undo)
+ return;
+
+ unowned List<Inversion>? inversion_item = reversed_history.nth (last_move_index);
+ if (inversion_item == null) assert_not_reached ();
+
+ unowned Inversion? inversion;
+ do
+ {
+ inversion = ((!) inversion_item).data;
+ if (inversion == null) assert_not_reached ();
+
+ undo_move (((!) inversion).x0, ((!) inversion).y0,
+ ((!) inversion).x1, ((!) inversion).y1);
+
+ inversion_item = ((!) inversion_item).next;
+ }
+ while (inversion_item != null);
+
+ can_undo = false;
+ can_redo = true;
+ }
+
/*\
* * save and restore
\*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]