| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 // WK Bug 55728 is fixed on the chrome 12 branch but not on the trunk. | 5 // WK Bug 55728 is fixed on the chrome 12 branch but not on the trunk. |
| 6 // TODO(rginda): Enable this everywhere once we have a trunk-worthy fix. | 6 // TODO(rginda): Enable this everywhere once we have a trunk-worthy fix. |
| 7 const ENABLE_METADATA = true; | 7 const ENABLE_METADATA = true; |
| 8 | 8 |
| 9 // Thumbnail view is painful without the exif reader. | 9 // Thumbnail view is painful without the exif reader. |
| 10 const ENABLE_THUMBNAIL_VIEW = ENABLE_METADATA; | 10 const ENABLE_THUMBNAIL_VIEW = ENABLE_METADATA; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 this.filterFiles_ = true; | 47 this.filterFiles_ = true; |
| 48 | 48 |
| 49 this.commands_ = {}; | 49 this.commands_ = {}; |
| 50 | 50 |
| 51 this.document_ = dialogDom.ownerDocument; | 51 this.document_ = dialogDom.ownerDocument; |
| 52 this.dialogType_ = | 52 this.dialogType_ = |
| 53 this.params_.type || FileManager.DialogType.FULL_PAGE; | 53 this.params_.type || FileManager.DialogType.FULL_PAGE; |
| 54 | 54 |
| 55 this.defaultPath_ = this.params_.defaultPath || '/'; | 55 this.defaultPath_ = this.params_.defaultPath || '/'; |
| 56 | 56 |
| 57 // Optional list of file types. | |
| 58 this.fileTypes_ = this.params_.typeList; | |
| 59 | |
| 60 // This is set to just the directory portion of defaultPath in initDialogType. | 57 // This is set to just the directory portion of defaultPath in initDialogType. |
| 61 this.defaultFolder_ = '/'; | 58 this.defaultFolder_ = '/'; |
| 62 | 59 |
| 63 this.showCheckboxes_ = | 60 this.showCheckboxes_ = |
| 64 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || | 61 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || |
| 65 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); | 62 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); |
| 66 | 63 |
| 67 // DirectoryEntry representing the current directory of the dialog. | 64 // DirectoryEntry representing the current directory of the dialog. |
| 68 this.currentDirEntry_ = null; | 65 this.currentDirEntry_ = null; |
| 69 | 66 |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 this.initTable_(); | 548 this.initTable_(); |
| 552 this.initGrid_(); | 549 this.initGrid_(); |
| 553 | 550 |
| 554 this.setListType(FileManager.ListType.DETAIL); | 551 this.setListType(FileManager.ListType.DETAIL); |
| 555 | 552 |
| 556 this.onResize_(); | 553 this.onResize_(); |
| 557 this.dialogDom_.style.opacity = '1'; | 554 this.dialogDom_.style.opacity = '1'; |
| 558 }; | 555 }; |
| 559 | 556 |
| 560 /** | 557 /** |
| 561 * "Save a file" dialog is supposed to have a combo box with available | |
| 562 * file types. Selecting an item filters files by extension and specifies how | |
| 563 * file should be saved. | |
| 564 * @return {intener} Index of selected type from this.fileTypes_ + 1. 0 | |
| 565 * means value is not specified. | |
| 566 */ | |
| 567 FileManager.prototype.getSelectedFilterIndex_= function(fileName) { | |
| 568 // TODO(serya): Implement the combo box | |
| 569 // For now try to guess choice by file extension. | |
| 570 if (!this.fileTypes_ || this.fileTypes_.length == 0) return 0; | |
| 571 | |
| 572 var extension = /\.[^\.]+$/.exec(fileName); | |
| 573 extension = extension ? extension[0].substring(1).toLowerCase() : ""; | |
| 574 var result = 0; // Use first type by default. | |
| 575 for (var i = 0; i < this.fileTypes_.length; i++) { | |
| 576 if (this.fileTypes_[i].extensions.indexOf(extension)) { | |
| 577 result = i; | |
| 578 } | |
| 579 } | |
| 580 return result + 1; // 1-based index. | |
| 581 }; | |
| 582 | |
| 583 /** | |
| 584 * Force the canExecute events to be dispatched. | 558 * Force the canExecute events to be dispatched. |
| 585 */ | 559 */ |
| 586 FileManager.prototype.updateCommands_ = function() { | 560 FileManager.prototype.updateCommands_ = function() { |
| 587 this.commands_['rename'].canExecuteChange(); | 561 this.commands_['rename'].canExecuteChange(); |
| 588 this.commands_['delete'].canExecuteChange(); | 562 this.commands_['delete'].canExecuteChange(); |
| 589 }; | 563 }; |
| 590 | 564 |
| 591 /** | 565 /** |
| 592 * Invoked to decide whether the "rename" command can be executed. | 566 * Invoked to decide whether the "rename" command can be executed. |
| 593 */ | 567 */ |
| (...skipping 1503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2097 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') | 2071 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') |
| 2098 currentDirUrl += '/'; | 2072 currentDirUrl += '/'; |
| 2099 | 2073 |
| 2100 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 2074 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
| 2101 // Save-as doesn't require a valid selection from the list, since | 2075 // Save-as doesn't require a valid selection from the list, since |
| 2102 // we're going to take the filename from the text input. | 2076 // we're going to take the filename from the text input. |
| 2103 var filename = this.filenameInput_.value; | 2077 var filename = this.filenameInput_.value; |
| 2104 if (!filename) | 2078 if (!filename) |
| 2105 throw new Error('Missing filename!'); | 2079 throw new Error('Missing filename!'); |
| 2106 | 2080 |
| 2107 chrome.fileBrowserPrivate.selectFile( | 2081 chrome.fileBrowserPrivate.selectFile(currentDirUrl + encodeURI(filename), |
| 2108 currentDirUrl + encodeURIComponent(filename), | 2082 0); |
| 2109 this.getSelectedFilterIndex_(filename)); | |
| 2110 window.close(); | 2083 window.close(); |
| 2111 return; | 2084 return; |
| 2112 } | 2085 } |
| 2113 | 2086 |
| 2114 var ary = []; | 2087 var ary = []; |
| 2115 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; | 2088 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; |
| 2116 | 2089 |
| 2117 // All other dialog types require at least one selected list item. | 2090 // All other dialog types require at least one selected list item. |
| 2118 // The logic to control whether or not the ok button is enabled should | 2091 // The logic to control whether or not the ok button is enabled should |
| 2119 // prevent us from ever getting here, but we sanity check to be sure. | 2092 // prevent us from ever getting here, but we sanity check to be sure. |
| 2120 if (!selectedIndexes.length) | 2093 if (!selectedIndexes.length) |
| 2121 throw new Error('Nothing selected!'); | 2094 throw new Error('Nothing selected!'); |
| 2122 | 2095 |
| 2123 for (var i = 0; i < selectedIndexes.length; i++) { | 2096 for (var i = 0; i < selectedIndexes.length; i++) { |
| 2124 var entry = this.dataModel_.item(selectedIndexes[i]); | 2097 var entry = this.dataModel_.item(selectedIndexes[i]); |
| 2125 if (!entry) { | 2098 if (!entry) { |
| 2126 console.log('Error locating selected file at index: ' + i); | 2099 console.log('Error locating selected file at index: ' + i); |
| 2127 continue; | 2100 continue; |
| 2128 } | 2101 } |
| 2129 | 2102 |
| 2130 ary.push(currentDirUrl + encodeURIComponent(entry.name)); | 2103 ary.push(currentDirUrl + encodeURI(entry.name)); |
| 2131 } | 2104 } |
| 2132 | 2105 |
| 2133 // Multi-file selection has no other restrictions. | 2106 // Multi-file selection has no other restrictions. |
| 2134 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { | 2107 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { |
| 2135 chrome.fileBrowserPrivate.selectFiles(ary); | 2108 chrome.fileBrowserPrivate.selectFiles(ary); |
| 2136 window.close(); | 2109 window.close(); |
| 2137 return; | 2110 return; |
| 2138 } | 2111 } |
| 2139 | 2112 |
| 2140 // In full screen mode, open all files for vieweing. | 2113 // In full screen mode, open all files for vieweing. |
| 2141 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 2114 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
| 2142 chrome.fileBrowserPrivate.viewFiles(ary, "default"); | 2115 chrome.fileBrowserPrivate.viewFiles(ary, "default"); |
| 2143 // Window stays open. | 2116 // Window stays open. |
| 2144 return; | 2117 return; |
| 2145 } | 2118 } |
| 2146 | 2119 |
| 2147 // Everything else must have exactly one. | 2120 // Everything else must have exactly one. |
| 2148 if (ary.length > 1) | 2121 if (ary.length > 1) |
| 2149 throw new Error('Too many files selected!'); | 2122 throw new Error('Too many files selected!'); |
| 2150 | 2123 |
| 2151 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { | 2124 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { |
| 2152 if (!this.selection.leadEntry.isDirectory) | 2125 if (!this.selection.leadEntry.isDirectory) |
| 2153 throw new Error('Selected entry is not a folder!'); | 2126 throw new Error('Selected entry is not a folder!'); |
| 2154 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 2127 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
| 2155 if (!this.selection.leadEntry.isFile) | 2128 if (!this.selection.leadEntry.isFile) |
| 2156 throw new Error('Selected entry is not a file!'); | 2129 throw new Error('Selected entry is not a file!'); |
| 2157 } | 2130 } |
| 2158 | 2131 |
| 2159 chrome.fileBrowserPrivate.selectFile( | 2132 chrome.fileBrowserPrivate.selectFile(ary[0], 0); |
| 2160 ary[0], this.getSelectedFilterIndex_(ary[0])); | |
| 2161 window.close(); | 2133 window.close(); |
| 2162 }; | 2134 }; |
| 2163 | 2135 |
| 2164 })(); | 2136 })(); |
| OLD | NEW |