[gnome-games/wip/exalm/unified-window: 18/26] application-window: Create views in XML



commit 3f8b002d18389ec97fac613983e88d0abfb29d57
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Fri Apr 10 18:46:16 2020 +0500

    application-window: Create views in XML

 data/ui/application-window.ui  | 16 ++++++++++++++++
 data/ui/collection-view.ui     |  1 -
 data/ui/display-view.ui        |  1 -
 src/ui/application-window.vala | 32 +++++++++++---------------------
 src/ui/collection-view.vala    | 29 ++++++++++++++++-------------
 src/ui/display-view.vala       |  4 ----
 6 files changed, 43 insertions(+), 40 deletions(-)
---
diff --git a/data/ui/application-window.ui b/data/ui/application-window.ui
index ad62942d..2a3e58aa 100644
--- a/data/ui/application-window.ui
+++ b/data/ui/application-window.ui
@@ -13,6 +13,22 @@
     <child>
       <object class="GtkStack" id="stack">
         <property name="visible">True</property>
+        <child>
+          <object class="GamesCollectionView" id="collection_view">
+            <property name="visible">True</property>
+            <property name="window">GamesApplicationWindow</property>
+            <property name="loading-notification" bind-source="GamesApplicationWindow" 
bind-property="loading-notification"/>
+            <signal name="game-activated" handler="on_game_activated"/>
+          </object>
+        </child>
+        <child>
+          <object class="GamesDisplayView" id="display_view">
+            <property name="visible">True</property>
+            <property name="window">GamesApplicationWindow</property>
+            <property name="is-fullscreen" bind-source="GamesApplicationWindow" 
bind-property="is-fullscreen" bind-flags="bidirectional"/>
+            <signal name="back" handler="on_display_back"/>
+          </object>
+        </child>
       </object>
     </child>
   </template>
diff --git a/data/ui/collection-view.ui b/data/ui/collection-view.ui
index e84ff8b0..439f620a 100644
--- a/data/ui/collection-view.ui
+++ b/data/ui/collection-view.ui
@@ -2,7 +2,6 @@
 <interface>
   <requires lib="gtk+" version="3.24"/>
   <template class="GamesCollectionView" parent="GtkBox">
-    <property name="visible">True</property>
     <property name="orientation">vertical</property>
     <property name="hexpand">True</property>
     <property name="vexpand">True</property>
diff --git a/data/ui/display-view.ui b/data/ui/display-view.ui
index ac5330c3..065200cd 100644
--- a/data/ui/display-view.ui
+++ b/data/ui/display-view.ui
@@ -2,7 +2,6 @@
 <interface>
   <requires lib="gtk+" version="3.24"/>
   <template class="GamesDisplayView" parent="GtkBox">
