[gnome-games/wip/exalm/savestates: 2/5] display-view: Make loading snapshot an action
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/savestates: 2/5] display-view: Make loading snapshot an action
- Date: Sun, 26 Jan 2020 19:23:40 +0000 (UTC)
commit 74e75abdcede8220fc50b0bcbd14a85d2a463de3
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sun Jan 26 23:21:48 2020 +0500
display-view: Make loading snapshot an action
This allows to remove another signal and a property from
SavestatesListState.
data/ui/display-header-bar.ui | 4 +--
src/ui/display-header-bar.vala | 12 ---------
src/ui/display-view.vala | 19 +++++++++++++
src/ui/savestates-list-state.vala | 2 --
src/ui/savestates-list.vala | 56 ++++++++++++++++-----------------------
5 files changed, 44 insertions(+), 49 deletions(-)
---
diff --git a/data/ui/display-header-bar.ui b/data/ui/display-header-bar.ui
index c9846b64..91551d76 100644
--- a/data/ui/display-header-bar.ui
+++ b/data/ui/display-header-bar.ui
@@ -131,13 +131,13 @@
<object class="GtkHeaderBar" id="savestates_header_bar">
<property name="visible">True</property>
<child>
- <object class="GtkButton" id="savestates_load_btn">
+ <object class="GtkButton">
<property name="sensitive">False</property>
<property name="visible">True</property>
<property name="valign">center</property>
<property name="use-underline">True</property>
<property name="label" translatable="yes">_Load</property>
- <signal name="clicked" handler="on_savestates_load_clicked"/>
+ <property name="action-name">display.load-snapshot</property>
<style>
<class name="suggested-action"/>
</style>
diff --git a/src/ui/display-header-bar.vala b/src/ui/display-header-bar.vala
index 859aed55..e735a392 100644
--- a/src/ui/display-header-bar.vala
+++ b/src/ui/display-header-bar.vala
@@ -15,7 +15,6 @@ private class Games.DisplayHeaderBar : Gtk.Bin {
if (value != null)
value.notify["is-revealed"].connect (on_savestates_list_revealed_changed);
- value.notify["selected-savestate"].connect (on_selected_savestate_changed);
}
}
@@ -86,8 +85,6 @@ private class Games.DisplayHeaderBar : Gtk.Bin {
private Gtk.MenuButton secondary_menu_button;
[GtkChild]
private Gtk.HeaderBar savestates_header_bar;
- [GtkChild]
- private Gtk.Button savestates_load_btn;
private Settings settings;
@@ -131,19 +128,10 @@ private class Games.DisplayHeaderBar : Gtk.Bin {
savestates_list_state.is_revealed = true;
}
- [GtkCallback]
- private void on_savestates_load_clicked () {
- savestates_list_state.load_clicked ();
- }
-
private void on_savestates_list_revealed_changed () {
if (savestates_list_state.is_revealed)
stack.visible_child = savestates_header_bar;
else
stack.visible_child = ingame_header_bar;
}
-
- private void on_selected_savestate_changed () {
- savestates_load_btn.sensitive = (savestates_list_state.selected_savestate != null);
- }
}
diff --git a/src/ui/display-view.vala b/src/ui/display-view.vala
index 29e5a9db..33fc4e44 100644
--- a/src/ui/display-view.vala
+++ b/src/ui/display-view.vala
@@ -53,6 +53,10 @@ private class Games.DisplayView : Object, UiView {
private long focus_out_timeout_id;
+ private const ActionEntry[] action_entries = {
+ { "load-snapshot", load_snapshot },
+ };
+
public DisplayView (Gtk.Window window) {
Object (window: window);
}
@@ -75,6 +79,10 @@ private class Games.DisplayView : Object, UiView {
"is-fullscreen", BindingFlags.BIDIRECTIONAL);
focus_out_timeout_id = -1;
+
+ var action_group = new SimpleActionGroup ();
+ action_group.add_action_entries (action_entries, this);
+ window.insert_action_group ("display", action_group);
}
public bool on_button_pressed (Gdk.EventButton event) {
@@ -532,4 +540,15 @@ private class Games.DisplayView : Object, UiView {
return true;
}
+
+ private void load_snapshot () {
+ try {
+ box.runner.load_previewed_savestate ();
+ }
+ catch (Error e) {
+ critical ("Failed to load snapshot: %s", e.message);
+ }
+
+ savestates_list_state.is_revealed = false;
+ }
}
diff --git a/src/ui/savestates-list-state.vala b/src/ui/savestates-list-state.vala
index 546da1af..a9518fa2 100644
--- a/src/ui/savestates-list-state.vala
+++ b/src/ui/savestates-list-state.vala
@@ -1,7 +1,5 @@
private class Games.SavestatesListState : Object {
- public signal void load_clicked ();
public signal void delete_clicked ();
public bool is_revealed { get; set; }
- public Savestate? selected_savestate { get; set; }
}
diff --git a/src/ui/savestates-list.vala b/src/ui/savestates-list.vala
index e2435cbc..d43f83f8 100644
--- a/src/ui/savestates-list.vala
+++ b/src/ui/savestates-list.vala
@@ -26,6 +26,8 @@ private class Games.SavestatesList : Gtk.Box {
[GtkChild]
private Gtk.Label rename_error_label;
+ private Savestate selected_savestate;
+
private SavestatesListState _state;
public SavestatesListState state {
get { return _state; }
@@ -37,7 +39,6 @@ private class Games.SavestatesList : Gtk.Box {
if (value != null) {
value.notify["is-revealed"].connect (on_revealed_changed);
- value.load_clicked.connect (on_load_clicked);
value.delete_clicked.connect (on_delete_clicked);
}
}
@@ -61,7 +62,7 @@ private class Games.SavestatesList : Gtk.Box {
var savestate_row = row as SavestateListBoxRow;
var savestate = savestate_row.savestate;
- if (savestate != state.selected_savestate)
+ if (savestate != selected_savestate)
select_savestate_row (row);
}
}
@@ -110,29 +111,6 @@ private class Games.SavestatesList : Gtk.Box {
}
}
- private void on_load_clicked () {
- if (!try_runner_load_previewed_savestate ()) {
- // TODO: Here we could show a dialog with one button like
- // "Failed to load snapshot [Ok]"
- }
-
- state.is_revealed = false;
- }
-
- private bool try_runner_load_previewed_savestate () {
- try {
- _runner.load_previewed_savestate ();
- }
- catch (Error e) {
- critical ("Failed to load snapshot: %s", e.message);
-
- return false;
- }
-
- // Nothing went wrong
- return true;
- }
-
private void on_revealed_changed () {
revealer.reveal_child = state.is_revealed;
@@ -194,7 +172,7 @@ private class Games.SavestatesList : Gtk.Box {
ensure_row_is_visible (selected_row);
- rename_entry.text = state.selected_savestate.name;
+ rename_entry.text = selected_savestate.name;
rename_popover.relative_to = selected_row;
rename_popover.popup ();
}
@@ -277,12 +255,23 @@ private class Games.SavestatesList : Gtk.Box {
}
}
+ private SimpleAction lookup_action (string name) {
+ var group = get_action_group ("display") as ActionMap;
+ assert (group != null);
+
+ var action = group.lookup_action (name);
+ assert (action is SimpleAction);
+
+ return action as SimpleAction;
+ }
+
private void select_savestate_row (Gtk.ListBoxRow? row) {
list_box.select_row (row);
if (row == null) {
runner.preview_current_state ();
- state.selected_savestate = null;
+ selected_savestate = null;
+ lookup_action ("load-snapshot").set_enabled (false);
}
else {
row.grab_focus ();
@@ -293,18 +282,19 @@ private class Games.SavestatesList : Gtk.Box {
var savestate_row = row as SavestateListBoxRow;
var savestate = savestate_row.savestate;
- if (savestate == state.selected_savestate) {
- on_load_clicked ();
+ if (savestate == selected_savestate) {
+ lookup_action ("load-snapshot").activate (null);
return;
}
runner.preview_savestate (savestate);
- state.selected_savestate = savestate;
+ selected_savestate = savestate;
+ lookup_action ("load-snapshot").set_enabled (true);
}
- delete_btn.sensitive = (state.selected_savestate != null);
- rename_btn.sensitive = (state.selected_savestate != null &&
- !state.selected_savestate.is_automatic);
+ delete_btn.sensitive = (selected_savestate != null);
+ rename_btn.sensitive = (selected_savestate != null &&
+ !selected_savestate.is_automatic);
}
public bool on_key_press_event (uint keyval, Gdk.ModifierType state) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]