[gnome-documents] view: scroll to the first selected object when updating selection



commit cd0763986da96185d9c0d9b3bb72932063783627
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Wed Aug 31 17:26:46 2011 -0400

    view: scroll to the first selected object when updating selection

 src/iconView.js |    4 ++++
 src/listView.js |    4 ++++
 src/view.js     |   10 ++++++++--
 3 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/src/iconView.js b/src/iconView.js
index d57f26d..3f865bb 100644
--- a/src/iconView.js
+++ b/src/iconView.js
@@ -73,6 +73,10 @@ IconView.prototype = {
         return this.widget.get_path_at_pos(position[0], position[1]);
     },
 
+    scrollToPath: function(path) {
+        this.widget.scroll_to_path(path, false, 0, 0);
+    },
+
     createRenderers: function() {
         let pixbufRenderer =
             new Gtk.CellRendererPixbuf({ xalign: 0.5,
diff --git a/src/listView.js b/src/listView.js
index 4dc9f26..dae6273 100644
--- a/src/listView.js
+++ b/src/listView.js
@@ -72,6 +72,10 @@ ListView.prototype = {
         return this.widget.get_path_at_pos(position[0], position[1])[1];
     },
 
+    scrollToPath: function(path) {
+        this.widget.scroll_to_cell(path, null, false, 0, 0);
+    },
+
     createRenderers: function() {
         let col = new Gtk.TreeViewColumn();
         this.widget.append_column(col);
diff --git a/src/view.js b/src/view.js
index 7d1c577..f199b9c 100644
--- a/src/view.js
+++ b/src/view.js
@@ -92,18 +92,19 @@ View.prototype = {
             this._selectionController.connect('selection-check',
                                               Lang.bind(this, this._updateSelection));
 
-        this._updateSelection();
+        this._updateSelection(true);
 
         this.connectToSelectionChanged(Lang.bind(this, this._onSelectionChanged));
     },
 
-    _updateSelection: function() {
+    _updateSelection: function(scroll) {
         let selectionObject = this.getSelectionObject();
         let selected = this._selectionController.getSelection().slice(0);
 
         if (!selected.length)
             return;
 
+        let first = true;
         this._treeModel.foreach(Lang.bind(this,
             function(model, path, iter) {
                 let urn = this._treeModel.get_value(iter, Documents.ModelColumns.URN);
@@ -112,6 +113,11 @@ View.prototype = {
                 if (urnIndex != -1) {
                     selectionObject.select_path(path);
                     selected.splice(urnIndex, 1);
+
+                    if (first && scroll) {
+                        this.scrollToPath(path);
+                        first = false;
+                    }
                 }
 
                 if (selected.length == 0)



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