[gnome-games/wip/exalm/controller-preferences] ui: Convert KeyboardConfigurer to PreferencesSubpageKeyboard



commit 963af7ba69d5e36bdeda125e9e6448b9a461391c
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Wed Sep 12 01:50:10 2018 +0500

    ui: Convert KeyboardConfigurer to PreferencesSubpageKeyboard

 data/org.gnome.Games.gresource.xml                 |  2 +-
 data/ui/preferences-page-controllers.ui            | 19 ++------
 ...nfigurer.ui => preferences-subpage-keyboard.ui} |  2 +-
 src/meson.build                                    |  2 +-
 src/ui/preferences-page-controllers.vala           | 55 +++++++---------------
 ...urer.vala => preferences-subpage-keyboard.vala} | 12 ++---
 6 files changed, 26 insertions(+), 66 deletions(-)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 200140eb..b9f080cb 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -25,7 +25,6 @@
     <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>
-    <file preprocess="xml-stripblanks">ui/keyboard-configurer.ui</file>
     <file preprocess="xml-stripblanks">ui/keyboard-mapper.ui</file>
     <file preprocess="xml-stripblanks">ui/keyboard-tester.ui</file>
     <file preprocess="xml-stripblanks">ui/media-menu-button.ui</file>
@@ -36,6 +35,7 @@
     <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-subpage-keyboard.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/preferences-page-controllers.ui b/data/ui/preferences-page-controllers.ui
index bc39e828..486d9582 100644
--- a/data/ui/preferences-page-controllers.ui
+++ b/data/ui/preferences-page-controllers.ui
@@ -1,19 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="GamesPreferencesPageControllers" parent="GtkStack">
+  <template class="GamesPreferencesPageControllers" parent="GtkBin">
     <property name="visible">True</property>
-    <property name="visible-child">main_stack_child_holder</property>
-    <property name="transition-type">GTK_STACK_TRANSITION_TYPE_SLIDE_LEFT_RIGHT</property>
     <child>
-      <object class="GtkBox" id="extra_stack_child_holder">
-        <property name="visible">True</property>
-      </object>
-      <packing>
-        <property name="name">extra_stack_child</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkScrolledWindow" id="main_stack_child_holder">
+      <object class="GtkScrolledWindow">
         <property name="visible">True</property>
         <child>
           <object class="GtkViewport">
@@ -75,12 +65,9 @@
           </object>
         </child>
       </object>
-      <packing>
-        <property name="name">main_stack_child</property>
-      </packing>
     </child>
   </template>
-  <object class="GtkHeaderBar" id="default_header_bar">
+  <object class="GtkHeaderBar" id="header_bar">
     <property name="visible">True</property>
     <property name="expand">True</property>
     <property name="title" translatable="yes">Controllers</property>
diff --git a/data/ui/keyboard-configurer.ui b/data/ui/preferences-subpage-keyboard.ui
similarity index 98%
rename from data/ui/keyboard-configurer.ui
rename to data/ui/preferences-subpage-keyboard.ui
index 1f05ec60..a70d9718 100644
--- a/data/ui/keyboard-configurer.ui
+++ b/data/ui/preferences-subpage-keyboard.ui
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
-  <template class="GamesKeyboardConfigurer" parent="GtkBox">
+  <template class="GamesPreferencesSubpageKeyboard" parent="GtkBox">
     <property name="visible">True</property>
     <property name="can_focus">True</property>
     <property name="orientation">vertical</property>
