[gnome-games/wip/exalm/views: 12/19] application-window: Replace 'ui-state' with 'current-view'



commit d86fdb74a94554064e5bb48aad89daa02ea5d445
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Thu Oct 4 20:44:10 2018 +0500

    application-window: Replace 'ui-state' with 'current-view'
    
    Since UI states are now represented by *View objects, use them directly
    instead of having an enum.

 src/ui/application-window.vala | 92 +++++++++++++++++-------------------------
 src/ui/display-view.vala       |  8 +++-
 2 files changed, 43 insertions(+), 57 deletions(-)
---
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index f6e4c399..15e15460 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -9,41 +9,26 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
        public ListModel collection { get; construct set; }
 
-       private UiState _ui_state;
-       public UiState ui_state {
-               get { return _ui_state; }
+       private UiView _current_view;
+       public UiView current_view {
+               get { return _current_view; }
                set {
-                       if (value == ui_state)
+                       if (value == current_view)
                                return;
 
-                       _ui_state = value;
+                       if (current_view != null)
+                               current_view.is_view_active = false;
 
-                       switch (ui_state) {
-                       case UiState.COLLECTION:
-                               content_box.visible_child = collection_view.content_box;
-                               header_bar.visible_child = collection_view.title_bar;
+                       _current_view = value;
 
-                               display_view.is_view_active = false;
-                               collection_view.is_view_active = true;
+                       content_box.visible_child = current_view.content_box;
+                       header_bar.visible_child = current_view.title_bar;
 
-                               if (display_view.box.runner != null) {
-                                       display_view.box.runner.stop ();
-                                       display_view.box.runner = null;
-                               }
-
-                               break;
-                       case UiState.DISPLAY:
-                               content_box.visible_child = display_view.content_box;
-                               header_bar.visible_child = display_view.title_bar;
-
-                               collection_view.is_view_active = false;
-                               display_view.is_view_active = true;
-
-                               break;
-                       }
+                       if (current_view != null)
+                               current_view.is_view_active = true;
 
                        assert (application is Application);
-                       (application as Application).set_pause_loading (ui_state != UiState.COLLECTION);
+                       (application as Application).set_pause_loading (current_view != collection_view);
 
                        konami_code.reset ();
                }
@@ -53,7 +38,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        public bool is_fullscreen {
                get { return _is_fullscreen; }
                set {
-                       _is_fullscreen = value && (ui_state == UiState.DISPLAY);
+                       _is_fullscreen = value && (current_view == display_view);
 
                        if (_is_fullscreen)
                                fullscreen ();
@@ -94,6 +79,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
        public ApplicationWindow (Application application, ListModel collection) {
                Object(application: application, collection: collection);
+
+               current_view = collection_view;
        }
 
        construct {
@@ -108,8 +95,6 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                collection_view.game_activated.connect (on_game_activated);
                display_view.back.connect (on_display_back);
 
-               ui_state = UiState.COLLECTION;
-
                settings = new Settings ("org.gnome.Games");
 
                int width, height;
@@ -219,8 +204,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                        return true;
                }
 
-               if (ui_state == UiState.COLLECTION)
-                       return collection_view.on_key_pressed (event);
+               if (current_view == collection_view)
+                       return current_view.on_key_pressed (event);
 
                return handle_display_key_event (event);
        }
@@ -229,7 +214,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        public bool on_button_pressed (Gdk.EventButton event) {
                // Mouse button 8 is the navigation previous button
                if (event.button == 8) {
-                       if (ui_state != UiState.DISPLAY)
+                       if (current_view != display_view)
                                return false;
 
                        on_display_back ();
@@ -251,7 +236,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                        return false;
 
                var focused = (bool) (event.new_window_state & Gdk.WindowState.FOCUSED);
-               var playing = (ui_state == UiState.DISPLAY);
+               var playing = (current_view == display_view);
 
                if (focused && playing)
                        inhibit (Gtk.ApplicationInhibitFlags.IDLE);
@@ -263,10 +248,9 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        public bool gamepad_button_press_event (Manette.Event event) {
-               switch (ui_state) {
-               case UiState.COLLECTION:
+               if (current_view == collection_view)
                        return is_active && collection_view.box.gamepad_button_press_event (event);
-               case UiState.DISPLAY:
+               else if (current_view == display_view) {
                        if (resume_dialog != null)
                                return resume_dialog.is_active && resume_dialog.gamepad_button_press_event 
(event);
 
@@ -285,33 +269,29 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                        switch (button) {
                        case EventCode.BTN_MODE:
-                               ui_state = UiState.COLLECTION;
+                               current_view = collection_view;
 
                                return true;
                        default:
                                return false;
                        }
-               default:
-                       return false;
                }
+
+               return false;
        }
 
        public bool gamepad_button_release_event (Manette.Event event) {
-               switch (ui_state) {
-               case UiState.COLLECTION:
+               if (current_view == collection_view)
                        return is_active && collection_view.box.gamepad_button_release_event (event);
-               default:
-                       return false;
-               }
+
+               return false;
        }
 
        public bool gamepad_absolute_axis_event (Manette.Event event) {
-               switch (ui_state) {
-               case UiState.COLLECTION:
+               if (current_view == collection_view)
                        return is_active && collection_view.box.gamepad_absolute_axis_event (event);
-               default:
-                       return false;
-               }
+
+               return false;
        }
 
        private void on_game_activated (Game game) {
@@ -320,7 +300,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
        private void on_display_back () {
                if (quit_game ())
-                       ui_state = UiState.COLLECTION;
+                       current_view = collection_view;
 
                uninhibit (Gtk.ApplicationInhibitFlags.IDLE | Gtk.ApplicationInhibitFlags.LOGOUT);
        }
@@ -328,7 +308,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        private void run_game_with_cancellable (Game game, Cancellable cancellable) {
                display_view.header_bar.game_title = game.name;
                display_view.box.header_bar.game_title = game.name;
-               ui_state = UiState.DISPLAY;
+               current_view = display_view;
 
                // Reset the UI parts depending on the runner to avoid an
                // inconsistent state is case we couldn't retrieve it.
@@ -446,7 +426,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                if (response == Gtk.ResponseType.CANCEL) {
                        display_view.box.runner = null;
-                       ui_state = UiState.COLLECTION;
+                       current_view = collection_view;
 
                        return;
                }
@@ -589,7 +569,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        private bool can_update_pause () {
-               if (ui_state != UiState.DISPLAY)
+               if (current_view != display_view)
                        return false;
 
                if (display_view.box.runner == null)
@@ -605,7 +585,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        private bool handle_display_key_event (Gdk.EventKey event) {
-               if (ui_state != UiState.DISPLAY)
+               if (current_view != display_view)
                        return false;
 
                var default_modifiers = Gtk.accelerator_get_default_mod_mask ();
@@ -685,7 +665,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        private void on_konami_code_performed () {
-               if (ui_state != UiState.COLLECTION)
+               if (current_view != collection_view)
                        return;
 
                try {
diff --git a/src/ui/display-view.vala b/src/ui/display-view.vala
index 9e313c4a..54b45b92 100644
--- a/src/ui/display-view.vala
+++ b/src/ui/display-view.vala
@@ -23,8 +23,14 @@ private class Games.DisplayView: Object, UiView {
 
                        _is_view_active = value;
 
-                       if (!is_view_active)
+                       if (!is_view_active) {
                                is_fullscreen = false;
+
+                               if (box.runner != null) {
+                                       box.runner.stop ();
+                                       box.runner = null;
+                               }
+                       }
                }
        }
 


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