Commit 0bfb8f3a authored by AndreiLisita's avatar AndreiLisita 🎮

display-header-bar: Make load and delete buttons insensitive if there's no savestate selected

parent c044570f
Pipeline #103406 passed with stages
in 14 minutes and 48 seconds
......@@ -134,7 +134,8 @@
<object class="GtkHeaderBar" id="savestates_header_bar">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="load">
<object class="GtkButton" id="savestates_load_btn">
<property name="sensitive">False</property>
<property name="visible">True</property>
<property name="valign">center</property>
<property name="use-underline">True</property>
......@@ -149,7 +150,8 @@
</packing>
</child>
<child>
<object class="GtkButton" id="delete">
<object class="GtkButton" id="savestates_delete_btn">
<property name="sensitive">False</property>
<property name="visible">True</property>
<property name="valign">center</property>
<property name="use-underline">True</property>
......@@ -208,8 +210,8 @@
<object class="GtkSizeGroup">
<property name="mode">GTK_SIZE_GROUP_HORIZONTAL</property>
<widgets>
<widget name="load"/>
<widget name="delete"/>
<widget name="savestates_load_btn"/>
<widget name="savestates_delete_btn"/>
</widgets>
</object>
</interface>
......@@ -13,7 +13,7 @@ private class Games.DisplayBox : Gtk.Bin {
public SavestatesListState savestates_list_state {
get { return savestates_list.state; }
set {
value.notify["is-revealed"].connect (on_savestates_list_state_changed);
value.notify["is-revealed"].connect (on_savestates_list_revealed_changed);
savestates_list.state = value;
fullscreen_header_bar.savestates_list_state = value;
......@@ -115,7 +115,7 @@ private class Games.DisplayBox : Gtk.Bin {
return runner.gamepad_button_press_event (button);
}
public void on_savestates_list_state_changed () {
public void on_savestates_list_revealed_changed () {
fullscreen_box.autohide = !savestates_list.state.is_revealed;
}
}
......@@ -14,7 +14,8 @@ private class Games.DisplayHeaderBar : Gtk.Stack {
_savestates_list_state = value;
if (value != null)
value.notify["is-revealed"].connect (on_savestates_list_state_changed);
value.notify["is-revealed"].connect (on_savestates_list_revealed_changed);
value.notify["selected-savestate"].connect (on_selected_savestate_changed);
}
}
......@@ -83,6 +84,10 @@ private class Games.DisplayHeaderBar : Gtk.Stack {
private Gtk.MenuButton secondary_menu_button;
[GtkChild]
private Gtk.HeaderBar savestates_header_bar;
[GtkChild]
private Gtk.Button savestates_load_btn;
[GtkChild]
private Gtk.Button savestates_delete_btn;
private Settings settings;
......@@ -141,10 +146,15 @@ private class Games.DisplayHeaderBar : Gtk.Stack {
savestates_list_state.is_revealed = false;
}
private void on_savestates_list_state_changed () {
private void on_savestates_list_revealed_changed () {
if (savestates_list_state.is_revealed)
set_visible_child (savestates_header_bar);
else
set_visible_child (ingame_header_bar);
}
private void on_selected_savestate_changed () {
savestates_load_btn.sensitive = (savestates_list_state.selected_savestate != null);
savestates_delete_btn.sensitive = (savestates_list_state.selected_savestate != null);
}
}
......@@ -3,4 +3,5 @@ private class Games.SavestatesListState : Object {
public signal void delete_clicked ();
public bool is_revealed { get; set; }
public Savestate? selected_savestate { get; set; }
}
......@@ -70,7 +70,7 @@ private class Games.SavestatesList : Gtk.Box {
var savestate_row = new SavestateListBoxRow (savestate);
list_box.insert (savestate_row, 1);
select_and_preview_row (savestate_row);
select_savestate_row (savestate_row);
}
else {
// Savestate creation failed
......@@ -79,12 +79,8 @@ private class Games.SavestatesList : Gtk.Box {
// TODO: Perhaps we should warn the user that the creation of
// the savestate failed via an in-app notification ?
}
} else {
var savestate_row = activated_row as SavestateListBoxRow;
var savestate = savestate_row.savestate;
runner.preview_savestate (savestate);
}
} else
select_savestate_row (activated_row);
}
private void on_load_clicked () {
......@@ -114,9 +110,10 @@ private class Games.SavestatesList : Gtk.Box {
revealer.reveal_child = state.is_revealed;
if (state.is_revealed) {
list_box.select_row (null);
runner.capture_current_state_pixbuf ();
runner.pause ();
select_savestate_row (null);
}
else
runner.resume ();
......@@ -139,19 +136,19 @@ private class Games.SavestatesList : Gtk.Box {
if (nr_rows == 1) {
// The only remaining row in the list is the create savestate one
runner.preview_current_state ();
select_savestate_row (null);
}
else {
// The last row of the list has been deleted but there are still
// rows remaining in the list
var last_row = list_box.get_row_at_index (selected_row_index - 1);
select_and_preview_row (last_row);
select_savestate_row (last_row);
}
return;
}
select_and_preview_row (next_row);
select_savestate_row (next_row);
}
private void update_header (Gtk.ListBoxRow row, Gtk.ListBoxRow? before) {
......@@ -161,11 +158,19 @@ private class Games.SavestatesList : Gtk.Box {
}
}
private void select_and_preview_row (Gtk.ListBoxRow row) {
var savestate_row = row as SavestateListBoxRow;
var savestate = savestate_row.savestate;
private void select_savestate_row (Gtk.ListBoxRow? row) {
if (row == null) {
list_box.select_row (null);
runner.preview_current_state ();
state.selected_savestate = null;
}
else {
var savestate_row = row as SavestateListBoxRow;
var savestate = savestate_row.savestate;
list_box.select_row (row);
runner.preview_savestate (savestate);
list_box.select_row (row);
runner.preview_savestate (savestate);
state.selected_savestate = savestate;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment