[gnome-games] ui: Add an empty state shared between all views



commit 9ba92af3bf2f79db952b8c403e30fbbb42f1a477
Author: Alexander Mikhaylenko <exalm7659 gmail com>
Date:   Mon Aug 6 16:08:45 2018 +0500

    ui: Add an empty state shared between all views
    
    Instead of having separate empty states for all CollectionIconViews,
    handle it separately in CollectionBox and CollectionHeaderBar.
    
    Also hide stack switcher and disable search button when empty.

 data/ui/collection-box.ui         |  8 ++++++++
 data/ui/collection-header-bar.ui  | 17 ++++++++++++++++-
 src/ui/application-window.vala    | 13 +++++++++++++
 src/ui/collection-box.vala        | 21 +++++++++++++++++++--
 src/ui/collection-header-bar.vala | 17 +++++++++++++++++
 5 files changed, 73 insertions(+), 3 deletions(-)
---
diff --git a/data/ui/collection-box.ui b/data/ui/collection-box.ui
index 88b6ad34..5864ab3b 100644
--- a/data/ui/collection-box.ui
+++ b/data/ui/collection-box.ui
@@ -22,6 +22,14 @@
             <property name="visible-child">collection_view</property>
             <property name="transition-type">GTK_STACK_TRANSITION_TYPE_CROSSFADE</property>
             <signal name="notify::visible-child" handler="on_visible_child_changed"/>
+            <child>
+              <object class="GamesEmptyCollection" id="empty_collection">
+                <property name="visible">True</property>
+              </object>
+              <packing>
+                <property name="name">empty</property>
+              </packing>
+            </child>
             <child>
               <object class="GamesCollectionIconView" id="collection_view">
                 <property name="visible">True</property>
diff --git a/data/ui/collection-header-bar.ui b/data/ui/collection-header-bar.ui
index 71f85360..9c50a47a 100644
--- a/data/ui/collection-header-bar.ui
+++ b/data/ui/collection-header-bar.ui
@@ -53,8 +53,23 @@
       </packing>
     </child>
     <child type="title">
-      <object class="GtkStackSwitcher" id="view_switcher">
+      <object class="GtkStack" id="title_stack">
         <property name="visible">True</property>
+        <property name="transition-type">GTK_STACK_TRANSITION_TYPE_CROSSFADE</property>
+        <child>
+          <object class="GtkStackSwitcher" id="view_switcher">
+            <property name="visible">True</property>
+          </object>
+        </child>
+        <child>
+          <object class="GtkLabel" id="empty_title">
+            <property name="visible">True</property>
+            <property name="label" translatable="yes">Games</property>
+            <style>
+              <class name="title"/>
+            </style>
+          </object>
+        </child>
       </object>
     </child>
     <child>
diff --git a/src/ui/application-window.vala b/src/ui/application-window.vala
index 748d1073..07e7f280 100644
--- a/src/ui/application-window.vala
+++ b/src/ui/application-window.vala
@@ -61,6 +61,8 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                get { return _search_mode; }
        }
 
+       public bool is_collection_empty { set; get; }
+
        public bool loading_notification { set; get; }
 
        [GtkChild]
@@ -81,8 +83,10 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
        private Binding box_search_binding;
        private Binding box_fullscreen_binding;
+       private Binding box_empty_collection_binding;
        private Binding header_bar_search_binding;
        private Binding header_bar_fullscreen_binding;
+       private Binding header_bar_empty_collection_binding;
        private Binding loading_notification_binding;
 
        private Cancellable run_game_cancellable;
