[gnome-boxes/wip/feborges/flowbox: 18/24] collection: Handle hidden items at the model side



commit 6be1b22300353a2d9b244655912913087646957f
Author: Felipe Borges <felipeborges gnome org>
Date:   Thu Dec 21 12:28:42 2017 +0100

    collection: Handle hidden items at the model side
    
    A hidden item is a newly create item (machine) where the user is
    still visualizing the wizard, and therefore should'nt be presented
    in the views.
    
    Both views (IconView and ListView) used to handle the hidden_items
    independently, duplicating the code and logic.
    
    Now we can handle the hidden_items in a single place, in the Collection
    object as a result of the decoupling of model and view recently
    introduced.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=791839

 src/collection.vala |   34 ++++++++++++++++++++++++++++++++++
 src/icon-view.vala  |   31 -------------------------------
 src/list-view.vala  |   32 --------------------------------
 3 files changed, 34 insertions(+), 63 deletions(-)
---
diff --git a/src/collection.vala b/src/collection.vala
index 078be0e..15f4bf3 100644
--- a/src/collection.vala
+++ b/src/collection.vala
@@ -32,6 +32,8 @@ private class Boxes.Collection: GLib.Object {
 
     public GLib.ListStore items;
 
+    private GLib.List<CollectionItem> hidden_items;
+
     public uint length {
         get { return items.get_n_items (); }
     }
@@ -40,6 +42,7 @@ private class Boxes.Collection: GLib.Object {
 
     construct {
         items = new GLib.ListStore (typeof (CollectionItem));
+        hidden_items = new GLib.List<CollectionItem> ();
     }
 
     public Collection () {
@@ -50,6 +53,36 @@ private class Boxes.Collection: GLib.Object {
     }
 
     public void add_item (CollectionItem item) {
+        var machine = item as Machine;
+
+        if (machine == null) {
+            warning ("Cannot add item %p".printf (&item));
+
+            return;
+        }
+
+        var window = machine.window;
+        if (window.ui_state == UIState.WIZARD) {
+            // Don't show newly created items until user is out of wizard
+            hidden_items.append (item);
+
+            ulong ui_state_id = 0;
+            ui_state_id = window.notify["ui-state"].connect (() => {
+                if (window.ui_state == UIState.WIZARD)
+                    return;
+
+                if (hidden_items.find (item) != null) {
+                    add_item (item);
+                    hidden_items.remove (item);
+                }
+                window.disconnect (ui_state_id);
+            });
+
+            return;
+        }
+
+        item.set_state (window.ui_state);
+
         items.insert_sorted (item, (item1, item2) => {
             if (item1 == null || item2 == null)
                 return 0;
@@ -61,6 +94,7 @@ private class Boxes.Collection: GLib.Object {
     }
 
     public void remove_item (CollectionItem item) {
+        hidden_items.remove (item);
         for (int i = 0 ; i < length ; i++) {
            if (get_item (i) == item) {
                 items.remove (i);
diff --git a/src/icon-view.vala b/src/icon-view.vala
index 6073ce8..8221625 100644
--- a/src/icon-view.vala
+++ b/src/icon-view.vala
@@ -16,8 +16,6 @@ private class Boxes.IconView: Gtk.ScrolledWindow, Boxes.ICollectionView, Boxes.U
     [GtkChild]
     private Gtk.FlowBox flowbox;
 
-    private GLib.List<CollectionItem> hidden_items;
-
     private AppWindow window;
     private Boxes.ActionsPopover context_popover;
 
@@ -32,7 +30,6 @@ private class Boxes.IconView: Gtk.ScrolledWindow, Boxes.ICollectionView, Boxes.U
 
     construct {
         category = new Category (_("New and Recent"), Category.Kind.NEW);
-        hidden_items = new GLib.List<CollectionItem> ();
 
         setup_flowbox ();
 
@@ -60,37 +57,9 @@ private class Boxes.IconView: Gtk.ScrolledWindow, Boxes.ICollectionView, Boxes.U
     }
 
     public void add_item (CollectionItem item) {
-        var machine = item as Machine;
-
-        if (machine == null) {
-            warning ("Cannot add item %p".printf (&item));
-            return;
-        }
-
-        var window = machine.window;
-        if (window.ui_state == UIState.WIZARD) {
-            // Don't show newly created items until user is out of wizard
-            hidden_items.append (item);
-
-            ulong ui_state_id = 0;
-
-            ui_state_id = window.notify["ui-state"].connect (() => {
-                if (window.ui_state == UIState.WIZARD)
-                    return;
-
-                if (hidden_items.find (item) != null) {
-                    add_item (item);
-                    hidden_items.remove (item);
-                }
-                window.disconnect (ui_state_id);
-            });
-
-            return;
-        }
     }
 
     public void remove_item (CollectionItem item) {
-        hidden_items.remove (item);
     }
 
     public void select_by_criteria (SelectionCriteria criteria) {
diff --git a/src/list-view.vala b/src/list-view.vala
index 0f6b624..8c9812a 100644
--- a/src/list-view.vala
+++ b/src/list-view.vala
@@ -12,7 +12,6 @@ private class Boxes.ListView: Gtk.ScrolledWindow, Boxes.ICollectionView, Boxes.U
 
     private Gtk.SizeGroup size_group;
 
-    private GLib.List<CollectionItem> hidden_items;
     private HashTable<CollectionItem, ItemConnections> items_connections;
 
     private AppWindow window;
@@ -53,7 +52,6 @@ private class Boxes.ListView: Gtk.ScrolledWindow, Boxes.ICollectionView, Boxes.U
     }
 
     construct {
-        hidden_items = new GLib.List<CollectionItem> ();
         items_connections = new HashTable<CollectionItem, ItemConnections> (direct_hash, direct_equal);
 
         setup_list_box ();
@@ -86,40 +84,10 @@ private class Boxes.ListView: Gtk.ScrolledWindow, Boxes.ICollectionView, Boxes.U
     public void add_item (CollectionItem item) {
         var machine = item as Machine;
 
-        if (machine == null) {
-            warning ("Cannot add item %p".printf (&item));
-
-            return;
-        }
-
-        var window = machine.window;
-        if (window.ui_state == UIState.WIZARD) {
-            // Don't show newly created items until user is out of wizard
-            hidden_items.append (item);
-
-            ulong ui_state_id = 0;
-
-            ui_state_id = window.notify["ui-state"].connect (() => {
-                if (window.ui_state == UIState.WIZARD)
-                    return;
-
-                if (hidden_items.find (item) != null) {
-                    add_item (item);
-                    hidden_items.remove (item);
-                }
-                window.disconnect (ui_state_id);
-            });
-
-            return;
-        }
-
         items_connections[item] = new ItemConnections (this, machine);
-
-        item.set_state (window.ui_state);
     }
 
     public void remove_item (CollectionItem item) {
-        hidden_items.remove (item);
         items_connections.remove (item);
         remove_row (item);
     }


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