[gnome-documents] view: Add a method to get the first document and keep the model private
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents] view: Add a method to get the first document and keep the model private
- Date: Mon, 17 Mar 2014 09:46:42 +0000 (UTC)
commit 153c6565544306728b289a0bdf3a9a832d75724b
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Mar 15 09:51:25 2014 +0100
view: Add a method to get the first document and keep the model private
Improves parts of 13954c74f593806a5111bea2129bbaa28423fab0
https://bugzilla.gnome.org/show_bug.cgi?id=719920
src/embed.js | 8 +++-----
src/view.js | 24 ++++++++++++++++++------
2 files changed, 21 insertions(+), 11 deletions(-)
---
diff --git a/src/embed.js b/src/embed.js
index 0d451f9..1a082e6 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -281,11 +281,9 @@ const Embed = new Lang.Class({
},
_onActivateResult: function() {
- let iter = this._view.model.model.get_iter_first()[1];
- if (iter) {
- let id = this._view.model.model.get_value(iter, Gd.MainColumns.ID);
- Application.documentManager.setActiveItem(Application.documentManager.getItemById(id))
- };
+ let doc = this._view.getFirstDocument();
+ if (doc)
+ Application.documentManager.setActiveItem(doc)
},
_onQueryStatusChanged: function() {
diff --git a/src/view.js b/src/view.js
index 0dd02de..b22004c 100644
--- a/src/view.js
+++ b/src/view.js
@@ -187,7 +187,7 @@ const ViewContainer = new Lang.Class({
this._adjustmentChangedId = 0;
this._scrollbarVisibleId = 0;
- this.model = new ViewModel();
+ this._model = new ViewModel();
this.widget = new Gtk.Grid({ orientation: Gtk.Orientation.VERTICAL });
this.view = new Gd.MainView({ shadow_type: Gtk.ShadowType.NONE });
@@ -248,6 +248,18 @@ const ViewContainer = new Lang.Class({
this._addListRenderers();
},
+ getFirstDocument: function() {
+ let doc = null;
+
+ let iter = this._model.model.get_iter_first()[1];
+ if (iter) {
+ let id = this._model.model.get_value(iter, Gd.MainColumns.ID);
+ doc = Application.documentManager.getItemById(id);
+ }
+
+ return doc;
+ },
+
_addListRenderers: function() {
let listWidget = this.view.get_generic_view();
@@ -332,7 +344,7 @@ const ViewContainer = new Lang.Class({
if (!status) {
// setup a model if we're not querying
- this.view.set_model(this.model.model);
+ this.view.set_model(this._model.model);
// unfreeze selection
Application.selectionController.freezeSelection(false);
@@ -356,13 +368,13 @@ const ViewContainer = new Lang.Class({
let generic = this.view.get_generic_view();
let first = true;
- this.model.model.foreach(Lang.bind(this,
+ this._model.model.foreach(Lang.bind(this,
function(model, path, iter) {
- let id = this.model.model.get_value(iter, Gd.MainColumns.ID);
+ let id = this._model.model.get_value(iter, Gd.MainColumns.ID);
let idIndex = selected.indexOf(id);
if (idIndex != -1) {
- this.model.model.set_value(iter, Gd.MainColumns.SELECTED, true);
+ this._model.model.set_value(iter, Gd.MainColumns.SELECTED, true);
newSelection.push(id);
if (first) {
@@ -388,7 +400,7 @@ const ViewContainer = new Lang.Class({
_onViewSelectionChanged: function() {
// update the selection on the controller when the view signals a change
let selectedURNs = Utils.getURNsFromPaths(this.view.get_selection(),
- this.model.model);
+ this._model.model);
Application.selectionController.setSelection(selectedURNs);
},
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]