@@ -102,6 +106,10 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
 
        public ApplicationWindow (ListModel collection) {
                collection_box.collection = collection;
+               collection.items_changed.connect (() => {
+                       is_collection_empty = collection.get_n_items () == 0;
+               });
+               is_collection_empty = collection.get_n_items () == 0;
        }
 
        construct {
@@ -131,6 +139,11 @@ private class Games.ApplicationWindow : Gtk.ApplicationWindow {
                header_bar_fullscreen_binding = bind_property ("is-fullscreen", display_header_bar, 
"is-fullscreen",
                                                               BindingFlags.BIDIRECTIONAL);
 
+               box_empty_collection_binding = bind_property ("is-collection-empty", collection_box, 
"is-collection-empty",
+                                                             BindingFlags.BIDIRECTIONAL);
+               header_bar_empty_collection_binding = bind_property ("is-collection-empty", 
collection_header_bar, "is-collection-empty",
+                                                                    BindingFlags.BIDIRECTIONAL);
+
                konami_code = new KonamiCode (this);
                konami_code.code_performed.connect (on_konami_code_performed);
 
diff --git a/src/ui/collection-box.vala b/src/ui/collection-box.vala
index 2ea9a13b..de2c95c2 100644
--- a/src/ui/collection-box.vala
+++ b/src/ui/collection-box.vala
@@ -13,6 +13,8 @@ private class Games.CollectionBox : Gtk.Box {
        [GtkChild]
        private Gtk.Revealer loading_notification_revealer;
        [GtkChild]
+       private EmptyCollection empty_collection;
+       [GtkChild]
        private CollectionIconView collection_view;
        [GtkChild]
        private DevelopersView developer_view;
@@ -24,6 +26,18 @@ private class Games.CollectionBox : Gtk.Box {
                get { return _viewstack; }
        }
 
+       private bool _is_collection_empty;
+       public bool is_collection_empty {
+               set {
+                       _is_collection_empty = value;
+                       if (_is_collection_empty)
+                               viewstack.visible_child = empty_collection;
+                       else
+                               viewstack.visible_child = collection_view;
+               }
+               get { return _is_collection_empty; }
+       }
+
        private Binding collection_binding;
        private Binding developer_collection_binding;
        private Binding platform_collection_binding;
@@ -58,6 +72,9 @@ private class Games.CollectionBox : Gtk.Box {
                if (!event.get_button (out button))
                        return false;
 
+               if (is_collection_empty)
+                       return false;
+
                switch (button) {
                case EventCode.BTN_TL:
                        var views = viewstack.get_children ();
@@ -65,7 +82,7 @@ private class Games.CollectionBox : Gtk.Box {
 
                        assert (current_view != null);
 
-                       if (current_view.prev != null)
+                       if (current_view.prev != null && current_view.prev.data != empty_collection)
                                viewstack.visible_child = current_view.prev.data;
 
                        return true;
@@ -75,7 +92,7 @@ private class Games.CollectionBox : Gtk.Box {
 
                        assert (current_view != null);
 
-                       if (current_view.next != null)
+                       if (current_view.next != null && current_view.next.data != empty_collection)
                                viewstack.visible_child = current_view.next.data;
 
                        return true;
diff --git a/src/ui/collection-header-bar.vala b/src/ui/collection-header-bar.vala
index a7c3eea3..f98d9279 100644
--- a/src/ui/collection-header-bar.vala
+++ b/src/ui/collection-header-bar.vala
@@ -12,6 +12,23 @@ private class Games.CollectionHeaderBar : Gtk.HeaderBar {
                get { return _viewstack; }
        }
 
+       private bool _is_collection_empty;
+       public bool is_collection_empty {
+               set {
+                       _is_collection_empty = value;
+                       if (_is_collection_empty)
+                               title_stack.visible_child = empty_title;
+                       else
+                               title_stack.visible_child = view_switcher;
+                       search.sensitive = !_is_collection_empty;
+               }
+               get { return _is_collection_empty; }
+       }
+
+       [GtkChild]
+       private Gtk.Stack title_stack;
+       [GtkChild]
+       private Gtk.Label empty_title;
        [GtkChild]
        private Gtk.StackSwitcher view_switcher;
        [GtkChild]


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