From 8acdde3e87f8cabd179a068c54fe5b78fa38e40d Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Thu, 5 Apr 2012 22:54:53 -0700 Subject: - using Montage TextField component to handle any edits like keyup, paste, cut. - optimized Enter and Esc key handling Signed-off-by: Ananya Sen --- js/io/ui/save-as-dialog.reel/save-as-dialog.html | 9 ++- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 79 +++++++++++++----------- 2 files changed, 51 insertions(+), 37 deletions(-) (limited to 'js/io/ui/save-as-dialog.reel') diff --git a/js/io/ui/save-as-dialog.reel/save-as-dialog.html b/js/io/ui/save-as-dialog.reel/save-as-dialog.html index 374e3d48..453d7a96 100644 --- a/js/io/ui/save-as-dialog.reel/save-as-dialog.html +++ b/js/io/ui/save-as-dialog.reel/save-as-dialog.html @@ -18,13 +18,20 @@ } }, + "newFileName": { + "prototype": "montage/ui/textfield.reel", + "properties": { + "element": {"#": "newFileName"} + } + }, + "owner":{ "module": "js/io/ui/new-file-dialog/new-file-location.reel", "name": "SaveAsDialog", "properties": { "element": {"#": "saveAsDialog"}, "fileInputField": {"@": "fileInputField"}, - "newFileName": {"#": "newFileName"}, + "newFileName": {"@": "newFileName"}, "error":{"#": "error"}, "okButton":{"#": "okButton"}, "cancelButton":{"#": "cancelButton"} 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 81d1afee..5df91ab9 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 @@ -36,7 +36,12 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { writable: true, value: null }, - + prepareForDraw: { + value: function() { + this.newFileName.value = this.fileName; + this.fileInputField.newFileDirectory.value = this.folderUri; + } + }, willDraw: { enumerable: false, value: function() {} @@ -51,19 +56,16 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { var self = this; this.fileInputField.selectDirectory = true; this.fileInputField.pickerName = "saveAsDirectoryPicker"; - this.newFileName.value = this.fileName; - this.fileInputField.newFileDirectory.value = this.folderUri; - this.newFileName.addEventListener("keyup", function(evt){self.handleNewFileNameOnkeyup(evt);}, false); - this.newFileName.addEventListener("paste", this, false); - this.newFileName.addEventListener("search", this, false); + this.addEventListener("change@newFileName.value", this.handleNewFileNameChange, false); + this.newFileName.element.addEventListener("keyup", this, false); this.eventManager.addEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false); - this.okButton.addEventListener("click", function(evt){self.handleOkButtonAction(evt);}, false); this.cancelButton.addEventListener("click", function(evt){self.handleCancelButtonAction(evt);}, false); - this.newFileName.focus(); - this.newFileName.select(); + this.eventManager.addEventListener("enterKey", this, false); + this.eventManager.addEventListener("escKey", this, false); + this.enableOk(); @@ -81,52 +83,57 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { } }, true); + this.newFileName.element.focus(); + this.newFileName.element.select(); + } }, handleNewFileDirectorySet:{ value:function(evt){ - if(evt.keyCode === 13){ - if(!this.okButton.hasAttribute("disabled")) this.handleOkButtonAction(evt); - }else if(evt.keyCode === 27){ - this.handleCancelButtonAction(evt); - } - else{ - this.folderUri = evt._event.newFileDirectory; - if(this.isValidUri(this.folderUri)){ - this.enableOk(); - } + this.folderUri = evt._event.newFileDirectory; + if(this.isValidUri(this.folderUri)){ + this.enableOk(); } } }, - handlePaste:{ - value:function(evt){ - evt.preventDefault(); - evt.target.value = evt.clipboardData.getData("Text"); - this.handleNewFileNameOnkeyup(evt); - } - }, - - handleNewFileNameOnkeyup:{ + handleNewFileNameChange:{ value:function(evt){ this.fileName = this.newFileName.value; if(this.isValidFileName(this.fileName)){ this.enableOk(); } - if(evt.keyCode === 13){ - if(!this.okButton.hasAttribute("disabled")){ + } + }, + + handleKeyup:{ + value: function(evt){ + if(evt.keyCode === 13){ + if(!this.okButton.hasAttribute("disabled")){ this.handleOkButtonAction(evt); } - }else if(evt.keyCode === 27){ - this.handleCancelButtonAction(evt); + }else if(evt.keyCode === 27){ + this.handleCancelButtonAction(evt); + } + } + }, + + handleEnterKey:{ + value: function(evt){ + if((this.application.ninja.newFileController.saveAsDialog !== null) + && !this.okButton.hasAttribute("disabled")){ + + this.handleOkButtonAction(evt); } - } + } }, - handleSearch:{ - value:function(evt){ - this.handleNewFileNameOnkeyup(evt); + handleEscKey:{ + value: function(evt){ + if(this.application.ninja.newFileController.saveAsDialog !== null){ + this.handleCancelButtonAction(evt); + } } }, -- cgit v1.2.3 From efe18b4c8e52667683727139e9f9e28f66381164 Mon Sep 17 00:00:00 2001 From: Ananya Sen Date: Fri, 6 Apr 2012 15:31:43 -0700 Subject: block filenames and directories with all space Signed-off-by: Ananya Sen --- js/io/ui/save-as-dialog.reel/save-as-dialog.js | 1 + 1 file changed, 1 insertion(+) (limited to 'js/io/ui/save-as-dialog.reel') 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 5df91ab9..e2f50ff5 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 @@ -266,6 +266,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, { var status = false; if((fileName !== null) && (fileName !== "")){ fileName = fileName.replace(/^\s+|\s+$/g,""); + if(fileName === ""){return false;} status = !(/[/\\]/g.test(fileName)); if(status && navigator.userAgent.indexOf("Macintosh") != -1){//for Mac files beginning with . are hidden status = !(/^\./g.test(fileName)); -- cgit v1.2.3