[gnome-games] ui: Merge ContentBox into ApplicationWindow



commit a7d2377b861aa86343199c24f048902770302b75
Author: Adrien Plazas <kekun plazas laposte net>
Date:   Sun Jul 24 12:56:33 2016 +0200

    ui: Merge ContentBox into ApplicationWindow
    
    Make ApplicationWindow handle the UI state of the content box and use
    CollectionBox and DisplayBox that have been extracted from ContentBox in
    the previous commits.
    
    This better distributes the concerns of the different parts of the UI.
    
    Fixes #312

 data/org.gnome.Games.gresource.xml |    1 -
 data/ui/application-window.ui      |   21 +++++-
 data/ui/content-box.ui             |   54 ++-------------
 src/Makefile.am                    |    1 -
 src/ui/application-window.vala     |   52 ++++++++------
 src/ui/content-box.vala            |  133 ------------------------------------
 6 files changed, 54 insertions(+), 208 deletions(-)
---
diff --git a/data/org.gnome.Games.gresource.xml b/data/org.gnome.Games.gresource.xml
index 4389f2d..461cf37 100644
--- a/data/org.gnome.Games.gresource.xml
+++ b/data/org.gnome.Games.gresource.xml
@@ -8,7 +8,6 @@
     <file preprocess="xml-stripblanks">ui/collection-box.ui</file>
     <file preprocess="xml-stripblanks">ui/collection-header-bar.ui</file>
     <file preprocess="xml-stripblanks">ui/collection-icon-view.ui</file>
-    <file preprocess="xml-stripblanks">ui/content-box.ui</file>
     <file preprocess="xml-stripblanks">ui/display-box.ui</file>
     <file preprocess="xml-stripblanks">ui/display-header-bar.ui</file>
     <file preprocess="xml-stripblanks">ui/dummy-display.ui</file>
diff --git a/data/ui/application-window.ui b/data/ui/application-window.ui
index 04d2910..1d57769 100644
--- a/data/ui/application-window.ui
+++ b/data/ui/application-window.ui
@@ -10,9 +10,26 @@
     <signal name="delete-event" after="yes" handler="on_delete_event"/>
     <signal name="key-press-event" after="yes" handler="on_key_pressed"/>
     <child>
-      <object class="GamesContentBox" id="content_box">
+      <object class="GtkStack" id="content_box">
         <property name="visible">True</property>
-        <signal name="game-activated" handler="on_game_activated"/>
+        <property name="can_focus">False</property>
+        <child>
+          <object class="GamesCollectionBox" id="collection_box">
+            <property name="visible">True</property>
+            <signal name="game-activated" handler="on_game_activated"/>
+          </object>
+          <packing>
+            <property name="name">collection</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GamesDisplayBox" id="display_box">
+            <property name="visible">True</property>
+          </object>
+          <packing>
+            <property name="name">display</property>
+          </packing>
+        </child>
       </object>
     </child>
     <child type="titlebar">
diff --git a/data/ui/content-box.ui b/data/ui/content-box.ui
index 99b703c..d7320e7 100644
--- a/data/ui/content-box.ui
+++ b/data/ui/content-box.ui
@@ -1,66 +1,24 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <requires lib="gtk+" version="3.16"/>
-  <template class="GamesContentBox" parent="GtkBox">
+  <template class="GamesContentBox" parent="GtkStack">
     <property name="visible">True</property>
-    <property name="orientation">vertical</property>
-    <property name="spacing">0</property>
-    <property name="halign">fill</property>
-    <property name="valign">fill</property>
-    <property name="hexpand">True</property>
-    <property name="vexpand">True</property>
     <property name="can-focus">False</property>
     <child>
-      <object class="GamesSearchBar" id="search_bar">
+      <object class="GamesCollectionBox" id="collection_box">
         <property name="visible">True</property>
-        <signal name="notify::text" handler="on_search_text_notify"/>
+        <signal name="game-activated" handler="on_game_activated"/>
       </object>
       <packing>
-        <property name="expand">False</property>
-        <property name="fill">True</property>
+        <property name="name">collection</property>
       </packing>
     </child>
     <child>
-      <object class="GtkOverlay" id="overlay">
+      <object class="GamesDisplayBox" id="display_box">
         <property name="visible">True</property>
-        <property name="can-focus">False</property>
-        <child type="overlay">
-          <object class="GtkBox" id="info_box">
-            <property name="visible">True</property>
-            <property name="halign">center</property>
-            <property name="valign">start</property>
-            <property name="hexpand">True</property>
-            <property name="vexpand">False</property>
-            <property name="orientation">vertical</property>
-          </object>
-        </child>
-        <child>
-          <object class="GtkStack" id="content_stack">
-            <property name="visible">True</property>
-            <property name="can-focus">False</property>
-            <child>
-              <object class="GamesCollectionIconView" id="collection_icon_view">
-                <property name="visible">True</property>
-                <signal name="game-activated" handler="on_game_activated"/>
-              </object>
-              <packing>
-                <property name="name">collection-icon-view</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkEventBox" id="display_box">
-                <property name="visible">True</property>
-              </object>
-              <packing>
-                <property name="name">display-box</property>
-              </packing>
-            </child>
-          </object>
-        </child>
       </object>
       <packing>
