[gnome-documents] view: update the selection in a timeout on view creation



commit 75eb45c48b54a423ae799b693c2156dd5844f177
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Mon Sep 12 18:13:04 2011 -0400

    view: update the selection in a timeout on view creation
    
    It looks a bit like a hack; the timeout there allows the view to
    fill with the date from the model we just populated. We need to do this
    because we have to call scrollToPath() after the view is populated.

 src/view.js |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)
---
diff --git a/src/view.js b/src/view.js
index 06e3449..2d26011 100644
--- a/src/view.js
+++ b/src/view.js
@@ -24,6 +24,7 @@ const Gtk = imports.gi.Gtk;
 const _ = imports.gettext.gettext;
 
 const Lang = imports.lang;
+const Mainloop = imports.mainloop;
 const Signals = imports.signals;
 
 const Documents = imports.documents;
@@ -126,12 +127,19 @@ View.prototype = {
             this._selectionController.connect('selection-check',
                                               Lang.bind(this, this._updateSelection));
 
-        this._updateSelection(true);
+        // HACK: give the view some time to setup the scrolled window
+        // allocation, as updateSelection() might call scrollToPath().
+        // Is there anything better we can do here?
+        Mainloop.timeout_add(100, Lang.bind(this,
+            function() {
+                this._updateSelection();
+                return false;
+            }));
 
         this.connectToSelectionChanged(Lang.bind(this, this._onSelectionChanged));
     },
 
-    _updateSelection: function(scroll) {
+    _updateSelection: function() {
         let selectionObject = this.getSelectionObject();
         let selected = this._selectionController.getSelection().slice(0);
 
@@ -148,7 +156,7 @@ View.prototype = {
                     selectionObject.select_path(path);
                     selected.splice(urnIndex, 1);
 
-                    if (first && scroll) {
+                    if (first) {
                         this.scrollToPath(path);
                         first = false;
                     }



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