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 |
57 // This is set to just the directory portion of defaultPath in initDialogType. | 60 // This is set to just the directory portion of defaultPath in initDialogType. |
58 this.defaultFolder_ = '/'; | 61 this.defaultFolder_ = '/'; |
59 | 62 |
60 this.showCheckboxes_ = | 63 this.showCheckboxes_ = |
61 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || | 64 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || |
62 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); | 65 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); |
63 | 66 |
64 // DirectoryEntry representing the current directory of the dialog. | 67 // DirectoryEntry representing the current directory of the dialog. |
65 this.currentDirEntry_ = null; | 68 this.currentDirEntry_ = null; |
66 | 69 |
(...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
548 this.initTable_(); | 551 this.initTable_(); |
549 this.initGrid_(); | 552 this.initGrid_(); |
550 | 553 |
551 this.setListType(FileManager.ListType.DETAIL); | 554 this.setListType(FileManager.ListType.DETAIL); |
552 | 555 |
553 this.onResize_(); | 556 this.onResize_(); |
554 this.dialogDom_.style.opacity = '1'; | 557 this.dialogDom_.style.opacity = '1'; |
555 }; | 558 }; |
556 | 559 |
557 /** | 560 /** |
| 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 /** |
558 * Force the canExecute events to be dispatched. | 584 * Force the canExecute events to be dispatched. |
559 */ | 585 */ |
560 FileManager.prototype.updateCommands_ = function() { | 586 FileManager.prototype.updateCommands_ = function() { |
561 this.commands_['rename'].canExecuteChange(); | 587 this.commands_['rename'].canExecuteChange(); |
562 this.commands_['delete'].canExecuteChange(); | 588 this.commands_['delete'].canExecuteChange(); |
563 }; | 589 }; |
564 | 590 |
565 /** | 591 /** |
566 * Invoked to decide whether the "rename" command can be executed. | 592 * Invoked to decide whether the "rename" command can be executed. |
567 */ | 593 */ |
(...skipping 1500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2068 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') | 2094 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') |
2069 currentDirUrl += '/'; | 2095 currentDirUrl += '/'; |
2070 | 2096 |
2071 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 2097 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
2072 // Save-as doesn't require a valid selection from the list, since | 2098 // Save-as doesn't require a valid selection from the list, since |
2073 // we're going to take the filename from the text input. | 2099 // we're going to take the filename from the text input. |
2074 var filename = this.filenameInput_.value; | 2100 var filename = this.filenameInput_.value; |
2075 if (!filename) | 2101 if (!filename) |
2076 throw new Error('Missing filename!'); | 2102 throw new Error('Missing filename!'); |
2077 | 2103 |
2078 chrome.fileBrowserPrivate.selectFile(currentDirUrl + encodeURI(filename), | 2104 chrome.fileBrowserPrivate.selectFile( |
2079 0); | 2105 currentDirUrl + encodeURIComponent(filename), |
| 2106 this.getSelectedFilterIndex_(filename)); |
2080 window.close(); | 2107 window.close(); |
2081 return; | 2108 return; |
2082 } | 2109 } |
2083 | 2110 |
2084 var ary = []; | 2111 var ary = []; |
2085 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; | 2112 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; |
2086 | 2113 |
2087 // All other dialog types require at least one selected list item. | 2114 // All other dialog types require at least one selected list item. |
2088 // The logic to control whether or not the ok button is enabled should | 2115 // The logic to control whether or not the ok button is enabled should |
2089 // prevent us from ever getting here, but we sanity check to be sure. | 2116 // prevent us from ever getting here, but we sanity check to be sure. |
2090 if (!selectedIndexes.length) | 2117 if (!selectedIndexes.length) |
2091 throw new Error('Nothing selected!'); | 2118 throw new Error('Nothing selected!'); |
2092 | 2119 |
2093 for (var i = 0; i < selectedIndexes.length; i++) { | 2120 for (var i = 0; i < selectedIndexes.length; i++) { |
2094 var entry = this.dataModel_.item(selectedIndexes[i]); | 2121 var entry = this.dataModel_.item(selectedIndexes[i]); |
2095 if (!entry) { | 2122 if (!entry) { |
2096 console.log('Error locating selected file at index: ' + i); | 2123 console.log('Error locating selected file at index: ' + i); |
2097 continue; | 2124 continue; |
2098 } | 2125 } |
2099 | 2126 |
2100 ary.push(currentDirUrl + encodeURI(entry.name)); | 2127 ary.push(currentDirUrl + encodeURIComponent(entry.name)); |
2101 } | 2128 } |
2102 | 2129 |
2103 // Multi-file selection has no other restrictions. | 2130 // Multi-file selection has no other restrictions. |
2104 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { | 2131 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { |
2105 chrome.fileBrowserPrivate.selectFiles(ary); | 2132 chrome.fileBrowserPrivate.selectFiles(ary); |
2106 window.close(); | 2133 window.close(); |
2107 return; | 2134 return; |
2108 } | 2135 } |
2109 | 2136 |
2110 // In full screen mode, open all files for vieweing. | 2137 // In full screen mode, open all files for vieweing. |
2111 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 2138 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
2112 chrome.fileBrowserPrivate.viewFiles(ary, "default"); | 2139 chrome.fileBrowserPrivate.viewFiles(ary, "default"); |
2113 // Window stays open. | 2140 // Window stays open. |
2114 return; | 2141 return; |
2115 } | 2142 } |
2116 | 2143 |
2117 // Everything else must have exactly one. | 2144 // Everything else must have exactly one. |
2118 if (ary.length > 1) | 2145 if (ary.length > 1) |
2119 throw new Error('Too many files selected!'); | 2146 throw new Error('Too many files selected!'); |
2120 | 2147 |
2121 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { | 2148 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { |
2122 if (!this.selection.leadEntry.isDirectory) | 2149 if (!this.selection.leadEntry.isDirectory) |
2123 throw new Error('Selected entry is not a folder!'); | 2150 throw new Error('Selected entry is not a folder!'); |
2124 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 2151 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
2125 if (!this.selection.leadEntry.isFile) | 2152 if (!this.selection.leadEntry.isFile) |
2126 throw new Error('Selected entry is not a file!'); | 2153 throw new Error('Selected entry is not a file!'); |
2127 } | 2154 } |
2128 | 2155 |
2129 chrome.fileBrowserPrivate.selectFile(ary[0], 0); | 2156 chrome.fileBrowserPrivate.selectFile( |
| 2157 ary[0], this.getSelectedFilterIndex_(ary[0])); |
2130 window.close(); | 2158 window.close(); |
2131 }; | 2159 }; |
2132 | 2160 |
2133 })(); | 2161 })(); |
OLD | NEW |