[gnome-games/wip/abhinavsingh/gamepad-config: 34/35] ui: Allow PreferencesPage to show custom headers
- From: Abhinav Singh <abhinavsingh src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-games/wip/abhinavsingh/gamepad-config: 34/35] ui: Allow PreferencesPage to show custom headers
- Date: Tue, 18 Jul 2017 11:36:42 +0000 (UTC)
commit 2d5728479de8fee2908e87f4ab6f017b18a57299
Author: theawless <theawless gmail com>
Date: Tue Jul 18 15:46:29 2017 +0530
ui: Allow PreferencesPage to show custom headers
This will allow the PreferencesPages to show widgets in the header bar.
src/ui/preferences-page-plugins.vala | 13 +++++++++-
src/ui/preferences-page-video.vala | 13 +++++++++-
src/ui/preferences-page.vala | 5 +++-
src/ui/preferences-window.vala | 45 +++++++++++++++++++++++++++++----
4 files changed, 67 insertions(+), 9 deletions(-)
---
diff --git a/src/ui/preferences-page-plugins.vala b/src/ui/preferences-page-plugins.vala
index 16500b8..ab85970 100644
--- a/src/ui/preferences-page-plugins.vala
+++ b/src/ui/preferences-page-plugins.vala
@@ -2,8 +2,19 @@
[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-plugins.ui")]
private class Games.PreferencesPagePlugins: Gtk.Bin, PreferencesPage {
- public string title {
+ public Gtk.Widget? custom_title {
+ get { return null; }
+ protected set {}
+ }
+
+ public string? subtitle {
+ get { return null; }
+ protected set {}
+ }
+
+ public string? title {
get { return _("Extensions"); }
+ protected set {}
}
[GtkChild]
diff --git a/src/ui/preferences-page-video.vala b/src/ui/preferences-page-video.vala
index 7754e59..0829031 100644
--- a/src/ui/preferences-page-video.vala
+++ b/src/ui/preferences-page-video.vala
@@ -2,8 +2,19 @@
[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-video.ui")]
private class Games.PreferencesPageVideo: Gtk.Bin, PreferencesPage {
- public string title {
+ public Gtk.Widget? custom_title {
+ get { return null; }
+ protected set {}
+ }
+
+ public string? subtitle {
+ get { return null; }
+ protected set {}
+ }
+
+ public string? title {
get { return _("Video"); }
+ protected set {}
}
private string _filter_active;
diff --git a/src/ui/preferences-page.vala b/src/ui/preferences-page.vala
index 14b2170..b3d8445 100644
--- a/src/ui/preferences-page.vala
+++ b/src/ui/preferences-page.vala
@@ -1,5 +1,8 @@
// This file is part of GNOME Games. License: GPL-3.0+.
private interface Games.PreferencesPage: Gtk.Widget {
- public abstract string title { get; }
+ public abstract Gtk.Widget? custom_title { set; protected get; }
+ public abstract string? subtitle { set; protected get; }
+ public abstract string? title { set; protected get; }
+ public virtual void visible_page_changed () {}
}
diff --git a/src/ui/preferences-window.vala b/src/ui/preferences-window.vala
index 3d1bc0b..2ee0aa8 100644
--- a/src/ui/preferences-window.vala
+++ b/src/ui/preferences-window.vala
@@ -7,17 +7,50 @@ private class Games.PreferencesWindow : Gtk.Window {
[GtkChild]
private Gtk.Stack stack;
+ Binding right_header_bar_custom_title_binding;
+ Binding right_header_bar_subtitle_binding;
+ Binding right_header_bar_title_binding;
+
public PreferencesWindow () {
stack.foreach ((child) => {
- var page = child as PreferencesPage;
- page.notify["title"].connect (update_title);
+ var page = (PreferencesPage) child;
+ stack.notify["visible-child-name"].connect (page.visible_page_changed);
});
- stack.notify["visible-child-name"].connect (update_title);
- update_title ();
+ stack.notify["visible-child-name"].connect (update_right_header);
+ update_right_header ();
}
- private void update_title () {
+ private void update_right_header () {
+ reset_right_header_bindings ();
+
var page = (PreferencesPage) stack.get_visible_child ();
- right_header_bar.title = (page == null) ? "" : page.title;
+ if (page == null) {
+ right_header_bar.custom_title = null;
+ right_header_bar.subtitle = null;
+ right_header_bar.title = null;
+
+ return;
+ }
+ right_header_bar_custom_title_binding = page.bind_property ("custom-title", right_header_bar,
"custom-title",
+ BindingFlags.SYNC_CREATE);
+ right_header_bar_subtitle_binding = page.bind_property ("subtitle", right_header_bar,
"subtitle",
+ BindingFlags.SYNC_CREATE);
+ right_header_bar_title_binding = page.bind_property ("title", right_header_bar, "title",
+ BindingFlags.SYNC_CREATE);
+ }
+
+ private void reset_right_header_bindings () {
+ if (right_header_bar_custom_title_binding != null) {
+ right_header_bar_custom_title_binding.unbind ();
+ right_header_bar_custom_title_binding = null;
+ }
+ if (right_header_bar_subtitle_binding != null) {
+ right_header_bar_subtitle_binding.unbind ();
+ right_header_bar_subtitle_binding = null;
+ }
+ if (right_header_bar_title_binding != null) {
+ right_header_bar_title_binding.unbind ();
+ right_header_bar_title_binding = null;
+ }
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]