OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** | 5 /** |
6 * Controler for handling behaviors of Files.app opened as a file/folder | 6 * Controler for handling behaviors of Files.app opened as a file/folder |
7 * selection dialog. | 7 * selection dialog. |
8 * | 8 * |
9 * @param {DialogType} dialogType Dialog type. | 9 * @param {DialogType} dialogType Dialog type. |
10 * @param {!DialogFooter} dialogFooter Dialog footer. | 10 * @param {!DialogFooter} dialogFooter Dialog footer. |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 121 |
122 dialogFooter.initFileTypeFilter( | 122 dialogFooter.initFileTypeFilter( |
123 this.fileTypes_, launchParam.includeAllFiles); | 123 this.fileTypes_, launchParam.includeAllFiles); |
124 this.onFileTypeFilterChanged_(); | 124 this.onFileTypeFilterChanged_(); |
125 } | 125 } |
126 | 126 |
127 /** | 127 /** |
128 * @private | 128 * @private |
129 */ | 129 */ |
130 DialogActionController.prototype.processOKActionForSaveDialog_ = function() { | 130 DialogActionController.prototype.processOKActionForSaveDialog_ = function() { |
| 131 var selection = this.fileSelectionHandler_.selection; |
| 132 |
| 133 // If OK action is clicked when a directory is selected, open the directory. |
| 134 if (selection.directoryCount === 1 && selection.fileCount === 0) { |
| 135 this.directoryModel_.changeDirectoryEntry(selection.entries[0]); |
| 136 return; |
| 137 } |
| 138 |
131 // Save-as doesn't require a valid selection from the list, since | 139 // Save-as doesn't require a valid selection from the list, since |
132 // we're going to take the filename from the text input. | 140 // we're going to take the filename from the text input. |
133 var filename = this.dialogFooter_.filenameInput.value; | 141 var filename = this.dialogFooter_.filenameInput.value; |
134 if (!filename) | 142 if (!filename) |
135 throw new Error('Missing filename!'); | 143 throw new Error('Missing filename!'); |
136 | 144 |
137 this.namingController_.validateFileNameForSaving(filename).then( | 145 this.namingController_.validateFileNameForSaving(filename).then( |
138 function(url) { | 146 function(url) { |
139 // TODO(mtomasz): Clean this up by avoiding constructing a URL | 147 // TODO(mtomasz): Clean this up by avoiding constructing a URL |
140 // via string concatenation. | 148 // via string concatenation. |
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 444 |
437 if (DialogType.isFolderDialog(this.dialogType_)) { | 445 if (DialogType.isFolderDialog(this.dialogType_)) { |
438 // In SELECT_FOLDER mode, we allow to select current directory | 446 // In SELECT_FOLDER mode, we allow to select current directory |
439 // when nothing is selected. | 447 // when nothing is selected. |
440 this.dialogFooter_.okButton.disabled = | 448 this.dialogFooter_.okButton.disabled = |
441 selection.directoryCount > 1 || selection.fileCount !== 0; | 449 selection.directoryCount > 1 || selection.fileCount !== 0; |
442 return; | 450 return; |
443 } | 451 } |
444 | 452 |
445 if (this.dialogType_ === DialogType.SELECT_SAVEAS_FILE) { | 453 if (this.dialogType_ === DialogType.SELECT_SAVEAS_FILE) { |
446 this.dialogFooter_.okButton.disabled = | 454 if (selection.directoryCount === 1 && selection.fileCount === 0) { |
447 this.directoryModel_.isReadOnly() || | 455 this.dialogFooter_.okButton.textContent = str('OPEN_LABEL'); |
448 !this.dialogFooter_.filenameInput.value; | 456 this.dialogFooter_.okButton.disabled = false; |
| 457 } else { |
| 458 this.dialogFooter_.okButton.textContent = str('SAVE_LABEL'); |
| 459 this.dialogFooter_.okButton.disabled = |
| 460 this.directoryModel_.isReadOnly() || |
| 461 !this.dialogFooter_.filenameInput.value; |
| 462 } |
449 return; | 463 return; |
450 } | 464 } |
451 | 465 |
452 if (this.dialogType_ === DialogType.SELECT_OPEN_FILE) { | 466 if (this.dialogType_ === DialogType.SELECT_OPEN_FILE) { |
453 this.dialogFooter_.okButton.disabled = | 467 this.dialogFooter_.okButton.disabled = |
454 selection.directoryCount !== 0 || | 468 selection.directoryCount !== 0 || |
455 selection.fileCount !== 1 || | 469 selection.fileCount !== 1 || |
456 !this.fileSelectionHandler_.isAvailable(); | 470 !this.fileSelectionHandler_.isAvailable(); |
457 return; | 471 return; |
458 } | 472 } |
459 | 473 |
460 if (this.dialogType_ === DialogType.SELECT_OPEN_MULTI_FILE) { | 474 if (this.dialogType_ === DialogType.SELECT_OPEN_MULTI_FILE) { |
461 this.dialogFooter_.okButton.disabled = | 475 this.dialogFooter_.okButton.disabled = |
462 selection.directoryCount !== 0 || | 476 selection.directoryCount !== 0 || |
463 selection.fileCount === 0 || | 477 selection.fileCount === 0 || |
464 !this.fileSelectionHandler_.isAvailable(); | 478 !this.fileSelectionHandler_.isAvailable(); |
465 return; | 479 return; |
466 } | 480 } |
467 | 481 |
468 assertNotReached('Unknown dialog type.'); | 482 assertNotReached('Unknown dialog type.'); |
469 }; | 483 }; |
OLD | NEW |