aboutsummaryrefslogtreecommitdiff
path: root/js/io/ui/save-as-dialog.reel/save-as-dialog.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/io/ui/save-as-dialog.reel/save-as-dialog.js')
-rw-r--r--js/io/ui/save-as-dialog.reel/save-as-dialog.js63
1 files changed, 58 insertions, 5 deletions
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 0a322b99..c5ed8d33 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
@@ -55,18 +55,42 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
55 this.fileInputField.newFileDirectory.value = this.folderUri; 55 this.fileInputField.newFileDirectory.value = this.folderUri;
56 56
57 this.newFileName.addEventListener("keyup", function(evt){self.handleNewFileNameOnkeyup(evt);}, false); 57 this.newFileName.addEventListener("keyup", function(evt){self.handleNewFileNameOnkeyup(evt);}, false);
58 this.newFileName.addEventListener("paste", this, false);
58 this.eventManager.addEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false); 59 this.eventManager.addEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false);
59 60
60 this.okButton.addEventListener("click", function(evt){self.handleOkButtonAction(evt);}, false); 61 this.okButton.addEventListener("click", function(evt){self.handleOkButtonAction(evt);}, false);
61 this.cancelButton.addEventListener("click", function(evt){self.handleCancelButtonAction(evt);}, false); 62 this.cancelButton.addEventListener("click", function(evt){self.handleCancelButtonAction(evt);}, false);
62 63
64 this.newFileName.focus();
65 this.newFileName.select();
66
63 this.enableOk(); 67 this.enableOk();
68
69 this.element.addEventListener("keyup", function(evt){
70 if(evt.keyCode == 27) {//ESC key
71 if(self.application.ninja.newFileController.saveAsDialog !== null){
72 self.handleCancelButtonAction();
73 }
74 }else if((evt.keyCode == 13) && !(evt.ctrlKey || evt.metaKey)){//ENTER key
75 if((self.application.ninja.newFileController.saveAsDialog !== null)
76 && !self.okButton.hasAttribute("disabled")){
77
78 self.handleOkButtonAction();
79 }
80 }
81 }, true);
82
64 } 83 }
65 }, 84 },
66 85
67 handleNewFileDirectorySet:{ 86 handleNewFileDirectorySet:{
68 value:function(evt){ 87 value:function(evt){
69 if(!!evt._event.newFileDirectory){ 88 if(evt.keyCode === 13){
89 if(!this.okButton.hasAttribute("disabled")) this.handleOkButtonAction(evt);
90 }else if(evt.keyCode === 27){
91 this.handleCancelButtonAction(evt);
92 }
93 else if(!!evt._event.newFileDirectory){
70 this.folderUri = evt._event.newFileDirectory; 94 this.folderUri = evt._event.newFileDirectory;
71 if(this.isValidUri(this.folderUri)){ 95 if(this.isValidUri(this.folderUri)){
72 this.enableOk(); 96 this.enableOk();
@@ -75,6 +99,14 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
75 } 99 }
76 }, 100 },
77 101
102 handlePaste:{
103 value:function(evt){
104 evt.preventDefault();
105 evt.target.value = evt.clipboardData.getData("Text");
106 this.handleNewFileNameOnkeyup(evt);
107 }
108 },
109
78 handleNewFileNameOnkeyup:{ 110 handleNewFileNameOnkeyup:{
79 value:function(evt){ 111 value:function(evt){
80 this.fileName = this.newFileName.value; 112 this.fileName = this.newFileName.value;
@@ -83,6 +115,13 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
83 this.enableOk(); 115 this.enableOk();
84 } 116 }
85 } 117 }
118 if(evt.keyCode === 13){
119 if(!this.okButton.hasAttribute("disabled")){
120 this.handleOkButtonAction(evt);
121 }
122 }else if(evt.keyCode === 27){
123 this.handleCancelButtonAction(evt);
124 }
86 } 125 }
87 }, 126 },
88 127
@@ -99,7 +138,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
99 handleCancelButtonAction :{ 138 handleCancelButtonAction :{
100 value:function(evt){ 139 value:function(evt){
101 //clean up memory 140 //clean up memory
102 //this.cleanup(); 141 this.cleanup();
103 142
104 if(this.popup){ 143 if(this.popup){
105 this.popup.hide(); 144 this.popup.hide();
@@ -111,7 +150,7 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
111 handleOkButtonAction:{ 150 handleOkButtonAction:{
112 value: function(evt){ 151 value: function(evt){
113 var filename = this.fileName, 152 var filename = this.fileName,
114 newFileDirectory = this.newFileDirectory, 153 newFileDirectory = this.folderUri,
115 success = true; 154 success = true;
116 if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri) && !this.checkFileExists(this.fileName, this.folderUri)){ 155 if(this.isValidFileName(this.fileName) && this.isValidUri(this.folderUri) && !this.checkFileExists(this.fileName, this.folderUri)){
117 try{ 156 try{
@@ -128,13 +167,13 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
128 } 167 }
129 }catch(e){ 168 }catch(e){
130 success = false; 169 success = false;
131 console.log("[ERROR] Failed to save: "+ this.fileName + " at "+ this.newFileDirectory); 170 console.log("[ERROR] Failed to save: "+ this.fileName + " at "+ newFileDirectory);
132 console.log(e.stack); 171 console.log(e.stack);
133 } 172 }
134 173
135 if(success){ 174 if(success){
136 //clean up memory 175 //clean up memory
137 //this.cleanup(); 176 this.cleanup();
138 177
139 if(this.popup){ 178 if(this.popup){
140 this.popup.hide(); 179 this.popup.hide();
@@ -227,6 +266,20 @@ var SaveAsDialog = exports.SaveAsDialog = Montage.create(Component, {
227 } 266 }
228 return status; 267 return status;
229 } 268 }
269 },
270
271 cleanup:{
272 value:function(){
273 var self = this;
274
275 //remove event listener
276 this.newFileName.removeEventListener("keyup", function(evt){self.handleNewFileNameOnkeyup(evt);}, false);
277 this.eventManager.removeEventListener("newFileDirectorySet", function(evt){self.handleNewFileDirectorySet(evt);}, false);
278 this.okButton.removeEventListener("click", function(evt){self.handleOkButtonAction(evt);}, false);
279 this.cancelButton.removeEventListener("click", function(evt){self.handleCancelButtonAction(evt);}, false);
280
281 this.application.ninja.newFileController.saveAsDialog = null;
230 } 282 }
283 }
231 284
232}); \ No newline at end of file 285}); \ No newline at end of file