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_EXIF_READER = navigator.userAgent.match(/chrome\/12\.0/i); | 7 const ENABLE_EXIF_READER = navigator.userAgent.match(/chrome\/12\.0/i); |
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_EXIF_READER; | 10 const ENABLE_THUMBNAIL_VIEW = ENABLE_EXIF_READER; |
(...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.showCheckboxes_ = | 60 this.showCheckboxes_ = |
58 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || | 61 (this.dialogType_ == FileManager.DialogType.FULL_PAGE || |
59 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); | 62 this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); |
60 | 63 |
61 // DirectoryEntry representing the current directory of the dialog. | 64 // DirectoryEntry representing the current directory of the dialog. |
62 this.currentDirEntry_ = null; | 65 this.currentDirEntry_ = null; |
63 | 66 |
64 window.addEventListener('popstate', this.onPopState_.bind(this)); | 67 window.addEventListener('popstate', this.onPopState_.bind(this)); |
65 this.addEventListener('directory-changed', | 68 this.addEventListener('directory-changed', |
66 this.onDirectoryChanged_.bind(this)); | 69 this.onDirectoryChanged_.bind(this)); |
(...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 this.initTable_(); | 542 this.initTable_(); |
540 this.initGrid_(); | 543 this.initGrid_(); |
541 | 544 |
542 this.setListType(FileManager.ListType.DETAIL); | 545 this.setListType(FileManager.ListType.DETAIL); |
543 | 546 |
544 this.onResize_(); | 547 this.onResize_(); |
545 this.dialogDom_.style.opacity = '1'; | 548 this.dialogDom_.style.opacity = '1'; |
546 }; | 549 }; |
547 | 550 |
548 /** | 551 /** |
| 552 * "Save a file" dialog is supposed to have a combo box with available |
| 553 * file types. Selecting an item filters files by extension and specifies how |
| 554 * file should be saved. |
| 555 * @return {intener} Index of selected type from this.fileTypes_ + 1. 0 |
| 556 * means value is not specified. |
| 557 */ |
| 558 FileManager.prototype.getSelectedFilterIndex_= function(fileName) { |
| 559 // TODO(serya): Implement the combo box |
| 560 // For now try to guess choice by file extension. |
| 561 if (!this.fileTypes_ || this.fileTypes_.length == 0) return 0; |
| 562 |
| 563 var extension = /\.[^\.]+$/.exec(fileName); |
| 564 extension = extension ? extension[0].substring(1).toLowerCase() : ""; |
| 565 var result = 0; // Use first type by default. |
| 566 for (var i = 0; i < this.fileTypes_.length; i++) { |
| 567 if (this.fileTypes_[i].extensions.indexOf(extension)) { |
| 568 result = i; |
| 569 } |
| 570 } |
| 571 return result + 1; // 1-based index. |
| 572 }; |
| 573 |
| 574 /** |
549 * Force the canExecute events to be dispatched. | 575 * Force the canExecute events to be dispatched. |
550 */ | 576 */ |
551 FileManager.prototype.updateCommands_ = function() { | 577 FileManager.prototype.updateCommands_ = function() { |
552 this.commands_['rename'].canExecuteChange(); | 578 this.commands_['rename'].canExecuteChange(); |
553 this.commands_['delete'].canExecuteChange(); | 579 this.commands_['delete'].canExecuteChange(); |
554 }; | 580 }; |
555 | 581 |
556 /** | 582 /** |
557 * Invoked to decide whether the "rename" command can be executed. | 583 * Invoked to decide whether the "rename" command can be executed. |
558 */ | 584 */ |
(...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2054 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') | 2080 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') |
2055 currentDirUrl += '/'; | 2081 currentDirUrl += '/'; |
2056 | 2082 |
2057 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 2083 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
2058 // Save-as doesn't require a valid selection from the list, since | 2084 // Save-as doesn't require a valid selection from the list, since |
2059 // we're going to take the filename from the text input. | 2085 // we're going to take the filename from the text input. |
2060 var filename = this.filenameInput_.value; | 2086 var filename = this.filenameInput_.value; |
2061 if (!filename) | 2087 if (!filename) |
2062 throw new Error('Missing filename!'); | 2088 throw new Error('Missing filename!'); |
2063 | 2089 |
2064 chrome.fileBrowserPrivate.selectFile(currentDirUrl + encodeURI(filename), | 2090 chrome.fileBrowserPrivate.selectFile( |
2065 0); | 2091 currentDirUrl + encodeURIComponent(filename), |
| 2092 this.getSelectedFilterIndex_(filename)); |
2066 window.close(); | 2093 window.close(); |
2067 return; | 2094 return; |
2068 } | 2095 } |
2069 | 2096 |
2070 var ary = []; | 2097 var ary = []; |
2071 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; | 2098 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; |
2072 | 2099 |
2073 // All other dialog types require at least one selected list item. | 2100 // All other dialog types require at least one selected list item. |
2074 // The logic to control whether or not the ok button is enabled should | 2101 // The logic to control whether or not the ok button is enabled should |
2075 // prevent us from ever getting here, but we sanity check to be sure. | 2102 // prevent us from ever getting here, but we sanity check to be sure. |
2076 if (!selectedIndexes.length) | 2103 if (!selectedIndexes.length) |
2077 throw new Error('Nothing selected!'); | 2104 throw new Error('Nothing selected!'); |
2078 | 2105 |
2079 for (var i = 0; i < selectedIndexes.length; i++) { | 2106 for (var i = 0; i < selectedIndexes.length; i++) { |
2080 var entry = this.dataModel_.item(selectedIndexes[i]); | 2107 var entry = this.dataModel_.item(selectedIndexes[i]); |
2081 if (!entry) { | 2108 if (!entry) { |
2082 console.log('Error locating selected file at index: ' + i); | 2109 console.log('Error locating selected file at index: ' + i); |
2083 continue; | 2110 continue; |
2084 } | 2111 } |
2085 | 2112 |
2086 ary.push(currentDirUrl + encodeURI(entry.name)); | 2113 ary.push(currentDirUrl + encodeURIComponent(entry.name)); |
2087 } | 2114 } |
2088 | 2115 |
2089 // Multi-file selection has no other restrictions. | 2116 // Multi-file selection has no other restrictions. |
2090 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { | 2117 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { |
2091 chrome.fileBrowserPrivate.selectFiles(ary); | 2118 chrome.fileBrowserPrivate.selectFiles(ary); |
2092 window.close(); | 2119 window.close(); |
2093 return; | 2120 return; |
2094 } | 2121 } |
2095 | 2122 |
2096 // In full screen mode, open all files for vieweing. | 2123 // In full screen mode, open all files for vieweing. |
2097 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 2124 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
2098 chrome.fileBrowserPrivate.viewFiles(ary, "default"); | 2125 chrome.fileBrowserPrivate.viewFiles(ary, "default"); |
2099 // Window stays open. | 2126 // Window stays open. |
2100 return; | 2127 return; |
2101 } | 2128 } |
2102 | 2129 |
2103 // Everything else must have exactly one. | 2130 // Everything else must have exactly one. |
2104 if (ary.length > 1) | 2131 if (ary.length > 1) |
2105 throw new Error('Too many files selected!'); | 2132 throw new Error('Too many files selected!'); |
2106 | 2133 |
2107 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { | 2134 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { |
2108 if (!this.selection.leadEntry.isDirectory) | 2135 if (!this.selection.leadEntry.isDirectory) |
2109 throw new Error('Selected entry is not a folder!'); | 2136 throw new Error('Selected entry is not a folder!'); |
2110 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 2137 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
2111 if (!this.selection.leadEntry.isFile) | 2138 if (!this.selection.leadEntry.isFile) |
2112 throw new Error('Selected entry is not a file!'); | 2139 throw new Error('Selected entry is not a file!'); |
2113 } | 2140 } |
2114 | 2141 |
2115 chrome.fileBrowserPrivate.selectFile(ary[0], 0); | 2142 chrome.fileBrowserPrivate.selectFile( |
| 2143 ary[0], this.getSelectedFilterIndex_(ary[0])); |
2116 window.close(); | 2144 window.close(); |
2117 }; | 2145 }; |
2118 | 2146 |
2119 })(); | 2147 })(); |
OLD | NEW |