[gnome-documents] searchbar: Disconnect from global objects when the widget is destroyed



commit b941dcc9199609e5fcf0875596658f898205f8d1
Author: Alessandro Bono <shadow openaliasbox org>
Date:   Mon Aug 3 20:39:33 2015 +0200

    searchbar: Disconnect from global objects when the widget is destroyed
    
    Nobody was calling the destroy method, and, ideally, there shouldn't be
    a need to. We should just disconnect when the widget is getting
    destroyed.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=752792

 src/searchbar.js |   39 +++++++++++----------------------------
 1 files changed, 11 insertions(+), 28 deletions(-)
---
diff --git a/src/searchbar.js b/src/searchbar.js
index adca056..57df4d8 100644
--- a/src/searchbar.js
+++ b/src/searchbar.js
@@ -157,13 +157,13 @@ const OverviewSearchbar = new Lang.Class({
 
         this.parent();
 
-        this._sourcesId = Application.sourceManager.connect('active-changed',
+        let sourcesId = Application.sourceManager.connect('active-changed',
             Lang.bind(this, this._onActiveSourceChanged));
-        this._searchTypeId = Application.searchTypeManager.connect('active-changed',
+        let searchTypeId = Application.searchTypeManager.connect('active-changed',
             Lang.bind(this, this._onActiveTypeChanged));
-        this._searchMatchId = Application.searchMatchManager.connect('active-changed',
+        let searchMatchId = Application.searchMatchManager.connect('active-changed',
             Lang.bind(this, this._onActiveMatchChanged));
-        this._collectionId = Application.documentManager.connect('active-collection-changed',
+        let collectionId = Application.documentManager.connect('active-collection-changed',
             Lang.bind(this, this._onActiveCollectionChanged));
 
         this._onActiveSourceChanged();
@@ -171,6 +171,13 @@ const OverviewSearchbar = new Lang.Class({
         this._onActiveMatchChanged();
 
         this._searchEntry.set_text(Application.searchController.getString());
+        this.connect('destroy', Lang.bind(this,
+            function() {
+                Application.sourceManager.disconnect(sourcesId);
+                Application.searchTypeManager.disconnect(searchTypeId);
+                Application.searchMatchManager.disconnect(searchMatchId);
+                Application.documentManager.disconnect(collectionId);
+            }));
     },
 
     createSearchWidgets: function() {
@@ -294,30 +301,6 @@ const OverviewSearchbar = new Lang.Class({
         this._dropdownButton.set_active(true);
     },
 
-    destroy: function() {
-        if (this._sourcesId != 0) {
-            Application.sourceManager.disconnect(this._sourcesId);
-            this._sourcesId = 0;
-        }
-
-        if (this._searchTypeId != 0) {
-            Application.searchTypeManager.disconnect(this._searchTypeId);
-            this._searchTypeId = 0;
-        }
-
-        if (this._searchMatchId != 0) {
-            Application.searchMatchManager.disconnect(this._searchMatchId);
-            this._searchMatchId = 0;
-        }
-
-        if (this._collectionId != 0) {
-            Application.documentManager.disconnect(this._collectionId);
-            this._collectionId = 0;
-        }
-
-        this.parent();
-    },
-
     reveal: function() {
         this._selectAll.enabled = false;
         this.parent();


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