From 108764dbdaa0c040de9146c2d722b6e53830cd54 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Wed, 23 May 2012 13:27:14 -0700 Subject: improve the closing of documents. Signed-off-by: Valerio Virgillito --- js/controllers/document-controller.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'js/controllers') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 7758f346..dadfaf05 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -393,14 +393,20 @@ var DocumentController = exports.DocumentController = Montage.create(Component, onCloseFile: { value: function(doc) { + var previousFocusedDocument; - this._documents.splice(this._documents.indexOf(doc), 1); + this._documents.splice(this._documents.indexOf(doc), 1); - this._activeDocument = null; - - this.application.ninja.stage.hideRulers(); + if(this._documents.length > 0) { + previousFocusedDocument = this._documents[this._documents.length - 1]; + this._activeDocument = previousFocusedDocument; + this.switchDocuments(this.activeDocument, previousFocusedDocument, true); + } else { + this._activeDocument = null; + this.application.ninja.stage.hideRulers(); - this.application.ninja.stage.hideCanvas(true); + this.application.ninja.stage.hideCanvas(true); + } //TODO: Use references for those instead of calling getElementById if(this._documents.length === 0){ -- cgit v1.2.3