From f3b6a62f110be31a9438a6172694b111ffd4d507 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 17 Feb 2012 11:07:42 -0800 Subject: -added keyboard control for saving documents -mark html design view when element is added or deleted Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 21 +++++++++++++++++++-- js/mediators/keyboard-mediator.js | 9 ++++++++- 2 files changed, 27 insertions(+), 3 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index b1a22c1b..6f31e24d 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -50,12 +50,21 @@ DocumentController = exports.DocumentController = Montage.create(Component, { deserializedFromTemplate: { value: function() { + var self = this; + this.eventManager.addEventListener("appLoaded", this, false); this.eventManager.addEventListener("executeFileOpen", this, false); this.eventManager.addEventListener("executeNewFile", this, false); this.eventManager.addEventListener("executeSave", this, false); this.eventManager.addEventListener("recordStyleChanged", this, false); + + //event listener to detect a change in the html design view + this.eventManager.addEventListener("elementAdded", function(evt){self.markCurrentDocumentChanged()}, false); + this.eventManager.addEventListener("elementDeleted", function(evt){self.markCurrentDocumentChanged()}, false); + //todo: add all applicable event listeners + //end-event listener to detect a change in the html design view + } }, @@ -88,8 +97,10 @@ DocumentController = exports.DocumentController = Montage.create(Component, { //TODO: Check for appropiate structures handleExecuteSave: { value: function(event) { - //Text and HTML document classes should return the same save object for fileSave - this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); + if(!!this.activeDocument){ + //Text and HTML document classes should return the same save object for fileSave + this.application.ninja.ioMediator.fileSave(this.activeDocument.save(), this.fileSaveResult.bind(this)); + } } }, //////////////////////////////////////////////////////////////////// @@ -427,5 +438,11 @@ DocumentController = exports.DocumentController = Montage.create(Component, { value: function() { return "userDocument_" + (this._iframeCounter++); } + }, + + markCurrentDocumentChanged:{ + value: function(){ + this.activeDocument.dirtyFlag = true; } + } }); diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index a1fdead3..e348a09b 100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js @@ -85,7 +85,7 @@ exports.KeyboardMediator = Montage.create(Component, { handleKeydown: { value: function(evt) { - if(document.activeElement.nodeName !== "BODY") { + if((document.activeElement.nodeName !== "BODY") && (this.application.ninja.documentController.activeDocument.currentView === "design")) { // Don't do anything if an input or other control is focused return; } @@ -110,6 +110,13 @@ exports.KeyboardMediator = Montage.create(Component, { return; } + // Check if cmd+s/ctrl+s for Save (Windows/Mac) + if ((evt.keyCode == Keyboard.S) && (evt.ctrlKey || evt.metaKey) && !evt.shiftKey) { + NJevent("executeSave"); + evt.preventDefault(); + return; + } + // Check if cmd+shift+z for Redo (Mac) if ((evt.keyCode == Keyboard.Z) && evt.metaKey && evt.shiftKey) { NJevent("executeRedo"); -- cgit v1.2.3