[gnome-documents] embed: go through DocumentManager to listen for active item changes



commit d6b299f5b733a2bb7f2a8f1ed28cfda6130fcc56
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Tue Nov 8 22:00:20 2011 -0500

    embed: go through DocumentManager to listen for active item changes
    
    Instead of having an additional View signal for the same thing.

 src/embed.js |   16 ++++++++++++----
 src/view.js  |    4 +---
 2 files changed, 13 insertions(+), 7 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index bc90430..e3e290d 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -48,6 +48,7 @@ function ViewEmbed() {
 
 ViewEmbed.prototype  = {
     _init: function() {
+        this._activeItemId = 0;
         this._adjustmentValueId = 0;
         this._adjustmentChangedId = 0;
         this._loaderCancellable = null;
@@ -240,13 +241,11 @@ ViewEmbed.prototype  = {
         else
             this._view = new IconView.IconView(this);
 
-        this._view.connect('item-activated', Lang.bind(this, this._onViewItemActivated));
         this._scrolledWinView.add(this._view.widget);
     },
 
-    _onViewItemActivated: function(view, urn) {
-        let doc = Global.documentManager.getItemById(urn);
-        Global.documentManager.setActiveItem(doc);
+    _onActiveItemChanged: function() {
+        let doc = Global.documentManager.getActiveItem();
 
         // switch to preview mode, and schedule the spinnerbox to
         // move in if the document is not loaded by the timeout
@@ -316,6 +315,10 @@ ViewEmbed.prototype  = {
         this._docModel = null;
 
         Global.documentManager.setActiveItem(null);
+        this._activeItemId =
+            Global.documentManager.connect('active-changed',
+                                           Lang.bind(this, this._onActiveItemChanged));
+
         this._viewSettingsId =
             Global.settings.connect('changed::list-view',
                                     Lang.bind(this, this._initView));
@@ -401,6 +404,11 @@ ViewEmbed.prototype  = {
             this._queryErrorId = 0;
         }
 
+        if (this._activeItemId != 0) {
+            Global.documentManager.disconnect(this._activeItemId);
+            this._activeItemId = 0;
+        }
+
         Global.searchController.setSearchVisible(false);
 
         if (this._adjustmentValueId != 0) {
diff --git a/src/view.js b/src/view.js
index e1a1710..f124b32 100644
--- a/src/view.js
+++ b/src/view.js
@@ -24,7 +24,6 @@ const _ = imports.gettext.gettext;
 
 const Lang = imports.lang;
 const Mainloop = imports.mainloop;
-const Signals = imports.signals;
 
 const Documents = imports.documents;
 const Global = imports.global;
@@ -269,7 +268,6 @@ View.prototype = {
         let iter = this._treeModel.get_iter(path)[1];
         let urn = this._treeModel.get_value(iter, Documents.ModelColumns.URN);
 
-        this.emit('item-activated', urn);
+        Global.documentManager.setActiveItemById(urn);
     }
 };
-Signals.addSignalMethods(View.prototype);



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