| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 var CommandUtil = {}; | 7 var CommandUtil = {}; |
| 8 | 8 |
| 9 /** | 9 /** |
| 10 * Extracts path on which command event was dispatched. | 10 * Extracts path on which command event was dispatched. |
| 11 * | 11 * |
| 12 * @param {DirectoryTree|DirectoryItem|VolumeList|HTMLLIElement|cr.ui.List} | 12 * @param {DirectoryTree|DirectoryItem|NavigationList|HTMLLIElement|cr.ui.List} |
| 13 * element Directory to extract a path from. | 13 * element Directory to extract a path from. |
| 14 * @return {?string} Path of the found node. | 14 * @return {?string} Path of the found node. |
| 15 */ | 15 */ |
| 16 CommandUtil.getCommandPath = function(element) { | 16 CommandUtil.getCommandPath = function(element) { |
| 17 if (element instanceof VolumeList) { | 17 if (element instanceof NavigationList) { |
| 18 // element is a VolumeList. | 18 // element is a NavigationList. |
| 19 return element.selectedItem; | 19 return element.selectedItem; |
| 20 } else if (element instanceof VolumeItem) { | 20 } else if (element instanceof NavigationListItem) { |
| 21 // element is a subitem of VolumeList. | 21 // element is a subitem of NavigationList. |
| 22 var volumeList = element.parentElement; | 22 var navigationList = element.parentElement; |
| 23 var index = volumeList.getIndexOfListItem(element); | 23 var index = navigationList.getIndexOfListItem(element); |
| 24 return (index != -1) ? volumeList.dataModel.item(index) : null; | 24 return (index != -1) ? navigationList.dataModel.item(index) : null; |
| 25 } else if (element instanceof DirectoryTree) { | 25 } else if (element instanceof DirectoryTree) { |
| 26 // element is a DirectoryTree. | 26 // element is a DirectoryTree. |
| 27 var item = element.selectedItem; | 27 var item = element.selectedItem; |
| 28 return item && item.fullPath; | 28 return item && item.fullPath; |
| 29 } else if (element instanceof DirectoryItem) { | 29 } else if (element instanceof DirectoryItem) { |
| 30 // element is a sub item in DirectoryTree. | 30 // element is a sub item in DirectoryTree. |
| 31 | 31 |
| 32 // DirectoryItem.fullPath is set on initialization, but entry is lazily. | 32 // DirectoryItem.fullPath is set on initialization, but entry is lazily. |
| 33 // We may use fullPath just in case that the entry has not been set yet. | 33 // We may use fullPath just in case that the entry has not been set yet. |
| 34 return element.entry && element.entry.fullPath || | 34 return element.entry && element.entry.fullPath || |
| 35 element.fullPath; | 35 element.fullPath; |
| 36 } else if (cr.ui.List) { | 36 } else if (cr.ui.List) { |
| 37 // element is a normal List (eg. the file list on the right panel). | 37 // element is a normal List (eg. the file list on the right panel). |
| 38 var entry = element.selectedItem; | 38 var entry = element.selectedItem; |
| 39 return entry && entry.fullPath; | 39 return entry && entry.fullPath; |
| 40 } else { | 40 } else { |
| 41 console.warn('Unsupported element'); | 41 console.warn('Unsupported element'); |
| 42 return null; | 42 return null; |
| 43 } | 43 } |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 /** | 46 /** |
| 47 * @param {VolumeList} volumeList Volume list to extract root node. | 47 * @param {NavigationList} navigationList navigation list to extract root node. |
| 48 * @return {?RootType} Type of the found root. | 48 * @return {?RootType} Type of the found root. |
| 49 */ | 49 */ |
| 50 CommandUtil.getCommandRootType = function(volumeList) { | 50 CommandUtil.getCommandRootType = function(navigationList) { |
| 51 var root = CommandUtil.getCommandPath(volumeList); | 51 var root = CommandUtil.getCommandPath(navigationList); |
| 52 return root && PathUtil.isRootPath(root) && PathUtil.getRootType(root); | 52 return root && PathUtil.isRootPath(root) && PathUtil.getRootType(root); |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 /** | 55 /** |
| 56 * Checks if command can be executed on drive. | 56 * Checks if command can be executed on drive. |
| 57 * @param {Event} event Command event to mark. | 57 * @param {Event} event Command event to mark. |
| 58 * @param {FileManager} fileManager FileManager to use. | 58 * @param {FileManager} fileManager FileManager to use. |
| 59 */ | 59 */ |
| 60 CommandUtil.canExecuteEnabledOnDriveOnly = function(event, fileManager) { | 60 CommandUtil.canExecuteEnabledOnDriveOnly = function(event, fileManager) { |
| 61 event.canExecute = fileManager.isOnDrive(); | 61 event.canExecute = fileManager.isOnDrive(); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 event.canExecute = document.queryCommandEnabled(event.command.id); | 164 event.canExecute = document.queryCommandEnabled(event.command.id); |
| 165 } | 165 } |
| 166 }; | 166 }; |
| 167 | 167 |
| 168 /** | 168 /** |
| 169 * Unmounts external drive. | 169 * Unmounts external drive. |
| 170 */ | 170 */ |
| 171 Commands.unmountCommand = { | 171 Commands.unmountCommand = { |
| 172 /** | 172 /** |
| 173 * @param {Event} event Command event. | 173 * @param {Event} event Command event. |
| 174 * @param {VolumeList} volumeList Target volume list. | 174 * @param {NavigationList} navigationList Target navigation list. |
| 175 */ | 175 */ |
| 176 execute: function(event, volumeList, fileManager) { | 176 execute: function(event, navigationList, fileManager) { |
| 177 var root = CommandUtil.getCommandPath(volumeList); | 177 var root = CommandUtil.getCommandPath(navigationList); |
| 178 if (root) | 178 if (root) |
| 179 fileManager.unmountVolume(PathUtil.getRootPath(root)); | 179 fileManager.unmountVolume(PathUtil.getRootPath(root)); |
| 180 }, | 180 }, |
| 181 /** | 181 /** |
| 182 * @param {Event} event Command event. | 182 * @param {Event} event Command event. |
| 183 * @param {VolumeList} volumeList Target volume list. | 183 * @param {NavigationList} navigationList Target navigation list. |
| 184 */ | 184 */ |
| 185 canExecute: function(event, volumeList) { | 185 canExecute: function(event, navigationList) { |
| 186 var rootType = CommandUtil.getCommandRootType(volumeList); | 186 var rootType = CommandUtil.getCommandRootType(navigationList); |
| 187 | 187 |
| 188 event.canExecute = (rootType == RootType.ARCHIVE || | 188 event.canExecute = (rootType == RootType.ARCHIVE || |
| 189 rootType == RootType.REMOVABLE); | 189 rootType == RootType.REMOVABLE); |
| 190 event.command.setHidden(!event.canExecute); | 190 event.command.setHidden(!event.canExecute); |
| 191 event.command.label = rootType == RootType.ARCHIVE ? | 191 event.command.label = rootType == RootType.ARCHIVE ? |
| 192 str('CLOSE_ARCHIVE_BUTTON_LABEL') : | 192 str('CLOSE_ARCHIVE_BUTTON_LABEL') : |
| 193 str('UNMOUNT_DEVICE_BUTTON_LABEL'); | 193 str('UNMOUNT_DEVICE_BUTTON_LABEL'); |
| 194 } | 194 } |
| 195 }; | 195 }; |
| 196 | 196 |
| 197 /** | 197 /** |
| 198 * Formats external drive. | 198 * Formats external drive. |
| 199 */ | 199 */ |
| 200 Commands.formatCommand = { | 200 Commands.formatCommand = { |
| 201 /** | 201 /** |
| 202 * @param {Event} event Command event. | 202 * @param {Event} event Command event. |
| 203 * @param {VolumeList} volumeList Target volume list. | 203 * @param {NavigationList} navigationList Target navigation list. |
| 204 * @param {FileManager} fileManager The file manager instance. | 204 * @param {FileManager} fileManager The file manager instance. |
| 205 */ | 205 */ |
| 206 execute: function(event, volumeList, fileManager) { | 206 execute: function(event, navigationList, fileManager) { |
| 207 var root = CommandUtil.getCommandPath(volumeList); | 207 var root = CommandUtil.getCommandPath(navigationList); |
| 208 | 208 |
| 209 if (root) { | 209 if (root) { |
| 210 var url = util.makeFilesystemUrl(PathUtil.getRootPath(root)); | 210 var url = util.makeFilesystemUrl(PathUtil.getRootPath(root)); |
| 211 fileManager.confirm.show( | 211 fileManager.confirm.show( |
| 212 loadTimeData.getString('FORMATTING_WARNING'), | 212 loadTimeData.getString('FORMATTING_WARNING'), |
| 213 chrome.fileBrowserPrivate.formatDevice.bind(null, url)); | 213 chrome.fileBrowserPrivate.formatDevice.bind(null, url)); |
| 214 } | 214 } |
| 215 }, | 215 }, |
| 216 /** | 216 /** |
| 217 * @param {Event} event Command event. | 217 * @param {Event} event Command event. |
| 218 * @param {VolumeList} volumeList Target volume list. | 218 * @param {NavigationList} navigationList Target navigation list. |
| 219 * @param {FileManager} fileManager The file manager instance. | 219 * @param {FileManager} fileManager The file manager instance. |
| 220 * @param {DirectoryModel} directoryModel The directory model instance. | 220 * @param {DirectoryModel} directoryModel The directory model instance. |
| 221 */ | 221 */ |
| 222 canExecute: function(event, volumeList, fileManager, directoryModel) { | 222 canExecute: function(event, navigationList, fileManager, directoryModel) { |
| 223 var root = CommandUtil.getCommandPath(volumeList); | 223 var root = CommandUtil.getCommandPath(navigationList); |
| 224 var removable = root && | 224 var removable = root && |
| 225 PathUtil.getRootType(root) == RootType.REMOVABLE; | 225 PathUtil.getRootType(root) == RootType.REMOVABLE; |
| 226 var isReadOnly = root && directoryModel.isPathReadOnly(root); | 226 var isReadOnly = root && directoryModel.isPathReadOnly(root); |
| 227 event.canExecute = removable && !isReadOnly; | 227 event.canExecute = removable && !isReadOnly; |
| 228 event.command.setHidden(!removable); | 228 event.command.setHidden(!removable); |
| 229 } | 229 } |
| 230 }; | 230 }; |
| 231 | 231 |
| 232 /** | 232 /** |
| 233 * Imports photos from external drive | 233 * Imports photos from external drive |
| 234 */ | 234 */ |
| 235 Commands.importCommand = { | 235 Commands.importCommand = { |
| 236 /** | 236 /** |
| 237 * @param {Event} event Command event. | 237 * @param {Event} event Command event. |
| 238 * @param {VolumeList} volumeList Target volume list. | 238 * @param {NavigationList} navigationList Target navigation list. |
| 239 */ | 239 */ |
| 240 execute: function(event, volumeList) { | 240 execute: function(event, navigationList) { |
| 241 var root = CommandUtil.getCommandPath(volumeList); | 241 var root = CommandUtil.getCommandPath(navigationList); |
| 242 if (!root) | 242 if (!root) |
| 243 return; | 243 return; |
| 244 | 244 |
| 245 // TODO(mtomasz): Implement launching Photo Importer. | 245 // TODO(mtomasz): Implement launching Photo Importer. |
| 246 }, | 246 }, |
| 247 /** | 247 /** |
| 248 * @param {Event} event Command event. | 248 * @param {Event} event Command event. |
| 249 * @param {VolumeList} volumeList Target volume list. | 249 * @param {NavigationList} navigationList Target navigation list. |
| 250 */ | 250 */ |
| 251 canExecute: function(event, volumeList) { | 251 canExecute: function(event, navigationList) { |
| 252 var rootType = CommandUtil.getCommandRootType(volumeList); | 252 var rootType = CommandUtil.getCommandRootType(navigationList); |
| 253 event.canExecute = (rootType != RootType.DRIVE); | 253 event.canExecute = (rootType != RootType.DRIVE); |
| 254 } | 254 } |
| 255 }; | 255 }; |
| 256 | 256 |
| 257 /** | 257 /** |
| 258 * Initiates new folder creation. | 258 * Initiates new folder creation. |
| 259 */ | 259 */ |
| 260 Commands.newFolderCommand = { | 260 Commands.newFolderCommand = { |
| 261 execute: function(event, fileManager) { | 261 execute: function(event, fileManager) { |
| 262 fileManager.createNewFolder(); | 262 fileManager.createNewFolder(); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 }, | 413 }, |
| 414 canExecute: function(event, fileManager) { | 414 canExecute: function(event, fileManager) { |
| 415 event.canExecute = !fileManager.isRenamingInProgress(); | 415 event.canExecute = !fileManager.isRenamingInProgress(); |
| 416 } | 416 } |
| 417 }; | 417 }; |
| 418 | 418 |
| 419 /** | 419 /** |
| 420 * Activates the n-th volume. | 420 * Activates the n-th volume. |
| 421 */ | 421 */ |
| 422 Commands.volumeSwitchCommand = { | 422 Commands.volumeSwitchCommand = { |
| 423 execute: function(event, volumeList, index) { | 423 execute: function(event, navigationList, index) { |
| 424 volumeList.selectByIndex(index - 1); | 424 navigationList.selectByIndex(index - 1); |
| 425 }, | 425 }, |
| 426 canExecute: function(event, volumeList, index) { | 426 canExecute: function(event, navigationList, index) { |
| 427 event.canExecute = index > 0 && index <= volumeList.dataModel.length; | 427 event.canExecute = index > 0 && index <= navigationList.dataModel.length; |
| 428 } | 428 } |
| 429 }; | 429 }; |
| 430 | 430 |
| 431 /** | 431 /** |
| 432 * Flips 'available offline' flag on the file. | 432 * Flips 'available offline' flag on the file. |
| 433 */ | 433 */ |
| 434 Commands.togglePinnedCommand = { | 434 Commands.togglePinnedCommand = { |
| 435 execute: function(event, fileManager) { | 435 execute: function(event, fileManager) { |
| 436 var pin = !event.command.checked; | 436 var pin = !event.command.checked; |
| 437 event.command.checked = pin; | 437 event.command.checked = pin; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 572 }, | 572 }, |
| 573 | 573 |
| 574 /** | 574 /** |
| 575 * @param {Event} event Command event. | 575 * @param {Event} event Command event. |
| 576 * @param {FileManager} fileManager The file manager instance. | 576 * @param {FileManager} fileManager The file manager instance. |
| 577 */ | 577 */ |
| 578 canExecute: function(event, fileManager) { | 578 canExecute: function(event, fileManager) { |
| 579 var target = event.target; | 579 var target = event.target; |
| 580 // TODO(yoshiki): remove this after launching folder shortcuts feature. | 580 // TODO(yoshiki): remove this after launching folder shortcuts feature. |
| 581 if (!fileManager.isFolderShortcutsEnabled() || | 581 if (!fileManager.isFolderShortcutsEnabled() || |
| 582 !target instanceof VolumeItem && !target instanceof DirectoryItem) { | 582 (!target instanceof NavigationListItem && |
| 583 !target instanceof DirectoryItem)) { |
| 583 event.command.setHidden(true); | 584 event.command.setHidden(true); |
| 584 return; | 585 return; |
| 585 } | 586 } |
| 586 | 587 |
| 587 var path = CommandUtil.getCommandPath(event.target); | 588 var path = CommandUtil.getCommandPath(event.target); |
| 588 var folderShortcutExists = path && fileManager.folderShortcutExists(path); | 589 var folderShortcutExists = path && fileManager.folderShortcutExists(path); |
| 589 | 590 |
| 590 var onlyOneFolderSelected = true; | 591 var onlyOneFolderSelected = true; |
| 591 // Only on list, user can select multiple files. The command is enabled only | 592 // Only on list, user can select multiple files. The command is enabled only |
| 592 // when a single file is selected. | 593 // when a single file is selected. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 617 }, | 618 }, |
| 618 | 619 |
| 619 /** | 620 /** |
| 620 * @param {Event} event Command event. | 621 * @param {Event} event Command event. |
| 621 * @param {FileManager} fileManager The file manager instance. | 622 * @param {FileManager} fileManager The file manager instance. |
| 622 */ | 623 */ |
| 623 canExecute: function(event, fileManager) { | 624 canExecute: function(event, fileManager) { |
| 624 var target = event.target; | 625 var target = event.target; |
| 625 // TODO(yoshiki): remove this after launching folder shortcut feature. | 626 // TODO(yoshiki): remove this after launching folder shortcut feature. |
| 626 if (!fileManager.isFolderShortcutsEnabled() || | 627 if (!fileManager.isFolderShortcutsEnabled() || |
| 627 !target instanceof VolumeItem && !target instanceof DirectoryItem) { | 628 (!target instanceof NavigationListItem && |
| 629 !target instanceof DirectoryItem)) { |
| 628 event.command.setHidden(true); | 630 event.command.setHidden(true); |
| 629 return; | 631 return; |
| 630 } | 632 } |
| 631 | 633 |
| 632 var path = CommandUtil.getCommandPath(target); | 634 var path = CommandUtil.getCommandPath(target); |
| 633 var eligible = path && PathUtil.isEligibleForFolderShortcut(path); | 635 var eligible = path && PathUtil.isEligibleForFolderShortcut(path); |
| 634 var isShortcut = path && fileManager.folderShortcutExists(path); | 636 var isShortcut = path && fileManager.folderShortcutExists(path); |
| 635 event.canExecute = isShortcut && eligible; | 637 event.canExecute = isShortcut && eligible; |
| 636 event.command.setHidden(!isShortcut); | 638 event.command.setHidden(!isShortcut); |
| 637 } | 639 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 659 | 661 |
| 660 /** | 662 /** |
| 661 * Reset the zoom factor. | 663 * Reset the zoom factor. |
| 662 */ | 664 */ |
| 663 Commands.zoomResetCommand = { | 665 Commands.zoomResetCommand = { |
| 664 execute: function(event) { | 666 execute: function(event) { |
| 665 chrome.fileBrowserPrivate.zoom('reset'); | 667 chrome.fileBrowserPrivate.zoom('reset'); |
| 666 }, | 668 }, |
| 667 canExecute: CommandUtil.canExecuteAlways | 669 canExecute: CommandUtil.canExecuteAlways |
| 668 }; | 670 }; |
| OLD | NEW |