-    <property name="visible">True</property>
     <property name="orientation">vertical</property>
     <signal name="notify::is-showing-snapshots" handler="on_showing_snapshots_changed"/>
     <signal name="notify::can-fullscreen" handler="on_fullscreen_changed"/>
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 92c1b546..42087885 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -4,6 +4,13 @@
 private class Games.ApplicationWindow : Hdy.ApplicationWindow {
        private const uint WINDOW_SIZE_UPDATE_DELAY_MILLISECONDS = 500;
 
+       [GtkChild]
+       private Gtk.Stack stack;
+       [GtkChild]
+       private CollectionView collection_view;
+       [GtkChild]
+       private DisplayView display_view;
+
        private UiView _current_view;
        public UiView current_view {
                get { return _current_view; }
@@ -43,12 +50,6 @@ private class Games.ApplicationWindow : Hdy.ApplicationWindow {
 
        public bool loading_notification { get; set; }
 
-       [GtkChild]
-       private Gtk.Stack stack;
-
-       private CollectionView collection_view;
-       private DisplayView display_view;
-
        private Settings settings;
 
        private long window_size_update_timeout;
@@ -67,6 +68,8 @@ private class Games.ApplicationWindow : Hdy.ApplicationWindow {
        construct {
                settings = new Settings ("org.gnome.Games");
 
+               collection_view.game_model = game_model;
+
                int width, height;
                settings.get ("window-size", "(ii)", out width, out height);
                var geometry = get_geometry ();
@@ -79,21 +82,6 @@ private class Games.ApplicationWindow : Hdy.ApplicationWindow {
                if (settings.get_boolean ("window-maximized"))
                        maximize ();
 
-               collection_view = new CollectionView (this, game_model);
-               display_view = new DisplayView (this);
-
-               stack.add (collection_view);
-               stack.add (display_view);
-
-               collection_view.game_activated.connect (on_game_activated);
-               display_view.back.connect (on_display_back);
-
-               bind_property ("loading-notification", collection_view,
-                       "loading-notification", BindingFlags.DEFAULT);
-
-               bind_property ("is-fullscreen", display_view,
-                              "is-fullscreen", BindingFlags.BIDIRECTIONAL);
-
                window_size_update_timeout = -1;
                inhibit_cookie = 0;
                inhibit_flags = 0;
@@ -210,10 +198,12 @@ private class Games.ApplicationWindow : Hdy.ApplicationWindow {
                return false;
        }
 
+       [GtkCallback]
        private void on_game_activated (Game game) {
                run_game (game);
        }
 
+       [GtkCallback]
        private void on_display_back () {
                if (quit_game ())
                        current_view = collection_view;
diff --git a/src/ui/collection-view.vala b/src/ui/collection-view.vala
index c39cd795..c9be812b 100644
--- a/src/ui/collection-view.vala
+++ b/src/ui/collection-view.vala
@@ -77,7 +77,22 @@ private class Games.CollectionView : Gtk.Box, UiView {
        }
 
        public Gtk.Window window { get; construct; }
-       public GameModel game_model { get; construct; }
+
+       private GameModel _game_model;
+       public GameModel game_model {
+               get { return _game_model; }
+               set {
+                       _game_model = value;
+
+                       collection_view.game_model = game_model;
+                       platform_view.game_model = game_model;
+
+                       is_collection_empty = game_model.get_n_items () == 0;
+                       game_model.items_changed.connect (() => {
+                               is_collection_empty = game_model.get_n_items () == 0;
+                       });
+               }
+       }
 
        public bool loading_notification { get; set; }
        public bool search_mode { get; set; }
@@ -92,24 +107,12 @@ private class Games.CollectionView : Gtk.Box, UiView {
                var icon_name = Config.APPLICATION_ID + "-symbolic";
                viewstack.child_set (collection_view, "icon-name", icon_name);
 
-               collection_view.game_model = game_model;
-               platform_view.game_model = game_model;
-
                swipe_group.add_swipeable (platform_view.get_leaflet ());
 
-               is_collection_empty = game_model.get_n_items () == 0;
-               game_model.items_changed.connect (() => {
-                       is_collection_empty = game_model.get_n_items () == 0;
-               });
-
                konami_code = new KonamiCode (window);
                konami_code.code_performed.connect (on_konami_code_performed);
        }
 
-       public CollectionView (Gtk.Window window, GameModel game_model) {
-               Object (window: window, game_model: game_model);
-       }
-
        public void show_error (string error_message) {
                error_info_bar.show_error (error_message);
        }
diff --git a/src/ui/display-view.vala b/src/ui/display-view.vala
index 740cd301..af4e23ea 100644
--- a/src/ui/display-view.vala
+++ b/src/ui/display-view.vala
@@ -143,10 +143,6 @@ private class Games.DisplayView : Gtk.Box, UiView {
                { "restart",        restart        },
        };
 
-       public DisplayView (Gtk.Window window) {
-               Object (window: window);
-       }
-
        construct {
                settings = new Settings ("org.gnome.Games");
 


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