[gnome-games/wip/exalm/libhandy2: 8/22] ui: Convert GamepadConfigurer into a subpage



commit da7223839eeb91a0a81cc0d66d4db644d3e41557
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Wed Sep 12 01:42:57 2018 +0500

    ui: Convert GamepadConfigurer into a subpage
    
    Temporarily rename 'on_back()' function in PreferencePageControllers to
    'on_back_old()' because of a name clash.

 data/org.gnome.Games.gresource.xml                 |  2 +-
 ...onfigurer.ui => preferences-subpage-gamepad.ui} |  2 +-
 src/meson.build                                    |  2 +-
 src/ui/preferences-page-controllers.vala           | 22 +++++++++++-----------
 ...gurer.vala => preferences-subpage-gamepad.vala} | 11 ++++-------
 5 files changed, 18 insertions(+), 21 deletions(-)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index dc309b63..200140eb 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -22,7 +22,6 @@
     <file preprocess="xml-stripblanks">ui/empty-collection.ui</file>
     <file preprocess="xml-stripblanks">ui/error-display.ui</file>
     <file preprocess="xml-stripblanks">ui/error-info-bar.ui</file>
-    <file preprocess="xml-stripblanks">ui/gamepad-configurer.ui</file>
     <file preprocess="xml-stripblanks">ui/gamepad-mapper.ui</file>
     <file preprocess="xml-stripblanks">ui/gamepad-tester.ui</file>
     <file preprocess="xml-stripblanks">ui/game-icon-view.ui</file>
@@ -36,6 +35,7 @@
     <file preprocess="xml-stripblanks">ui/preferences-page-plugins.ui</file>
     <file preprocess="xml-stripblanks">ui/preferences-page-plugins-item.ui</file>
     <file preprocess="xml-stripblanks">ui/preferences-page-video.ui</file>
+    <file preprocess="xml-stripblanks">ui/preferences-subpage-gamepad.ui</file>
     <file preprocess="xml-stripblanks">ui/preferences-window.ui</file>
     <file preprocess="xml-stripblanks">ui/quit-dialog.ui</file>
     <file preprocess="xml-stripblanks">ui/remote-display.ui</file>
diff --git a/data/ui/gamepad-configurer.ui b/data/ui/preferences-subpage-gamepad.ui
similarity index 98%
rename from data/ui/gamepad-configurer.ui
rename to data/ui/preferences-subpage-gamepad.ui
index c02a8af2..78f93415 100644
--- a/data/ui/gamepad-configurer.ui
+++ b/data/ui/preferences-subpage-gamepad.ui
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="GamesGamepadConfigurer" parent="GtkBox">
+  <template class="GamesPreferencesSubpageGamepad" parent="GtkBox">
     <property name="visible">True</property>
     <property name="orientation">vertical</property>
     <child>
