[gnome-documents] selections: track model deletions in selection mode



commit 24eb32547f0169bc6cac6d2290748b69f7450603
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Thu Mar 8 11:14:23 2012 -0500

    selections: track model deletions in selection mode
    
    If an item which is part of the selection got removed from the model,
    update our selection list to remove it.

 src/selections.js |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)
---
diff --git a/src/selections.js b/src/selections.js
index c81afac..370135c 100644
--- a/src/selections.js
+++ b/src/selections.js
@@ -595,6 +595,25 @@ SelectionController.prototype = {
     _init: function() {
         this._selection = [];
         this._selectionMode = false;
+
+        Global.documentManager.connect('item-removed',
+                                       Lang.bind(this, this._onDocumentRemoved));
+    },
+
+    _onDocumentRemoved: function(manager, item) {
+        let changed = false;
+        let filtered = this._selection.filter(Lang.bind(this,
+            function(value, index) {
+                if (item.id == value)
+                    changed = true;
+
+                return (item.id != value);
+            }));
+
+        if (changed) {
+            this._selection = filtered;
+            this.emit('selection-changed', this._selection);
+        }
     },
 
     setSelection: function(selection) {



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