[gnome-games/wip/exalm/preferences] ui: Simplify preferences page subpages
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/exalm/preferences] ui: Simplify preferences page subpages
- Date: Wed, 3 Jun 2020 12:11:08 +0000 (UTC)
commit e36638c0d8ff26d9739eb8e8ca776958d4d1e627
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Jun 3 17:07:18 2020 +0500
ui: Simplify preferences page subpages
Pass the window reference to the pages and allow them to open subpage by
just calling a method instead of setting a property that's bound to the
window for the current page.
data/ui/preferences-window.ui | 9 ++--
src/ui/preferences-page-controllers.vala | 15 +-----
src/ui/preferences-page.vala | 2 +-
src/ui/preferences-subpage-gamepad.vala | 2 -
src/ui/preferences-subpage-keyboard.vala | 2 -
src/ui/preferences-subpage.vala | 2 +
src/ui/preferences-window.vala | 83 ++++++++------------------------
7 files changed, 31 insertions(+), 84 deletions(-)
---
diff --git a/data/ui/preferences-window.ui b/data/ui/preferences-window.ui
index 413c11ac..bdf06c20 100644
--- a/data/ui/preferences-window.ui
+++ b/data/ui/preferences-window.ui
@@ -9,8 +9,8 @@
<child>
<object class="HdyDeck" id="deck">
<property name="visible">True</property>
- <signal name="notify::transition-running" handler="subpage_transition_finished"/>
- <signal name="notify::visible-child" handler="on_visible_child_changed"/>
+ <signal name="notify::transition-running" handler="try_remove_subpage"/>
+ <signal name="notify::visible-child" handler="try_remove_subpage"/>
<child>
<object class="GtkBox" id="main_box">
<property name="visible">True</property>
@@ -38,10 +38,10 @@
<property name="visible-child">video_page</property>
<property name="transition-type">crossfade</property>
<property name="width-request">300</property>
- <signal name="notify::visible-child" handler="update_ui"/>
<child>
<object class="GamesPreferencesPageVideo" id="video_page">
<property name="visible">True</property>
+ <property name="window">GamesPreferencesWindow</property>
</object>
<packing>
<property name="title" translatable="yes">Video</property>
@@ -51,6 +51,7 @@
<child>
<object class="GamesPreferencesPageControllers" id="controllers_page">
<property name="visible">True</property>
+ <property name="window">GamesPreferencesWindow</property>
</object>
<packing>
<property name="title" translatable="yes">Controllers</property>
@@ -60,6 +61,7 @@
<child>
<object class="GamesPreferencesPagePlatforms" id="platforms_page">
<property name="visible">True</property>
+ <property name="window">GamesPreferencesWindow</property>
</object>
<packing>
<property name="title" translatable="yes">Platforms</property>
@@ -69,6 +71,7 @@
<child>
<object class="GamesPreferencesPageImportExport" id="import_export_page">
<property name="visible">True</property>
+ <property name="window">GamesPreferencesWindow</property>
</object>
<packing>
<property name="title" translatable="yes">Import & Export</property>
diff --git a/src/ui/preferences-page-controllers.vala b/src/ui/preferences-page-controllers.vala
index 7bbdcb19..208301fd 100644
--- a/src/ui/preferences-page-controllers.vala
+++ b/src/ui/preferences-page-controllers.vala
@@ -9,8 +9,6 @@ private class Games.PreferencesPageControllers : PreferencesPage {
private Manette.Monitor monitor;
- private ulong back_handler_id;
-
construct {
monitor = new Manette.Monitor ();
monitor.device_connected.connect (rebuild_gamepad_list);
@@ -41,9 +39,7 @@ private class Games.PreferencesPageControllers : PreferencesPage {
var this_device = device;
row.activated.connect (() => {
- var subpage_gamepad = new PreferencesSubpageGamepad (this_device);
- back_handler_id = subpage_gamepad.back.connect (on_back);
- subpage = subpage_gamepad;
+ window.open_subpage (new PreferencesSubpageGamepad (this_device));
});
row.show_all ();
@@ -66,17 +62,10 @@ private class Games.PreferencesPageControllers : PreferencesPage {
row.activatable = true;
row.activated.connect (() => {
- var subpage_keyboard = new PreferencesSubpageKeyboard ();
- back_handler_id = subpage_keyboard.back.connect (on_back);
- subpage = subpage_keyboard;
+ window.open_subpage (new PreferencesSubpageKeyboard ());
});
row.show_all ();
keyboard_group.add (row);
}
-
- private void on_back () {
- subpage.disconnect (back_handler_id);
- subpage = null;
- }
}
diff --git a/src/ui/preferences-page.vala b/src/ui/preferences-page.vala
index 911996fe..98c1d0c9 100644
--- a/src/ui/preferences-page.vala
+++ b/src/ui/preferences-page.vala
@@ -2,7 +2,7 @@
[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page.ui")]
private class Games.PreferencesPage : Gtk.Bin, Gtk.Buildable {
- public PreferencesSubpage subpage { get; set; }
+ public PreferencesWindow window { get; construct; }
[GtkChild]
private Gtk.Label error_label;
diff --git a/src/ui/preferences-subpage-gamepad.vala b/src/ui/preferences-subpage-gamepad.vala
index 36b1019c..ecfe5bf8 100644
--- a/src/ui/preferences-subpage-gamepad.vala
+++ b/src/ui/preferences-subpage-gamepad.vala
@@ -31,8 +31,6 @@ private class Games.PreferencesSubpageGamepad : Gtk.Bin, PreferencesSubpage {
CONFIGURE,
}
- public signal void back ();
-
private State _state;
private State state {
set {
diff --git a/src/ui/preferences-subpage-keyboard.vala b/src/ui/preferences-subpage-keyboard.vala
index b2b6951c..e0857fd7 100644
--- a/src/ui/preferences-subpage-keyboard.vala
+++ b/src/ui/preferences-subpage-keyboard.vala
@@ -26,8 +26,6 @@ private class Games.PreferencesSubpageKeyboard : Gtk.Bin, PreferencesSubpage {
CONFIGURE,
}
- public signal void back ();
-
private State _state;
private State state {
get { return _state; }
diff --git a/src/ui/preferences-subpage.vala b/src/ui/preferences-subpage.vala
index 17cf3baf..e81b00e2 100644
--- a/src/ui/preferences-subpage.vala
+++ b/src/ui/preferences-subpage.vala
@@ -1,5 +1,7 @@
// This file is part of GNOME Games. License: GPL-3.0+.
private interface Games.PreferencesSubpage : Gtk.Widget {
+ public signal void back ();
+
public abstract bool allow_back { get; set; }
}
diff --git a/src/ui/preferences-window.vala b/src/ui/preferences-window.vala
index 0db7b341..04c78bac 100644
--- a/src/ui/preferences-window.vala
+++ b/src/ui/preferences-window.vala
@@ -8,82 +8,39 @@ private class Games.PreferencesWindow : Hdy.Window {
private Gtk.Box main_box;
[GtkChild]
private Gtk.Box subpage_box;
- [GtkChild]
- private Gtk.Stack stack;
-
- private PreferencesSubpage _subpage;
- public PreferencesSubpage subpage {
- get { return _subpage; }
- set {
- if (subpage == value)
- return;
-
- if (subpage != null) {
- deck.navigate (Hdy.NavigationDirection.BACK);
- swipe_back_binding.unbind ();
- }
-
- if (value != null) {
- subpage_box.add (value);
-
- swipe_back_binding = value.bind_property ("allow-back", deck,
- "can-swipe-back",
- BindingFlags.SYNC_CREATE);
-
- deck.navigate (Hdy.NavigationDirection.FORWARD);
- }
- _subpage = value;
- }
- }
-
- private Binding subpage_binding;
+ private PreferencesSubpage subpage;
private Binding swipe_back_binding;
- construct {
- update_ui ();
- }
-
[GtkCallback]
- private void update_ui () {
- var page = stack.visible_child as PreferencesPage;
-
- if (subpage_binding != null) {
- subpage_binding.unbind ();
- subpage_binding = null;
- }
-
- if (page == null) {
- subpage = null;
-
+ public void try_remove_subpage () {
+ if (deck.transition_running ||
+ deck.visible_child != main_box ||
+ subpage == null)
return;
- }
-
- subpage_binding = page.bind_property ("subpage", this, "subpage",
- BindingFlags.SYNC_CREATE | BindingFlags.BIDIRECTIONAL);
- }
- private void remove_subpage () {
- foreach (var child in subpage_box.get_children ())
- subpage_box.remove (child);
+ subpage_box.remove (subpage);
subpage = null;
}
- [GtkCallback]
- public void subpage_transition_finished () {
- if (deck.transition_running ||
- deck.visible_child != main_box)
+ public void open_subpage (PreferencesSubpage subpage) {
+ if (this.subpage != null)
return;
- remove_subpage ();
- }
+ this.subpage = subpage;
- [GtkCallback]
- private void on_visible_child_changed () {
- if (deck.transition_running || subpage == null)
- return;
+ swipe_back_binding = subpage.bind_property ("allow-back", deck,
+ "can-swipe-back",
+ BindingFlags.SYNC_CREATE);
+
+ subpage_box.add (subpage);
+
+ subpage.back.connect (() => {
+ deck.navigate (Hdy.NavigationDirection.BACK);
+ swipe_back_binding.unbind ();
+ });
- remove_subpage ();
+ deck.navigate (Hdy.NavigationDirection.FORWARD);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]