[gnome-games/wip/exalm/tnum: 2/24] collection-model: Add support for removing collections




commit c23bdbf66ead84ac58ad3095882954857c1c1e99
Author: Neville <nevilleantony98 gmail com>
Date:   Thu Aug 6 20:38:11 2020 +0530

    collection-model: Add support for removing collections

 src/collection/collection-model.vala | 15 +++++++++++++++
 src/ui/application.vala              |  1 +
 2 files changed, 16 insertions(+)
---
diff --git a/src/collection/collection-model.vala b/src/collection/collection-model.vala
index 66ce14ce3..05e45305c 100644
--- a/src/collection/collection-model.vala
+++ b/src/collection/collection-model.vala
@@ -2,6 +2,7 @@
 
 private class Games.CollectionModel : Object, ListModel {
        public signal void collection_added (Collection collection);
+       public signal void collection_removed (Collection collection);
 
        private Sequence<Collection> sequence;
        private int n_collections;
@@ -32,4 +33,18 @@ private class Games.CollectionModel : Object, ListModel {
                items_changed (iter.get_position (), 0, 1);
                collection_added (collection);
        }
+
+       public void remove_collection (Collection collection) {
+               var iter = sequence.lookup (collection, Collection.compare);
+
+               if (iter == null)
+                       return;
+
+               var pos = iter.get_position ();
+               iter.remove ();
+               n_collections--;
+
+               items_changed (pos, 1, 0);
+               collection_removed (collection);
+       }
 }
diff --git a/src/ui/application.vala b/src/ui/application.vala
index 7553822fb..ab738c4b6 100644
--- a/src/ui/application.vala
+++ b/src/ui/application.vala
@@ -298,6 +298,7 @@ public class Games.Application : Gtk.Application {
                        collection_model = new CollectionModel ();
                        collection_manager = new CollectionManager (database);
                        collection_manager.collection_added.connect (collection_model.add_collection);
+                       collection_manager.collection_removed.connect (collection_model.remove_collection);
 
                        load_game_list.begin ();
 


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