-        <property name="expand">True</property>
-        <property name="fill">True</property>
+        <property name="name">display</property>
       </packing>
     </child>
   </template>
diff --git a/src/Makefile.am b/src/Makefile.am
index 35b4bf1..7bb4bce 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -87,7 +87,6 @@ gnome_games_SOURCES = \
        ui/collection-box.vala \
        ui/collection-icon-view.vala \
        ui/collection-header-bar.vala \
-       ui/content-box.vala \
        ui/display-box.vala \
        ui/display-header-bar.vala \
        ui/dummy-display.vala \
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 3dc1215..3bd25be 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -12,10 +12,17 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                        switch (ui_state) {
                        case UiState.COLLECTION:
+                               content_box.set_visible_child (collection_box);
                                header_bar.set_visible_child (collection_header_bar);
 
+                               if (display_box.runner != null) {
+                                       display_box.runner.pause ();
+                                       display_box.runner = null;
+                               }
+
                                break;
                        case UiState.DISPLAY:
+                               content_box.set_visible_child (display_box);
                                header_bar.set_visible_child (display_header_bar);
 
                                search_mode = false;
@@ -33,9 +40,11 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        [GtkChild]
-       private ContentBox content_box;
-       private Binding cb_ui_binding;
-       private Binding cb_search_binding;
+       private Gtk.Stack content_box;
+       [GtkChild]
+       private CollectionBox collection_box;
+       [GtkChild]
+       private DisplayBox display_box;
 
        [GtkChild]
        private Gtk.Stack header_bar;
@@ -43,7 +52,9 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        private CollectionHeaderBar collection_header_bar;
        [GtkChild]
        private DisplayHeaderBar display_header_bar;
-       private Binding hb_search_binding;
+
+       private Binding box_search_binding;
+       private Binding header_bar_search_binding;
 
        private HashTable<Game, Runner> runners;
 
@@ -51,19 +62,16 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        private Cancellable quit_game_cancellable;
 
        public ApplicationWindow (ListModel collection) {
-               content_box.collection = collection;
+               collection_box.collection = collection;
        }
 
        construct {
                runners = new HashTable<Game, Runner> (GLib.direct_hash, GLib.direct_equal);
 
-               cb_ui_binding = content_box.bind_property ("ui-state",
-                                                          this, "ui-state", BindingFlags.BIDIRECTIONAL);
-
-               cb_search_binding = content_box.bind_property ("search-mode",
-                                                              this, "search-mode", 
BindingFlags.BIDIRECTIONAL);
-               hb_search_binding = bind_property ("search-mode", collection_header_bar, "search-mode",
-                                                  BindingFlags.BIDIRECTIONAL);
+               box_search_binding = bind_property ("search-mode", collection_box, "search-mode",
+                                                   BindingFlags.BIDIRECTIONAL);
+               header_bar_search_binding = bind_property ("search-mode", collection_header_bar, 
"search-mode",
+                                                          BindingFlags.BIDIRECTIONAL);
        }
 
        public void run_game (Game game) {
@@ -119,7 +127,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                        return true;
                }
 
-               if (ui_state == UiState.COLLECTION && content_box.search_bar_handle_event (event))
+               if (ui_state == UiState.COLLECTION && collection_box.search_bar_handle_event (event))
                        return true;
 
                return false;
@@ -143,13 +151,13 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                }
                catch (Error e) {
                        warning ("%s\n", e.message);
-                       content_box.display_error (e.message);
+                       collection_box.display_error (e.message);
 
                        return;
                }
 
                display_header_bar.game_title = game.name;
-               content_box.runner = runner;
+               display_box.runner = runner;
                ui_state = UiState.DISPLAY;
 
                var resume = false;
@@ -170,7 +178,7 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
                        switch (response) {
                        case Gtk.ResponseType.CANCEL:
-                               content_box.runner = null;
+                               display_box.runner = null;
                                ui_state = UiState.COLLECTION;
 
                                return;
@@ -200,12 +208,12 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        public bool quit_game_with_cancellable (Cancellable cancellable) {
-               if (content_box.runner == null)
+               if (display_box.runner == null)
                        return true;
 
-               content_box.runner.pause ();
+               display_box.runner.pause ();
 
-               if (content_box.runner.can_quit_safely)
+               if (display_box.runner.can_quit_safely)
                        return true;
 
                var dialog = new QuitDialog ();
@@ -228,10 +236,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
        }
 
        private bool cancel_quitting_game () {
-               content_box.ui_state = ui_state;
-
-               if (content_box.runner != null)
-                       content_box.runner.resume ();
+               if (display_box.runner != null)
+                       display_box.runner.resume ();
 
                return false;
        }


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