Chromium Code Reviews| 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 * Encodes filename to compose file URL. | |
| 553 */ | |
| 554 FileManager.prototype.encodeFileName_ = function(fileName) { | |
| 555 fileName = encodeURI(fileName); | |
|
rginda
2011/06/01 16:53:51
If you switch to encodeURIComponent you won't need
SeRya
2011/06/02 08:42:40
Done.
| |
| 556 | |
| 557 // '#' would be treated as ananchor mark of the url. Escape it. | |
| 558 fileName = fileName.replace(/#/g, '%23'); | |
| 559 return fileName; | |
| 560 }; | |
| 561 | |
| 562 /** | |
| 563 * "Save a file" dislog is suttposed to have a combo box with available | |
|
rginda
2011/06/01 16:53:51
dislog is suttposed => dialog is supposed
SeRya
2011/06/02 08:42:40
Done.
| |
| 564 * file types. Selecting an item filter files by extension and specifies how | |
|
rginda
2011/06/01 16:53:51
filters files
SeRya
2011/06/02 08:42:40
Done.
| |
| 565 * file should be saved. | |
| 566 * @return {intener} Index of selected type from this.fileTypes_ + 1. 0 | |
| 567 * means value is not specified. | |
| 568 */ | |
| 569 FileManager.prototype.getSelectedFilterIndex_= function(fileName) { | |
| 570 // TODO(serya): Implement the combo box | |
| 571 // For now try to guess choice by file extension. | |
| 572 if (!this.fileTypes_ || this.fileTypes_.length == 0) return 0; | |
| 573 | |
| 574 var extension = /\.[^\.]+$/.exec(fileName); | |
| 575 extension = extension ? extension[0].substring(1).toLowerCase() : ""; | |
| 576 var result = 0; // Use first type by default. | |
| 577 for (var i = 0; i < this.fileTypes_.length; i++) { | |
| 578 if (this.fileTypes_[i].extensions.indexOf(extension)) { | |
| 579 result = i; | |
| 580 } | |
| 581 } | |
| 582 return result + 1; // 1-based index. | |
| 583 }; | |
| 584 | |
| 585 /** | |
| 549 * Force the canExecute events to be dispatched. | 586 * Force the canExecute events to be dispatched. |
| 550 */ | 587 */ |
| 551 FileManager.prototype.updateCommands_ = function() { | 588 FileManager.prototype.updateCommands_ = function() { |
| 552 this.commands_['rename'].canExecuteChange(); | 589 this.commands_['rename'].canExecuteChange(); |
| 553 this.commands_['delete'].canExecuteChange(); | 590 this.commands_['delete'].canExecuteChange(); |
| 554 }; | 591 }; |
| 555 | 592 |
| 556 /** | 593 /** |
| 557 * Invoked to decide whether the "rename" command can be executed. | 594 * Invoked to decide whether the "rename" command can be executed. |
| 558 */ | 595 */ |
| (...skipping 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2054 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') | 2091 if (currentDirUrl.charAt(currentDirUrl.length - 1) != '/') |
| 2055 currentDirUrl += '/'; | 2092 currentDirUrl += '/'; |
| 2056 | 2093 |
| 2057 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { | 2094 if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { |
| 2058 // Save-as doesn't require a valid selection from the list, since | 2095 // Save-as doesn't require a valid selection from the list, since |
| 2059 // we're going to take the filename from the text input. | 2096 // we're going to take the filename from the text input. |
| 2060 var filename = this.filenameInput_.value; | 2097 var filename = this.filenameInput_.value; |
| 2061 if (!filename) | 2098 if (!filename) |
| 2062 throw new Error('Missing filename!'); | 2099 throw new Error('Missing filename!'); |
| 2063 | 2100 |
| 2064 chrome.fileBrowserPrivate.selectFile(currentDirUrl + encodeURI(filename), | 2101 chrome.fileBrowserPrivate.selectFile( |
| 2065 0); | 2102 currentDirUrl + this.encodeFileName_(filename), |
| 2103 this.getSelectedFilterIndex_(filename)); | |
| 2066 window.close(); | 2104 window.close(); |
| 2067 return; | 2105 return; |
| 2068 } | 2106 } |
| 2069 | 2107 |
| 2070 var ary = []; | 2108 var ary = []; |
| 2071 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; | 2109 var selectedIndexes = this.currentList_.selectionModel.selectedIndexes; |
| 2072 | 2110 |
| 2073 // All other dialog types require at least one selected list item. | 2111 // 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 | 2112 // 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. | 2113 // prevent us from ever getting here, but we sanity check to be sure. |
| 2076 if (!selectedIndexes.length) | 2114 if (!selectedIndexes.length) |
| 2077 throw new Error('Nothing selected!'); | 2115 throw new Error('Nothing selected!'); |
| 2078 | 2116 |
| 2079 for (var i = 0; i < selectedIndexes.length; i++) { | 2117 for (var i = 0; i < selectedIndexes.length; i++) { |
| 2080 var entry = this.dataModel_.item(selectedIndexes[i]); | 2118 var entry = this.dataModel_.item(selectedIndexes[i]); |
| 2081 if (!entry) { | 2119 if (!entry) { |
| 2082 console.log('Error locating selected file at index: ' + i); | 2120 console.log('Error locating selected file at index: ' + i); |
| 2083 continue; | 2121 continue; |
| 2084 } | 2122 } |
| 2085 | 2123 |
| 2086 ary.push(currentDirUrl + encodeURI(entry.name)); | 2124 ary.push(currentDirUrl + this.encodeFileName_(entry.name)); |
| 2087 } | 2125 } |
| 2088 | 2126 |
| 2089 // Multi-file selection has no other restrictions. | 2127 // Multi-file selection has no other restrictions. |
| 2090 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { | 2128 if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { |
| 2091 chrome.fileBrowserPrivate.selectFiles(ary); | 2129 chrome.fileBrowserPrivate.selectFiles(ary); |
| 2092 window.close(); | 2130 window.close(); |
| 2093 return; | 2131 return; |
| 2094 } | 2132 } |
| 2095 | 2133 |
| 2096 // In full screen mode, open all files for vieweing. | 2134 // In full screen mode, open all files for vieweing. |
| 2097 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { | 2135 if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) { |
| 2098 chrome.fileBrowserPrivate.viewFiles(ary, "default"); | 2136 chrome.fileBrowserPrivate.viewFiles(ary, "default"); |
| 2099 // Window stays open. | 2137 // Window stays open. |
| 2100 return; | 2138 return; |
| 2101 } | 2139 } |
| 2102 | 2140 |
| 2103 // Everything else must have exactly one. | 2141 // Everything else must have exactly one. |
| 2104 if (ary.length > 1) | 2142 if (ary.length > 1) |
| 2105 throw new Error('Too many files selected!'); | 2143 throw new Error('Too many files selected!'); |
| 2106 | 2144 |
| 2107 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { | 2145 if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { |
| 2108 if (!this.selection.leadEntry.isDirectory) | 2146 if (!this.selection.leadEntry.isDirectory) |
| 2109 throw new Error('Selected entry is not a folder!'); | 2147 throw new Error('Selected entry is not a folder!'); |
| 2110 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { | 2148 } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { |
| 2111 if (!this.selection.leadEntry.isFile) | 2149 if (!this.selection.leadEntry.isFile) |
| 2112 throw new Error('Selected entry is not a file!'); | 2150 throw new Error('Selected entry is not a file!'); |
| 2113 } | 2151 } |
| 2114 | 2152 |
| 2115 chrome.fileBrowserPrivate.selectFile(ary[0], 0); | 2153 chrome.fileBrowserPrivate.selectFile( |
| 2154 ary[0], this.getSelectedFilterIndex_(ary[0])); | |
| 2116 window.close(); | 2155 window.close(); |
| 2117 }; | 2156 }; |
| 2118 | 2157 |
| 2119 })(); | 2158 })(); |
| OLD | NEW |