From 50e555587d3a97dbfc75c33f3589cfccee392180 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 20 Feb 2012 12:04:57 -0800 Subject: - moved tools specific keyboard controls for desing view only - stopped snapping when all documents are closed Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 2 + js/mediators/keyboard-mediator.js | 220 ++++++++++++++++++---------------- 2 files changed, 117 insertions(+), 105 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 57289448..f8507086 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -303,6 +303,8 @@ var DocumentController = exports.DocumentController = Montage.create(Component, this._removeDocumentView(doc.container); this.application.ninja.stage.stageView.hideRulers(); document.getElementById("iframeContainer").style.display="block"; + + this.application.ninja.stage.hideCanvas(true); } } }, diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index 40b26582..0282060f 100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js @@ -85,23 +85,115 @@ exports.KeyboardMediator = Montage.create(Component, { handleKeydown: { value: function(evt) { - if((document.activeElement.nodeName !== "BODY") && (!!this.application.ninja.documentController.activeDocument) - && (this.application.ninja.documentController.activeDocument.currentView === "design")) { - // Don't do anything if an input or other control is focused - return; - } - // Disable defaults for the Arrow Keys - if((evt.keyCode == Keyboard.LEFT) || (evt.keyCode == Keyboard.RIGHT) || (evt.keyCode == Keyboard.UP) || (evt.keyCode == Keyboard.DOWN)) { - evt.preventDefault(); - } + //keyboard controls for html design view + if((!!this.application.ninja.documentController.activeDocument) && (this.application.ninja.documentController.activeDocument.currentView === "design")){ + + // Don't do anything if an input or other control is focused + if(document.activeElement.nodeName !== "BODY") { + return; + } + + // Disable defaults for the Arrow Keys + if((evt.keyCode == Keyboard.LEFT) || (evt.keyCode == Keyboard.RIGHT) || (evt.keyCode == Keyboard.UP) || (evt.keyCode == Keyboard.DOWN)) { + evt.preventDefault(); + } + + // Check DELETE OR BACKSPACE + if((evt.keyCode == Keyboard.BACKSPACE) || (evt.keyCode == Keyboard.DELETE)) { + evt.stopImmediatePropagation(); + evt.preventDefault(); + NJevent("deleting"); + return; + } + + + // Shortcut for Selection Tool is V + if(evt.keyCode === Keyboard.V) { + evt.preventDefault(); + this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[0]}); + return; + } + + // Shortcut for Tag Tool is D + if(evt.keyCode === Keyboard.D){ + evt.preventDefault(); + this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[4]}); + return; + } + + // Shortcut for Rotate Tool is W + if(evt.keyCode === Keyboard.W){ + evt.preventDefault(); + this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[2]}); + return; + } + + // Shortcut for Translate Tool is G + if(evt.keyCode === Keyboard.G){ + evt.preventDefault(); + this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[3]}); + return; + } + + // Shortcut for Rectangle Tool is R + // unless the user is pressing the command key. + // If the user is pressing the command key, they want to refresh the browser. + if((evt.keyCode === Keyboard.R) && !evt.metaKey) { + evt.preventDefault(); + this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); + this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[1]}); + return; + } + + // Shortcut for Oval Tool is O + if(evt.keyCode === Keyboard.O) { + evt.preventDefault(); + this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); + this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[0]}); + return; + } + + // Shortcut for Line Tool is L + if(evt.keyCode === Keyboard.L ) { + evt.preventDefault(); + this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); + this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[2]}); + return; + } + + if(evt.keyCode === Keyboard.H ) { + evt.preventDefault(); + this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[15]}); + return; + } + + if(evt.keyCode === Keyboard.Z ) { + evt.preventDefault(); + this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[16]}); + return; + } + + // Check if cmd+a/ctrl+a for Select All + if((evt.keyCode == Keyboard.A) && (evt.ctrlKey || evt.metaKey)) { + NJevent("selectAll"); + return; + } + + if(evt.keyCode === Keyboard.ESCAPE){//ESC key + //console.log("ESC key pressed"); + if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleEscape(evt); + //menuViewManagerModule.MenuViewManager.closeMenu("mainMenuBar"); + } + + + if((evt.keyCode == Keyboard.ENTER) && (evt.ctrlKey || evt.metaKey)) { + this.application.ninja.executeChromePreview(); + return; + } + + if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleKeyPress(evt); - // Check DELETE OR BACKSPACE - if((evt.keyCode == Keyboard.BACKSPACE) || (evt.keyCode == Keyboard.DELETE)) { - evt.stopImmediatePropagation(); - evt.preventDefault(); - NJevent("deleting"); - return; } // Check if cmd+z/ctrl+z for Undo (Windows/Mac) @@ -132,103 +224,21 @@ exports.KeyboardMediator = Montage.create(Component, { return; } - // Shortcut for Selection Tool is V - if(evt.keyCode === Keyboard.V) { - evt.preventDefault(); - this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[0]}); - return; - } - - // Shortcut for Tag Tool is D - if(evt.keyCode === Keyboard.D){ - evt.preventDefault(); - this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[4]}); - return; - } - - // Shortcut for Rotate Tool is W - if(evt.keyCode === Keyboard.W){ - evt.preventDefault(); - this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[2]}); - return; - } - - // Shortcut for Translate Tool is G - if(evt.keyCode === Keyboard.G){ - evt.preventDefault(); - this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[3]}); - return; - } - - // Shortcut for Rectangle Tool is R - // unless the user is pressing the command key. - // If the user is pressing the command key, they want to refresh the browser. - if((evt.keyCode === Keyboard.R) && !evt.metaKey) { - evt.preventDefault(); - this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); - this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[1]}); - return; - } - - // Shortcut for Oval Tool is O - if(evt.keyCode === Keyboard.O) { - evt.preventDefault(); - this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); - this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[0]}); - return; - } - - // Shortcut for Line Tool is L - if(evt.keyCode === Keyboard.L ) { - evt.preventDefault(); - this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[7]}); - this.application.ninja.handleSelectSubTool({"detail": this.application.ninja.toolsData.defaultToolsData[7].subtools[2]}); - return; - } - - if(evt.keyCode === Keyboard.H ) { - evt.preventDefault(); - this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[15]}); - return; - } - - if(evt.keyCode === Keyboard.Z ) { - evt.preventDefault(); - this.application.ninja.handleSelectTool({"detail": this.application.ninja.toolsData.defaultToolsData[16]}); - return; - } - - // Check if cmd+a/ctrl+a for Select All - if((evt.keyCode == Keyboard.A) && (evt.ctrlKey || evt.metaKey)) { - NJevent("selectAll"); - return; - } - - if(evt.keyCode === Keyboard.ESCAPE){//ESC key - //console.log("ESC key pressed"); - if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleEscape(evt); - //menuViewManagerModule.MenuViewManager.closeMenu("mainMenuBar"); - } - - // Check if cmd+a/ctrl+a for Select All - if((evt.keyCode == Keyboard.ENTER) && (evt.ctrlKey || evt.metaKey)) { - this.application.ninja.executeChromePreview(); - return; - } - - if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleKeyPress(evt); } }, handleKeyup: { value: function(evt) { - if(document.activeElement.nodeName !== "BODY") { - // Don't do anything if an input or other control is focused - return; + //keyboard controls for html design view + if((!!this.application.ninja.documentController.activeDocument) && (this.application.ninja.documentController.activeDocument.currentView === "design")){ + if(document.activeElement.nodeName !== "BODY") { + // Don't do anything if an input or other control is focused + return; + } + + if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleKeyUp(evt); } - - if(this.application.ninja.toolsData) this.application.ninja.toolsData.selectedToolInstance.HandleKeyUp(evt); } }, -- cgit v1.2.3 From 3251315ecc22544dab50623ee5862e00dfe02302 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Mon, 20 Feb 2012 15:15:37 -0800 Subject: check cloud availability before open file picker and new file dialogs Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 22 +++++++++++++++------- js/io/system/coreioapi.js | 10 ++++++---- js/io/ui/cloudpopup.reel/cloudpopup.js | 11 +++++++++++ 3 files changed, 32 insertions(+), 11 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index f8507086..e279d5c5 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -70,7 +70,7 @@ var DocumentController = exports.DocumentController = Montage.create(Component, value: function (request) { if (request.url.indexOf('js/document/templates/montage-html') !== -1) { - console.log(request); + //console.log(request); //TODO: Figure out why active document is not available here @@ -98,18 +98,26 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteFileOpen: { value: function(event) { var pickerSettings = event._event.settings || {}; - pickerSettings.callback = this.openFileWithURI.bind(this); - pickerSettings.pickerMode = "read"; - pickerSettings.inFileMode = true; - this.application.ninja.filePickerController.showFilePicker(pickerSettings); + //adding callback so that file picker can be opened after checking cloud status + this.application.ninja.coreIoApi.cloudAvailable(function(){ + pickerSettings.callback = this.openFileWithURI.bind(this); + pickerSettings.pickerMode = "read"; + pickerSettings.inFileMode = true; + this.application.ninja.filePickerController.showFilePicker(pickerSettings); + }.bind(this)); + } }, handleExecuteNewFile: { value: function(event) { var newFileSettings = event._event.settings || {}; - newFileSettings.callback = this.createNewFile.bind(this); - this.application.ninja.newFileController.showNewFileDialog(newFileSettings); + //adding callback so that new file dialog can be opened after checking cloud status + this.application.ninja.coreIoApi.cloudAvailable(function(){ + newFileSettings.callback = this.createNewFile.bind(this); + this.application.ninja.newFileController.showNewFileDialog(newFileSettings); + }.bind(this)); + } }, diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 2051da43..1bc66532 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -234,18 +234,19 @@ exports.CoreIoApi = Montage.create(Component, { //Method to check status of I/O API, will return false if not active cloudAvailable: { enumerable: false, - value: function () { + value: function (callback) { var cloud = this.getCloudStatus(); // if (this.rootUrl && cloud.status === 200) { //Active this.cloudData.name = cloud.response['name']; this.cloudData.root = cloud.response['server-root']; - return true; + if(!!callback){callback();} + else{return true}; } else { //Inactive if (!this._cloudDialogOpen && this.application.ninja) { - this.showCloudDialog(); + this.showCloudDialog(callback); } return false; } @@ -273,7 +274,7 @@ exports.CoreIoApi = Montage.create(Component, { // showCloudDialog: { enumerable: false, - value: function () { + value: function (callback) { // this._cloudDialogOpen = true; // @@ -294,6 +295,7 @@ exports.CoreIoApi = Montage.create(Component, { this._cloudDialogComponents.dialog.element = popup; this._cloudDialogComponents.dialog.needsDraw = true; this._cloudDialogComponents.dialog.element.style.opacity = 0; + this._cloudDialogComponents.dialog.callback = callback; // this._cloudDialogComponents.dialog.addEventListener('firstDraw', this, false); } diff --git a/js/io/ui/cloudpopup.reel/cloudpopup.js b/js/io/ui/cloudpopup.reel/cloudpopup.js index a2283d46..8e24f1a1 100755 --- a/js/io/ui/cloudpopup.reel/cloudpopup.js +++ b/js/io/ui/cloudpopup.reel/cloudpopup.js @@ -23,6 +23,12 @@ exports.CloudPopup = Montage.create(Component, { }, //////////////////////////////////////////////////////////////////// // + callback:{ + writable:true, + enumerable:true, + value:null + }, + // components: { enumerable: false, value: {test_btn: null, ok_btn: null, cancel_btn: null, download_btn: null, status: null, url: null} @@ -121,6 +127,10 @@ exports.CloudPopup = Montage.create(Component, { value: function() { // this.application.ninja.coreIoApi.hideCloudDialog(); + this.application.ninja.coreIoApi._cloudDialogOpen=false; + if(!!this.callback){ + this.callback(); + } } }, //////////////////////////////////////////////////////////////////// @@ -131,6 +141,7 @@ exports.CloudPopup = Montage.create(Component, { // this.application.ninja.coreIoApi.rootUrl = null; this.application.ninja.coreIoApi.hideCloudDialog(); + this.application.ninja.coreIoApi._cloudDialogOpen=false; } } //////////////////////////////////////////////////////////////////// -- cgit v1.2.3 From 9f80fc891b7952900dabec04877606c6c8229c61 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Tue, 21 Feb 2012 09:47:05 -0800 Subject: Revert "check cloud availability before open file picker and new file dialogs" This reverts commit 3251315ecc22544dab50623ee5862e00dfe02302. Conflicts: js/controllers/document-controller.js Signed-off-by: Ananya Sen --- js/controllers/document-controller.js | 20 ++++++-------------- js/io/system/coreioapi.js | 10 ++++------ js/io/ui/cloudpopup.reel/cloudpopup.js | 11 ----------- 3 files changed, 10 insertions(+), 31 deletions(-) (limited to 'js') diff --git a/js/controllers/document-controller.js b/js/controllers/document-controller.js index 3cd2c254..9a063280 100755 --- a/js/controllers/document-controller.js +++ b/js/controllers/document-controller.js @@ -100,26 +100,18 @@ var DocumentController = exports.DocumentController = Montage.create(Component, handleExecuteFileOpen: { value: function(event) { var pickerSettings = event._event.settings || {}; - //adding callback so that file picker can be opened after checking cloud status - this.application.ninja.coreIoApi.cloudAvailable(function(){ - pickerSettings.callback = this.openFileWithURI.bind(this); - pickerSettings.pickerMode = "read"; - pickerSettings.inFileMode = true; - this.application.ninja.filePickerController.showFilePicker(pickerSettings); - }.bind(this)); - + pickerSettings.callback = this.openFileWithURI.bind(this); + pickerSettings.pickerMode = "read"; + pickerSettings.inFileMode = true; + this.application.ninja.filePickerController.showFilePicker(pickerSettings); } }, handleExecuteNewFile: { value: function(event) { var newFileSettings = event._event.settings || {}; - //adding callback so that new file dialog can be opened after checking cloud status - this.application.ninja.coreIoApi.cloudAvailable(function(){ - newFileSettings.callback = this.createNewFile.bind(this); - this.application.ninja.newFileController.showNewFileDialog(newFileSettings); - }.bind(this)); - + newFileSettings.callback = this.createNewFile.bind(this); + this.application.ninja.newFileController.showNewFileDialog(newFileSettings); } }, diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index 1bc66532..2051da43 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -234,19 +234,18 @@ exports.CoreIoApi = Montage.create(Component, { //Method to check status of I/O API, will return false if not active cloudAvailable: { enumerable: false, - value: function (callback) { + value: function () { var cloud = this.getCloudStatus(); // if (this.rootUrl && cloud.status === 200) { //Active this.cloudData.name = cloud.response['name']; this.cloudData.root = cloud.response['server-root']; - if(!!callback){callback();} - else{return true}; + return true; } else { //Inactive if (!this._cloudDialogOpen && this.application.ninja) { - this.showCloudDialog(callback); + this.showCloudDialog(); } return false; } @@ -274,7 +273,7 @@ exports.CoreIoApi = Montage.create(Component, { // showCloudDialog: { enumerable: false, - value: function (callback) { + value: function () { // this._cloudDialogOpen = true; // @@ -295,7 +294,6 @@ exports.CoreIoApi = Montage.create(Component, { this._cloudDialogComponents.dialog.element = popup; this._cloudDialogComponents.dialog.needsDraw = true; this._cloudDialogComponents.dialog.element.style.opacity = 0; - this._cloudDialogComponents.dialog.callback = callback; // this._cloudDialogComponents.dialog.addEventListener('firstDraw', this, false); } diff --git a/js/io/ui/cloudpopup.reel/cloudpopup.js b/js/io/ui/cloudpopup.reel/cloudpopup.js index 34393db5..d2e82662 100755 --- a/js/io/ui/cloudpopup.reel/cloudpopup.js +++ b/js/io/ui/cloudpopup.reel/cloudpopup.js @@ -23,12 +23,6 @@ exports.CloudPopup = Montage.create(Component, { }, //////////////////////////////////////////////////////////////////// // - callback:{ - writable:true, - enumerable:true, - value:null - }, - // components: { enumerable: false, value: {test_btn: null, ok_btn: null, cancel_btn: null, download_btn: null, status: null, url: null} @@ -131,10 +125,6 @@ exports.CloudPopup = Montage.create(Component, { value: function() { // this.application.ninja.coreIoApi.hideCloudDialog(); - this.application.ninja.coreIoApi._cloudDialogOpen=false; - if(!!this.callback){ - this.callback(); - } } }, //////////////////////////////////////////////////////////////////// @@ -145,7 +135,6 @@ exports.CloudPopup = Montage.create(Component, { // this.application.ninja.coreIoApi.rootUrl = null; this.application.ninja.coreIoApi.hideCloudDialog(); - this.application.ninja.coreIoApi._cloudDialogOpen=false; } } //////////////////////////////////////////////////////////////////// -- cgit v1.2.3