diff --git a/src/meson.build b/src/meson.build
index f6bb3613..bc9b1317 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -144,7 +144,6 @@ vala_sources = [
   'ui/game-icon-view.vala',
   'ui/game-thumbnail.vala',
   'ui/gamepad-view-configuration.vala',
-  'ui/keyboard-configurer.vala',
   'ui/keyboard-mapper.vala',
   'ui/keyboard-tester.vala',
   'ui/konami-code.vala',
@@ -160,6 +159,7 @@ vala_sources = [
   'ui/preferences-page-video.vala',
   'ui/preferences-subpage.vala',
   'ui/preferences-subpage-gamepad.vala',
+  'ui/preferences-subpage-keyboard.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 eba78ff8..95daa742 100644
--- a/src/ui/preferences-page-controllers.vala
+++ b/src/ui/preferences-page-controllers.vala
@@ -1,9 +1,19 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
 [GtkTemplate (ui = "/org/gnome/Games/ui/preferences-page-controllers.ui")]
-private class Games.PreferencesPageControllers: Gtk.Stack, PreferencesPage {
-       public Gtk.HeaderBar header_bar { get; protected set; }
-       public bool immersive_mode { get; protected set; }
+private class Games.PreferencesPageControllers: Gtk.Bin, PreferencesPage {
+       [GtkChild (name = "header_bar")]
+       private Gtk.HeaderBar _header_bar;
+       public Gtk.HeaderBar header_bar {
+               protected set {}
+               get { return _header_bar; }
+       }
+
+       public bool immersive_mode {
+               protected set {}
+               get { return false; }
+       }
+
        public PreferencesSubpage subpage { get; protected set; }
 
        [GtkChild]
@@ -14,21 +24,12 @@ private class Games.PreferencesPageControllers: Gtk.Stack, PreferencesPage {
        private Gtk.ListBox gamepads_list_box;
        [GtkChild]
        private Gtk.ListBox keyboard_list_box;
-       [GtkChild]
-       private Gtk.Box extra_stack_child_holder;
-       [GtkChild]
-       private Gtk.HeaderBar default_header_bar;
 
        private Manette.Monitor monitor;
 
-       private Binding header_bar_binding;
-       private Binding immersive_mode_binding;
        private ulong back_handler_id;
 
        construct {
-               header_bar = default_header_bar;
-               immersive_mode = false;
-
                monitor = new Manette.Monitor ();
                monitor.device_connected.connect (rebuild_gamepad_list);
                monitor.device_disconnected.connect (rebuild_gamepad_list);
@@ -36,10 +37,6 @@ private class Games.PreferencesPageControllers: Gtk.Stack, PreferencesPage {
                build_keyboard_list ();
        }
 
-       public void visible_page_changed () {
-               on_back_old (null);
-       }
-
        private void rebuild_gamepad_list () {
                clear_gamepad_list ();
                build_gamepad_list ();
@@ -96,33 +93,13 @@ 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_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",
-                                                                  BindingFlags.SYNC_CREATE);
-               extra_stack_child_holder.pack_start (configurer);
-               visible_child_name = "extra_stack_child";
+               var subpage_keyboard = new PreferencesSubpageKeyboard ();
+               back_handler_id = subpage_keyboard.back.connect (on_back);
+               subpage = subpage_keyboard;
        }
 
        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) {
-                       if (emitter != null)
-                               emitter.disconnect (back_handler_id);
-                       back_handler_id = 0;
-               }
-
-               header_bar = default_header_bar;
-               immersive_mode = false;
-               visible_child_name = "main_stack_child";
-               extra_stack_child_holder.foreach ((child) => child.destroy ());
-       }
 }
diff --git a/src/ui/keyboard-configurer.vala b/src/ui/preferences-subpage-keyboard.vala
similarity index 95%
rename from src/ui/keyboard-configurer.vala
rename to src/ui/preferences-subpage-keyboard.vala
index e18588ef..2a3619c3 100644
--- a/src/ui/keyboard-configurer.vala
+++ b/src/ui/preferences-subpage-keyboard.vala
@@ -1,7 +1,7 @@
 // This file is part of GNOME Games. License: GPL-3.0+.
 
-[GtkTemplate (ui = "/org/gnome/Games/ui/keyboard-configurer.ui")]
-private class Games.KeyboardConfigurer : Gtk.Box {
+[GtkTemplate (ui = "/org/gnome/Games/ui/preferences-subpage-keyboard.ui")]
+private class Games.PreferencesSubpageKeyboard: Gtk.Box, PreferencesSubpage {
        private const GamepadInput[] KEYBOARD_GAMEPAD_INPUTS = {
                { EventCode.EV_KEY, EventCode.BTN_A },
                { EventCode.EV_KEY, EventCode.BTN_B },
@@ -56,9 +56,9 @@ private class Games.KeyboardConfigurer : Gtk.Box {
                get { return _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:
@@ -93,11 +93,7 @@ private class Games.KeyboardConfigurer : Gtk.Box {
        private Gtk.HeaderBar _header_bar;
        public Gtk.HeaderBar header_bar {
                get { return _header_bar; }
-               private set {}
        }
-
-       public bool immersive_mode { get; private set; }
-
        [GtkChild]
        private Gtk.Stack gamepad_view_stack;
        [GtkChild]
@@ -121,7 +117,7 @@ private class Games.KeyboardConfigurer : Gtk.Box {
 
        private Binding info_message_binding;
 
-       public KeyboardConfigurer () {
+       public PreferencesSubpageKeyboard () {
                mapper = new KeyboardMapper (KEYBOARD_GAMEPAD_VIEW_CONFIGURATION, KEYBOARD_GAMEPAD_INPUTS);
                gamepad_view_stack.add (mapper);
                tester = new KeyboardTester (KEYBOARD_GAMEPAD_VIEW_CONFIGURATION);


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