[gnome-games/wip/exalm/controller-preferences: 4/6] ui: Unify action bars in controller preferences



commit 939e0d2bb379b9558abb0df5b5e69e3d1608255a
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Tue Sep 11 22:20:08 2018 +0500

    ui: Unify action bars in controller preferences
    
    Move GamepadMapper action bar to GamepadConfigurer, and KeyboardMapper
    action bar to KeyboardConfigurer.
    
    This allows to avoid hiding and showing GamepadConfigurer and
    KeyboardConfigurer action bars when switching between states.
    
    Fixes #116

 data/ui/gamepad-configurer.ui   | 65 ++++++++++++++++++++++++++++-------------
 data/ui/gamepad-mapper.ui       | 20 -------------
 data/ui/keyboard-configurer.ui  | 65 ++++++++++++++++++++++++++++-------------
 data/ui/keyboard-mapper.ui      | 20 -------------
 src/ui/gamepad-configurer.vala  | 26 +++++++++++++----
 src/ui/gamepad-mapper.vala      | 13 ++++-----
 src/ui/keyboard-configurer.vala | 26 +++++++++++++----
 src/ui/keyboard-mapper.vala     |  9 +++---
 8 files changed, 142 insertions(+), 102 deletions(-)
---
diff --git a/data/ui/gamepad-configurer.ui b/data/ui/gamepad-configurer.ui
index 5197e586..e60322b0 100644
--- a/data/ui/gamepad-configurer.ui
+++ b/data/ui/gamepad-configurer.ui
@@ -4,7 +4,7 @@
     <property name="visible">True</property>
     <property name="orientation">vertical</property>
     <child>
-      <object class="GtkStack" id="stack">
+      <object class="GtkStack" id="gamepad_view_stack">
         <property name="visible">True</property>
         <property name="hexpand">True</property>
         <property name="vexpand">True</property>
@@ -27,33 +27,58 @@
       </object>
     </child>
     <child>
-      <object class="GtkActionBar" id="action_bar">
+      <object class="GtkStack" id="action_bar_stack">
         <property name="visible">True</property>
         <child>
-          <object class="GtkButton" id="reset_button">
+          <object class="GtkActionBar" id="tester_action_bar">
             <property name="visible">True</property>
-            <property name="label" translatable="yes" context="Gamepad configuration factory 
reset">Reset</property>
-            <signal name="clicked" handler="on_reset_clicked"/>
-            <style>
-              <class name="destructive-action"/>
-            </style>
+            <child>
+              <object class="GtkButton" id="reset_button">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes" context="Keyboard configuration factory 
reset">Reset</property>
+                <signal name="clicked" handler="on_reset_clicked"/>
+                <style>
+                  <class name="destructive-action"/>
+                </style>
+              </object>
+              <packing>
+                <property name="pack-type">end</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="configure_button">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Configure</property>
+                <signal name="clicked" handler="on_configure_clicked"/>
+                <style>
+                  <class name="suggested-action"/>
+                </style>
+              </object>
+              <packing>
+                <property name="pack-type">start</property>
+              </packing>
+            </child>
           </object>
-          <packing>
-            <property name="pack-type">end</property>
-          </packing>
         </child>
         <child>
-          <object class="GtkButton" id="configure_button">
+          <object class="GtkActionBar" id="mapper_action_bar">
             <property name="visible">True</property>
-            <property name="label" translatable="yes">Configure</property>
-            <signal name="clicked" handler="on_configure_clicked"/>
-            <style>
-              <class name="suggested-action"/>
-            </style>
+            <child>
+              <object class="GtkButton" id="skip_button">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Skip</property>
+                <signal name="clicked" handler="on_skip_clicked"/>
+              </object>
+              <packing>
+                <property name="pack-type">start</property>
+              </packing>
+            </child>
+            <child type="center">
+              <object class="GtkLabel" id="info_message">
+                <property name="visible">True</property>
+              </object>
+            </child>
           </object>
