From 2557f463c1cfe2d0dd8ea187c184755bd141dab4 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 22 Mar 2012 10:38:44 -0700 Subject: IKNINJA-1302 : For File>New and File>SaveAll dialogs, 'ESC' key now triggers Cancel button and 'Enter' key now triggers OK button. For File picker, the 'ESC' now triggers the Cancel button. Signed-off-by: Ananya Sen Conflicts: js/io/ui/new-file-dialog/new-file-workflow-controller.js Signed-off-by: Ananya Sen --- js/io/ui/file-picker/file-picker-controller.js | 7 +++++- .../picker-navigator.reel/picker-navigator.js | 2 +- .../new-file-location.reel/new-file-location.js | 6 +++++ .../new-file-options-navigator.js | 8 ++++++ .../new-file-workflow-controller.js | 14 +++++++++-- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 23 +++++++++++++++-- js/mediators/keyboard-mediator.js | 29 ++++++++++++++++++++++ 7 files changed, 83 insertions(+), 6 deletions(-) diff --git a/js/io/ui/file-picker/file-picker-controller.js b/js/io/ui/file-picker/file-picker-controller.js index 105dc223..e3276ee6 100755 --- a/js/io/ui/file-picker/file-picker-controller.js +++ b/js/io/ui/file-picker/file-picker-controller.js @@ -23,6 +23,11 @@ var FilePickerController = exports.FilePickerController = Montage.create(require } }, + pickerNavChoices:{ + enumerable: true, + value: null + }, + filePickerPopupType:{ enumerable: false, value: "filePicker" @@ -149,7 +154,7 @@ var FilePickerController = exports.FilePickerController = Montage.create(require writable:false, enumerable:true, value:function(callback, aModel){ - var pickerNavChoices = Montage.create(pickerNavigatorReel); + var pickerNavChoices = this.pickerNavChoices = Montage.create(pickerNavigatorReel); var initUri = aModel.currentRoot; //remove extra / at the end diff --git a/js/io/ui/file-picker/picker-navigator.reel/picker-navigator.js b/js/io/ui/file-picker/picker-navigator.reel/picker-navigator.js index 7a9d90b4..e31fa29d 100644 --- a/js/io/ui/file-picker/picker-navigator.reel/picker-navigator.js +++ b/js/io/ui/file-picker/picker-navigator.reel/picker-navigator.js @@ -258,7 +258,6 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { this.element.addEventListener("refreshTreeSegment", function(evt){that.handlePickerNavRefreshTreeSegment(evt);}, false); this.resultsArea.addEventListener("click", function(evt){that.handleResultsAreaClick(evt);}, false); this.element.addEventListener("click", function(evt){that.handlePickerNavClick(evt);}, false); - this.okButton.addEventListener("click", function(evt){that.handleOkButtonAction(evt);}, false); this.cancelButton.addEventListener("click", function(evt){that.handleCancelButtonAction(evt);}, false); @@ -1071,6 +1070,7 @@ var PickerNavigator = exports.PickerNavigator = Montage.create(Component, { //clear memory - TODO:check for more memory leaks this.pickerModel = null; this.application.ninja.filePickerController._directoryContentCache = {}; + this.application.ninja.filePickerController.pickerNavChoices = null; //remove listeners this.element.removeEventListener("openFolder", this, false);//add icon double click event listener to reload iconList with new set of data this.element.removeEventListener("selectedItem", this, false);//for single selection only diff --git a/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js b/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js index 0e1e09a4..c4b7ea99 100755 --- a/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js +++ b/js/io/ui/new-file-dialog/new-file-location.reel/new-file-location.js @@ -34,6 +34,12 @@ var NewFileLocation = exports.NewFileLocation = Montage.create(Component, { newFileNameSetEvent.newFileName = this.newFileName.value; this.eventManager.dispatchEvent(newFileNameSetEvent); } + if(evt.keyCode === 13){ + var enterPressedEvent = document.createEvent("Events"); + enterPressedEvent.initEvent("enterPressed", false, false); + enterPressedEvent.newFileName = this.newFileName.value; + this.eventManager.dispatchEvent(enterPressedEvent); + } } } diff --git a/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js b/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js index aaf39005..5adcc250 100644 --- a/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js +++ b/js/io/ui/new-file-dialog/new-file-options-navigator.reel/new-file-options-navigator.js @@ -106,6 +106,12 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C this.okButton.addEventListener("click", function(evt){that.handleOkButtonAction(evt);}, false); this.cancelButton.addEventListener("click", function(evt){that.handleCancelButtonAction(evt);}, false); + this.element.addEventListener("enterPressed", function(evt){ + if(!that.okButton.hasAttribute("disabled")){ + that.handleOkButtonAction(evt); + } + }, false); + if(!!this.newFileModel.defaultProjectType){ var templates = this.newFileModel.prepareContents(this.newFileModel.defaultProjectType); this.templateList = iconsListModule.IconsList.create(); @@ -382,6 +388,8 @@ var NewFileOptionsNavigator = exports.NewFileOptionsNavigator = Montage.create(C this.element.removeEventListener("selectedItem", function(evt){that.handleNewFileNavSelectedItem(evt);}, false);//for single selection only this.eventManager.removeEventListener("newFileDirectorySet", function(evt){that.handleNewFileDirectorySet(evt);}, false); this.eventManager.removeEventListener("newFileNameSet", function(evt){that.handleNewFileNameSet(evt);}, false); + + this.application.ninja.newFileController.newFileOptionsNav = null; } }, diff --git a/js/io/ui/new-file-dialog/new-file-workflow-controller.js b/js/io/ui/new-file-dialog/new-file-workflow-controller.js index d065ca35..279a74b4 100755 --- a/js/io/ui/new-file-dialog/new-file-workflow-controller.js +++ b/js/io/ui/new-file-dialog/new-file-workflow-controller.js @@ -27,6 +27,16 @@ var NewFileWorkflowController = exports.NewFileWorkflowController = Montage.cre value: null }, + newFileOptionsNav:{ + enumerable:true, + value: null + }, + + saveAsDialog:{ + enumerable:true, + value: null + }, + showNewFileDialog:{ writable:false, enumerable:true, @@ -49,7 +59,7 @@ var NewFileWorkflowController = exports.NewFileWorkflowController = Montage.cre this.model.defaultProjectType = lastSelectedProjectType; } - var newFileOptionsNav = newFileOptionsNavigatorModule.NewFileOptionsNavigator.create(); + var newFileOptionsNav = this.newFileOptionsNav = newFileOptionsNavigatorModule.NewFileOptionsNavigator.create(); newFileOptionsNav.newFileModel = this.model; var popup = Popup.create(); @@ -70,7 +80,7 @@ var NewFileWorkflowController = exports.NewFileWorkflowController = Montage.cre var fileName = data.fileName || "filename.txt"; var folderUri = data.folderUri || "/Documents"; - var saveAsDialog = saveAsModule.SaveAsDialog.create(); + var saveAsDialog = this.saveAsDialog = saveAsModule.SaveAsDialog.create(); saveAsDialog.fileName = fileName; saveAsDialog.folderUri = folderUri; saveAsDialog.callback = data.callback; diff --git a/js/io/ui/save-as-dialog.reel/save-as-dialog.js b/js/io/ui/save-as-dialog.reel/save-as-dialog.js index c60a92f9..98749106 100644 --- a/js/io/ui/save-as-dialog.reel/save-as-dialog.js +++ b/js/io/ui/save-as-dialog.reel/save-as-dialog.js @@ -83,6 +83,11 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { this.enableOk(); } } + if(evt.keyCode === 13){ + if(!this.okButton.hasAttribute("disabled")){ + this.handleOkButtonAction(evt); + } + } } }, @@ -99,7 +104,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { handleCancelButtonAction :{ value:function(evt){ //clean up memory - //this.cleanup(); + this.cleanup(); if(this.popup){ this.popup.hide(); @@ -134,7 +139,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { if(success){ //clean up memory - //this.cleanup(); + this.cleanup(); if(this.popup){ this.popup.hide(); @@ -227,6 +232,20 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { } return status; } + }, + + cleanup:{ + value:function(){ + var self = this; + + //remove event listener + this.newFileName.removeEventListener("keyup", function(evt){self.handleNewFileNameOnkeyup(evt);}, false); + this.eventManager.removeEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false); + this.okButton.removeEventListener("click", function(evt){self.handleOkButtonAction(evt);}, false); + this.cancelButton.removeEventListener("click", function(evt){self.handleCancelButtonAction(evt);}, false); + + this.application.ninja.newFileController.saveAsDialog = null; } + } }); \ No newline at end of file diff --git a/js/mediators/keyboard-mediator.js b/js/mediators/keyboard-mediator.js index 65dd34cd..63dcfa88 100755 --- a/js/mediators/keyboard-mediator.js +++ b/js/mediators/keyboard-mediator.js @@ -246,6 +246,35 @@ exports.KeyboardMediator = Montage.create(Component, { return; } + // check for ENTER key + if((evt.keyCode == Keyboard.ENTER) && !(evt.ctrlKey || evt.metaKey)) { + //new file + if((this.application.ninja.newFileController.newFileOptionsNav !== null) + && !this.application.ninja.newFileController.newFileOptionsNav.okButton.hasAttribute("disabled")){ + + this.application.ninja.newFileController.newFileOptionsNav.handleOkButtonAction(); + } + //save as + if((this.application.ninja.newFileController.saveAsDialog !== null) + && !this.application.ninja.newFileController.saveAsDialog.okButton.hasAttribute("disabled")){ + + this.application.ninja.newFileController.saveAsDialog.handleOkButtonAction(); + } + return; + } + //ESC key + if(evt.keyCode === Keyboard.ESCAPE){ + if(this.application.ninja.filePickerController.pickerNavChoices !== null){ + this.application.ninja.filePickerController.pickerNavChoices.handleCancelButtonAction(); + } + if(this.application.ninja.newFileController.newFileOptionsNav !== null){ + this.application.ninja.newFileController.newFileOptionsNav.handleCancelButtonAction(); + } + if(this.application.ninja.newFileController.saveAsDialog !== null){ + this.application.ninja.newFileController.saveAsDialog.handleCancelButtonAction(); + } + return; + } } }, -- cgit v1.2.3