diff --git a/src/meson.build b/src/meson.build
index f1f5302a..f6bb3613 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -138,7 +138,6 @@ vala_sources = [
   'ui/error-display.vala',
   'ui/error-info-bar.vala',
   'ui/gamepad-browse.vala',
-  'ui/gamepad-configurer.vala',
   'ui/gamepad-mapper.vala',
   'ui/gamepad-tester.vala',
   'ui/gamepad-view.vala',
@@ -160,6 +159,7 @@ vala_sources = [
   'ui/preferences-page-plugins-item.vala',
   'ui/preferences-page-video.vala',
   'ui/preferences-subpage.vala',
+  'ui/preferences-subpage-gamepad.vala',
   'ui/preferences-window.vala',
   'ui/quit-dialog.vala',
   'ui/remote-display.vala',
diff --git a/src/ui/preferences-page-controllers.vala b/src/ui/preferences-page-controllers.vala
index ffdc5474..eba78ff8 100644
--- a/src/ui/preferences-page-controllers.vala
+++ b/src/ui/preferences-page-controllers.vala
@@ -37,7 +37,7 @@ private class Games.PreferencesPageControllers: Gtk.Stack, PreferencesPage {
        }
 
        public void visible_page_changed () {
-               on_back (null);
+               on_back_old (null);
        }
 
        private void rebuild_gamepad_list () {
@@ -81,14 +81,9 @@ private class Games.PreferencesPageControllers: Gtk.Stack, PreferencesPage {
                if (device == null)
                        return;
 
-               var configurer = new GamepadConfigurer (device);
-               back_handler_id = configurer.back.connect (on_back);
-               header_bar_binding = configurer.bind_property ("header-bar", this, "header-bar",
-                                                              BindingFlags.SYNC_CREATE);
-               immersive_mode_binding = configurer.bind_property ("immersive-mode", this, "immersive-mode",
-                                                                  BindingFlags.SYNC_CREATE);
-               extra_stack_child_holder.pack_start (configurer);
-               set_visible_child_name ("extra_stack_child");
+               var subpage_gamepad = new PreferencesSubpageGamepad (device);
+               back_handler_id = subpage_gamepad.back.connect (on_back);
+               subpage = subpage_gamepad;
        }
 
        private void build_keyboard_list () {
@@ -102,7 +97,7 @@ private class Games.PreferencesPageControllers: Gtk.Stack, PreferencesPage {
        [GtkCallback]
        private void keyboard_list_box_row_activated (Gtk.ListBoxRow row_item) {
                var configurer = new KeyboardConfigurer ();
-               back_handler_id = configurer.back.connect (on_back);
+               back_handler_id = configurer.back.connect (on_back_old);
                header_bar_binding = configurer.bind_property ("header-bar", this, "header-bar",
                                                               BindingFlags.SYNC_CREATE);
                immersive_mode_binding = configurer.bind_property ("immersive-mode", this, "immersive-mode",
@@ -111,7 +106,12 @@ private class Games.PreferencesPageControllers: Gtk.Stack, PreferencesPage {
                visible_child_name = "extra_stack_child";
        }
 
-       private void on_back (Object? emitter) {
+       private void on_back () {
+               subpage.disconnect (back_handler_id);
+               subpage = null;
+       }
+
+       private void on_back_old (Object? emitter) {
                header_bar_binding = null;
                immersive_mode_binding = null;
                if (back_handler_id != 0) {
diff --git a/src/ui/gamepad-configurer.vala b/src/ui/preferences-subpage-gamepad.vala
similarity index 95%
rename from src/ui/gamepad-configurer.vala
rename to src/ui/preferences-subpage-gamepad.vala
index d60f33c6..5ac7460d 100644
--- a/src/ui/gamepad-configurer.vala
+++ b/src/ui/preferences-subpage-gamepad.vala
@@ -1,7 +1,7 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
-[GtkTemplate (ui = "/org/gnome/Games/ui/gamepad-configurer.ui")]
-private class Games.GamepadConfigurer : Gtk.Box {
+[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-subpage-gamepad.ui")]
+private class Games.PreferencesSubpageGamepad: Gtk.Box, PreferencesSubpage {
        private const GamepadInput[] STANDARD_GAMEPAD_INPUTS = {
                { EventCode.EV_KEY, EventCode.BTN_A },
                { EventCode.EV_KEY, EventCode.BTN_B },
@@ -65,9 +65,9 @@ private class Games.GamepadConfigurer : Gtk.Box {
        private State state {
                set {
                        _state = value;
-                       immersive_mode = (state == State.CONFIGURE);
                        back_button.visible = (state == State.TEST);
                        cancel_button.visible = (state == State.CONFIGURE);
+                       header_bar.show_close_button = (state == State.TEST);
 
                        switch (value) {
                        case State.TEST:
@@ -104,12 +104,9 @@ private class Games.GamepadConfigurer : Gtk.Box {
        [GtkChild (name = "header_bar")]
        private Gtk.HeaderBar _header_bar;
        public Gtk.HeaderBar header_bar {
-               private set {}
                get { return _header_bar; }
        }
 
-       public bool immersive_mode { private set; get; }
-
        [GtkChild]
        private Gtk.Stack gamepad_view_stack;
        [GtkChild]
@@ -133,7 +130,7 @@ private class Games.GamepadConfigurer : Gtk.Box {
 
        private Binding info_message_binding;
 
-       public GamepadConfigurer (Manette.Device device) {
+       public PreferencesSubpageGamepad (Manette.Device device) {
                this.device = device;
                mapper = new GamepadMapper (device, STANDARD_GAMEPAD_VIEW_CONFIGURATION, 
STANDARD_GAMEPAD_INPUTS);
                gamepad_view_stack.add (mapper);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]