-          <packing>
-            <property name="pack-type">start</property>
-          </packing>
         </child>
       </object>
     </child>
diff --git a/data/ui/gamepad-mapper.ui b/data/ui/gamepad-mapper.ui
index 30cc5041..3ee8af1a 100644
--- a/data/ui/gamepad-mapper.ui
+++ b/data/ui/gamepad-mapper.ui
@@ -10,25 +10,5 @@
         <property name="vexpand">True</property>
       </object>
     </child>
-    <child>
-      <object class="GtkActionBar" id="action_bar">
-        <property name="visible">True</property>
-        <child>
-          <object class="GtkButton" id="skip_button">
-            <property name="visible">True</property>
-            <property name="label" translatable="yes">Skip</property>
-            <signal name="clicked" handler="on_skip_clicked"/>
-          </object>
-          <packing>
-            <property name="pack-type">start</property>
-          </packing>
-        </child>
-        <child type="center">
-          <object class="GtkLabel" id="info_message">
-            <property name="visible">True</property>
-          </object>
-        </child>
-      </object>
-    </child>
   </template>
 </interface>
diff --git a/data/ui/keyboard-configurer.ui b/data/ui/keyboard-configurer.ui
index 573aa75f..0b6bd9b2 100644
--- a/data/ui/keyboard-configurer.ui
+++ b/data/ui/keyboard-configurer.ui
@@ -5,7 +5,7 @@
     <property name="can_focus">True</property>
     <property name="orientation">vertical</property>
     <child>
-      <object class="GtkStack" id="stack">
+      <object class="GtkStack" id="gamepad_view_stack">
         <property name="visible">True</property>
         <property name="hexpand">True</property>
         <property name="vexpand">True</property>
@@ -28,33 +28,58 @@
       </object>
     </child>
     <child>
-      <object class="GtkActionBar" id="action_bar">
+      <object class="GtkStack" id="action_bar_stack">
         <property name="visible">True</property>
         <child>
-          <object class="GtkButton" id="reset_button">
+          <object class="GtkActionBar" id="tester_action_bar">
             <property name="visible">True</property>
-            <property name="label" translatable="yes" context="Keyboard configuration factory 
reset">Reset</property>
-            <signal name="clicked" handler="on_reset_clicked"/>
-            <style>
-              <class name="destructive-action"/>
-            </style>
+            <child>
+              <object class="GtkButton" id="reset_button">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes" context="Keyboard configuration factory 
reset">Reset</property>
+                <signal name="clicked" handler="on_reset_clicked"/>
+                <style>
+                  <class name="destructive-action"/>
+                </style>
+              </object>
+              <packing>
+                <property name="pack-type">end</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="configure_button">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Configure</property>
+                <signal name="clicked" handler="on_configure_clicked"/>
+                <style>
+                  <class name="suggested-action"/>
+                </style>
+              </object>
+              <packing>
+                <property name="pack-type">start</property>
+              </packing>
+            </child>
           </object>
-          <packing>
-            <property name="pack-type">end</property>
-          </packing>
         </child>
         <child>
-          <object class="GtkButton" id="configure_button">
+          <object class="GtkActionBar" id="mapper_action_bar">
             <property name="visible">True</property>
-            <property name="label" translatable="yes">Configure</property>
-            <signal name="clicked" handler="on_configure_clicked"/>
-            <style>
-              <class name="suggested-action"/>
-            </style>
+            <child>
+              <object class="GtkButton" id="skip_button">
+                <property name="visible">True</property>
+                <property name="label" translatable="yes">Skip</property>
+                <signal name="clicked" handler="on_skip_clicked"/>
+              </object>
+              <packing>
+                <property name="pack-type">start</property>
+              </packing>
+            </child>
+            <child type="center">
+              <object class="GtkLabel" id="info_message">
+                <property name="visible">True</property>
+              </object>
+            </child>
           </object>
-          <packing>
-            <property name="pack-type">start</property>
-          </packing>
         </child>
       </object>
     </child>
