[gnome-games] display-view: Convert showing snapshots to an action
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games] display-view: Convert showing snapshots to an action
- Date: Tue, 28 Jan 2020 14:09:27 +0000 (UTC)
commit 0abf19cbd2a60c5ce8fdbf460061c61dcc8b0512
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Tue Jan 28 19:03:56 2020 +0500
display-view: Convert showing snapshots to an action
data/ui/display-header-bar.ui | 4 ++--
src/ui/display-header-bar.vala | 8 --------
src/ui/display-view.vala | 28 ++++++++++++++++++++++++----
3 files changed, 26 insertions(+), 14 deletions(-)
---
diff --git a/data/ui/display-header-bar.ui b/data/ui/display-header-bar.ui
index a70c27cb..584378a2 100644
--- a/data/ui/display-header-bar.ui
+++ b/data/ui/display-header-bar.ui
@@ -198,10 +198,10 @@
</object>
</child>
<child>
- <object class="GtkModelButton" id="savestates_menu_button">
+ <object class="GtkModelButton">
<property name="visible">True</property>
<property name="text" translatable="yes">_Snapshots</property>
- <signal name="clicked" handler="on_secondary_menu_savestates_clicked"/>
+ <property name="action-name">display.show-snapshots</property>
</object>
</child>
</object>
diff --git a/src/ui/display-header-bar.vala b/src/ui/display-header-bar.vala
index e83c7779..b190b480 100644
--- a/src/ui/display-header-bar.vala
+++ b/src/ui/display-header-bar.vala
@@ -39,7 +39,6 @@ private class Games.DisplayHeaderBar : Gtk.Bin {
extra_widget = runner.get_extra_widget ();
secondary_menu_button.visible = runner.is_integrated;
- savestates_menu_button.sensitive = runner.supports_savestates;
}
else
extra_widget = null;
@@ -74,8 +73,6 @@ private class Games.DisplayHeaderBar : Gtk.Bin {
[GtkChild]
private Gtk.MenuButton secondary_menu_button;
[GtkChild]
- private Gtk.ModelButton savestates_menu_button;
- [GtkChild]
private Gtk.HeaderBar savestates_header_bar;
private Settings settings;
@@ -111,11 +108,6 @@ private class Games.DisplayHeaderBar : Gtk.Bin {
settings.set_boolean ("fullscreen", false);
}
- [GtkCallback]
- private void on_secondary_menu_savestates_clicked () {
- is_showing_snapshots = true;
- }
-
[GtkCallback]
private void on_showing_snapshots_changed () {
if (is_showing_snapshots)
diff --git a/src/ui/display-view.vala b/src/ui/display-view.vala
index 378955d4..50d61aae 100644
--- a/src/ui/display-view.vala
+++ b/src/ui/display-view.vala
@@ -32,6 +32,8 @@ private class Games.DisplayView : Object, UiView {
box.runner.stop ();
box.runner = null;
}
+
+ update_actions ();
}
}
}
@@ -52,9 +54,11 @@ private class Games.DisplayView : Object, UiView {
private long focus_out_timeout_id;
+ private SimpleActionGroup action_group;
private const ActionEntry[] action_entries = {
- { "load-snapshot", load_snapshot },
- { "restart", restart },
+ { "load-snapshot", load_snapshot },
+ { "show-snapshots", show_snapshots },
+ { "restart", restart },
};
public DisplayView (Gtk.Window window) {
@@ -84,7 +88,7 @@ private class Games.DisplayView : Object, UiView {
focus_out_timeout_id = -1;
- var action_group = new SimpleActionGroup ();
+ action_group = new SimpleActionGroup ();
action_group.add_action_entries (action_entries, this);
window.insert_action_group ("display", action_group);
}
@@ -150,7 +154,7 @@ private class Games.DisplayView : Object, UiView {
if (((keyval == Gdk.Key.a || keyval == Gdk.Key.A) && ctrl_pressed) ||
(keyval == Gdk.Key.F4)) {
- is_showing_snapshots = true;
+ show_snapshots ();
return true;
}
@@ -294,6 +298,8 @@ private class Games.DisplayView : Object, UiView {
header_bar.media_set = runner.media_set;
box.header_bar.media_set = runner.media_set;
+ update_actions ();
+
is_fullscreen = settings.get_boolean ("fullscreen") && runner.can_fullscreen;
if (!runner.can_resume) {
@@ -492,6 +498,8 @@ private class Games.DisplayView : Object, UiView {
box.runner = null;
header_bar.media_set = null;
box.header_bar.media_set = null;
+
+ update_actions ();
}
public void on_snapshots_hidden () {
@@ -545,6 +553,13 @@ private class Games.DisplayView : Object, UiView {
return true;
}
+ private void update_actions () {
+ var runner = box.runner;
+
+ var action = action_group.lookup_action ("show-snapshots") as SimpleAction;
+ action.set_enabled (runner != null && runner.supports_savestates);
+ }
+
private void load_snapshot () {
try {
box.runner.load_previewed_savestate ();
@@ -556,6 +571,11 @@ private class Games.DisplayView : Object, UiView {
is_showing_snapshots = false;
}
+ private void show_snapshots () {
+ if (box.runner != null && box.runner.is_integrated)
+ is_showing_snapshots = true;
+ }
+
private void restart () {
if (box.runner != null && box.runner.is_integrated)
box.runner.restart ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]