diff --git a/data/ui/keyboard-mapper.ui b/data/ui/keyboard-mapper.ui
index 4fcc5854..baee6d68 100644
--- a/data/ui/keyboard-mapper.ui
+++ b/data/ui/keyboard-mapper.ui
@@ -10,25 +10,5 @@
         <property name="vexpand">True</property>
       </object>
     </child>
-    <child>
-      <object class="GtkActionBar" id="action_bar">
-        <property name="visible">True</property>
-        <child>
-          <object class="GtkButton" id="skip_button">
-            <property name="visible">True</property>
-            <property name="label" translatable="yes">Skip</property>
-            <signal name="clicked" handler="on_skip_clicked"/>
-          </object>
-          <packing>
-            <property name="pack-type">start</property>
-          </packing>
-        </child>
-        <child type="center">
-          <object class="GtkLabel" id="info_message">
-            <property name="visible">True</property>
-          </object>
-        </child>
-      </object>
-    </child>
   </template>
 </interface>
diff --git a/src/ui/gamepad-configurer.vala b/src/ui/gamepad-configurer.vala
index 85fdb668..c3a45781 100644
--- a/src/ui/gamepad-configurer.vala
+++ b/src/ui/gamepad-configurer.vala
@@ -68,7 +68,6 @@ private class Games.GamepadConfigurer : Gtk.Box {
                        immersive_mode = (state == State.CONFIGURE);
                        back_button.visible = (state == State.TEST);
                        cancel_button.visible = (state == State.CONFIGURE);
-                       action_bar.visible = (state == State.TEST);
 
                        switch (value) {
                        case State.TEST:
@@ -77,7 +76,8 @@ private class Games.GamepadConfigurer : Gtk.Box {
                                /* translators: testing a gamepad, %s is its name */
                                header_bar.title = _("Testing %s").printf (device.get_name ());
                                header_bar.get_style_context ().remove_class ("selection-mode");
-                               stack.visible_child = gamepad_tester_holder;
+                               gamepad_view_stack.visible_child = gamepad_tester_holder;
+                               action_bar_stack.visible_child = tester_action_bar;
 
                                tester.start ();
                                mapper.stop ();
@@ -88,7 +88,8 @@ private class Games.GamepadConfigurer : Gtk.Box {
                                /* translators: configuring a gamepad, %s is its name */
                                header_bar.title = _("Configuring %s").printf (device.get_name ());
                                header_bar.get_style_context ().add_class ("selection-mode");
-                               stack.visible_child = gamepad_mapper_holder;
+                               gamepad_view_stack.visible_child = gamepad_mapper_holder;
+                               action_bar_stack.visible_child = mapper_action_bar;
 
                                tester.stop ();
                                mapper.start ();
@@ -110,24 +111,32 @@ private class Games.GamepadConfigurer : Gtk.Box {
        public bool immersive_mode { private set; get; }
 
        [GtkChild]
-       private Gtk.Stack stack;
+       private Gtk.Stack gamepad_view_stack;
        [GtkChild]
        private Gtk.Box gamepad_mapper_holder;
        [GtkChild]
        private Gtk.Box gamepad_tester_holder;
        [GtkChild]
-       private Gtk.ActionBar action_bar;
+       private Gtk.Stack action_bar_stack;
+       [GtkChild]
+       private Gtk.ActionBar tester_action_bar;
+       [GtkChild]
+       private Gtk.ActionBar mapper_action_bar;
        [GtkChild]
        private Gtk.Button reset_button;
        [GtkChild]
        private Gtk.Button back_button;
        [GtkChild]
        private Gtk.Button cancel_button;
+       [GtkChild]
+       private Gtk.Label info_message;
 
        private Manette.Device device;
        private GamepadMapper mapper;
        private GamepadTester tester;
 
+       private Binding info_message_binding;
+
        public GamepadConfigurer (Manette.Device device) {
                this.device = device;
                mapper = new GamepadMapper (device, STANDARD_GAMEPAD_VIEW_CONFIGURATION, 
STANDARD_GAMEPAD_INPUTS);
@@ -135,6 +144,8 @@ private class Games.GamepadConfigurer : Gtk.Box {
                tester = new GamepadTester (device, STANDARD_GAMEPAD_VIEW_CONFIGURATION);
                gamepad_tester_holder.pack_start (tester);
 
+               info_message_binding = mapper.bind_property ("info-message", info_message, "label", 
BindingFlags.SYNC_CREATE);
+
                state = State.TEST;
        }
 
@@ -148,6 +159,11 @@ private class Games.GamepadConfigurer : Gtk.Box {
                state = State.CONFIGURE;
        }
 
+       [GtkCallback]
+       private void on_skip_clicked () {
+               mapper.skip ();
+       }
+
        [GtkCallback]
        private void on_back_clicked () {
                back ();
diff --git a/src/ui/gamepad-mapper.vala b/src/ui/gamepad-mapper.vala
index 651d6e5e..7f452361 100644
--- a/src/ui/gamepad-mapper.vala
+++ b/src/ui/gamepad-mapper.vala
@@ -6,8 +6,6 @@ private class Games.GamepadMapper : Gtk.Box {
 
        [GtkChild]
        private GamepadView gamepad_view;
-       [GtkChild]
-       private Gtk.Label info_message;
 
        private Manette.Device device;
        private GamepadMappingBuilder mapping_builder;
@@ -15,6 +13,8 @@ private class Games.GamepadMapper : Gtk.Box {
        private GamepadInput input;
        private uint current_input_index;
 
+       public string info_message { get; private set; }
+
        private ulong gamepad_event_handler_id;
 
        public GamepadMapper (Manette.Device device, GamepadViewConfiguration configuration, GamepadInput[] 
mapping_inputs) {
@@ -40,8 +40,7 @@ private class Games.GamepadMapper : Gtk.Box {
                disconnect_from_gamepad ();
        }
 
-       [GtkCallback]
-       private void on_skip_clicked () {
+       public void skip () {
                next_input ();
        }
 
@@ -123,14 +122,14 @@ private class Games.GamepadMapper : Gtk.Box {
        private void update_info_message () {
                switch (input.type) {
                case EventCode.EV_KEY:
-                       info_message.label = _("Press suitable button on your gamepad");
+                       info_message = _("Press suitable button on your gamepad");
 
                        break;
                case EventCode.EV_ABS:
                        if (input.code == EventCode.ABS_X || input.code == EventCode.ABS_RX)
-                               info_message.label = _("Move suitable axis left/right on your gamepad");
+                               info_message = _("Move suitable axis left/right on your gamepad");
                        else if (input.code == EventCode.ABS_Y || input.code == EventCode.ABS_RY)
-                               info_message.label = _("Move suitable axis up/down on your gamepad");
+                               info_message = _("Move suitable axis up/down on your gamepad");
 
                        break;
                default:
diff --git a/src/ui/keyboard-configurer.vala b/src/ui/keyboard-configurer.vala
index f8a37f38..043a1fdc 100644
--- a/src/ui/keyboard-configurer.vala
+++ b/src/ui/keyboard-configurer.vala
@@ -59,7 +59,6 @@ private class Games.KeyboardConfigurer : Gtk.Box {
                        immersive_mode = (state == State.CONFIGURE);
                        back_button.visible = (state == State.TEST);
                        cancel_button.visible = (state == State.CONFIGURE);
-                       action_bar.visible = (state == State.TEST);
 
                        switch (value) {
                        case State.TEST:
@@ -67,7 +66,8 @@ private class Games.KeyboardConfigurer : Gtk.Box {
 
                                header_bar.title = _("Testing Keyboard");
                                header_bar.get_style_context ().remove_class ("selection-mode");
-                               stack.visible_child = keyboard_tester_holder;
+                               gamepad_view_stack.visible_child = keyboard_tester_holder;
+                               action_bar_stack.visible_child = tester_action_bar;
 
                                tester.start ();
                                mapper.stop ();
@@ -77,7 +77,8 @@ private class Games.KeyboardConfigurer : Gtk.Box {
                        case State.CONFIGURE:
                                header_bar.title = _("Configuring Keyboard");
                                header_bar.get_style_context ().add_class ("selection-mode");
-                               stack.visible_child = keyboard_mapper_holder;
+                               gamepad_view_stack.visible_child = keyboard_mapper_holder;
+                               action_bar_stack.visible_child = mapper_action_bar;
 
                                tester.stop ();
                                mapper.start ();
@@ -98,24 +99,32 @@ private class Games.KeyboardConfigurer : Gtk.Box {
        public bool immersive_mode { get; private set; }
 
        [GtkChild]
-       private Gtk.Stack stack;
+       private Gtk.Stack gamepad_view_stack;
        [GtkChild]
        private Gtk.Box keyboard_mapper_holder;
        [GtkChild]
        private Gtk.Box keyboard_tester_holder;
        [GtkChild]
-       private Gtk.ActionBar action_bar;
+       private Gtk.Stack action_bar_stack;
+       [GtkChild]
+       private Gtk.ActionBar tester_action_bar;
+       [GtkChild]
+       private Gtk.ActionBar mapper_action_bar;
        [GtkChild]
        private Gtk.Button reset_button;
        [GtkChild]
        private Gtk.Button back_button;
        [GtkChild]
        private Gtk.Button cancel_button;
+       [GtkChild]
+       private Gtk.Label info_message;
 
        private KeyboardMapper mapper;
        private KeyboardTester tester;
        private KeyboardMappingManager mapping_manager;
 
+       private Binding info_message_binding;
+
        public KeyboardConfigurer () {
                mapper = new KeyboardMapper (KEYBOARD_GAMEPAD_VIEW_CONFIGURATION, KEYBOARD_GAMEPAD_INPUTS);
                keyboard_mapper_holder.pack_start (mapper);
@@ -128,6 +137,8 @@ private class Games.KeyboardConfigurer : Gtk.Box {
                        tester.mapping = mapping_manager.mapping;
                });
 
+               info_message_binding = mapper.bind_property ("info-message", info_message, "label", 
BindingFlags.SYNC_CREATE);
+
                state = State.TEST;
        }
 
@@ -141,6 +152,11 @@ private class Games.KeyboardConfigurer : Gtk.Box {
                state = State.CONFIGURE;
        }
 
+       [GtkCallback]
+       private void on_skip_clicked () {
+               mapper.skip ();
+       }
+
        [GtkCallback]
        private void on_back_clicked () {
                back ();
diff --git a/src/ui/keyboard-mapper.vala b/src/ui/keyboard-mapper.vala
index 382219b8..f7ac9f2e 100644
--- a/src/ui/keyboard-mapper.vala
+++ b/src/ui/keyboard-mapper.vala
@@ -6,16 +6,16 @@ private class Games.KeyboardMapper : Gtk.Box {
 
        [GtkChild]
        private GamepadView gamepad_view;
-       [GtkChild]
-       private Gtk.Label info_message;
 
        private KeyboardMappingBuilder mapping_builder;
        private GamepadInput[] mapping_inputs;
        private GamepadInput input;
        private uint current_input_index;
 
+       public string info_message { get; private set; }
+
        construct {
-               info_message.label = _("Press suitable key on your keyboard");
+               info_message = _("Press suitable key on your keyboard");
        }
 
        public KeyboardMapper (GamepadViewConfiguration configuration, GamepadInput[] mapping_inputs) {
@@ -40,8 +40,7 @@ private class Games.KeyboardMapper : Gtk.Box {
                disconnect_from_keyboard ();
        }
 
-       [GtkCallback]
-       private void on_skip_clicked () {
+       public void skip () {
                next_input ();
        }
 


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