| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
| 6 * @param {DialogType} dialogType | 6 * @param {DialogType} dialogType |
| 7 * @param {!VolumeManagerWrapper} volumeManager | 7 * @param {!VolumeManagerWrapper} volumeManager |
| 8 * @param {!FileManagerUI} ui | 8 * @param {!FileManagerUI} ui |
| 9 * @param {!MetadataModel} metadataModel | 9 * @param {!MetadataModel} metadataModel |
| 10 * @param {!DirectoryModel} directoryModel | 10 * @param {!DirectoryModel} directoryModel |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 this.metadataUpdateController_ = metadataUpdateController; | 60 this.metadataUpdateController_ = metadataUpdateController; |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * @private {boolean} | 63 * @private {boolean} |
| 64 */ | 64 */ |
| 65 this.canExecuteDefaultTask_ = false; | 65 this.canExecuteDefaultTask_ = false; |
| 66 | 66 |
| 67 /** | 67 /** |
| 68 * @private {boolean} | 68 * @private {boolean} |
| 69 */ | 69 */ |
| 70 this.canExecuteOpenWith_ = false; | 70 this.canExecuteMoreActions_ = false; |
| 71 | 71 |
| 72 /** | 72 /** |
| 73 * @private {!cr.ui.Command} | 73 * @private {!cr.ui.Command} |
| 74 * @const | 74 * @const |
| 75 */ | 75 */ |
| 76 this.defaultTaskCommand_ = assertInstanceof( | 76 this.defaultTaskCommand_ = assertInstanceof( |
| 77 document.querySelector('#default-task'), cr.ui.Command); | 77 document.querySelector('#default-task'), cr.ui.Command); |
| 78 | 78 |
| 79 /** | 79 /** |
| 80 * @private {!cr.ui.Command} | 80 * @private {!cr.ui.Command} |
| 81 * @const | 81 * @const |
| 82 */ | 82 */ |
| 83 this.openWithCommand_ = | 83 this.moreActionsCommand_ = |
| 84 assertInstanceof(document.querySelector('#open-with'), cr.ui.Command); | 84 assertInstanceof(document.querySelector('#more-actions'), cr.ui.Command); |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * @private {Promise<!FileTasks>} | 87 * @private {Promise<!FileTasks>} |
| 88 */ | 88 */ |
| 89 this.tasks_ = null; | 89 this.tasks_ = null; |
| 90 | 90 |
| 91 ui.taskMenuButton.addEventListener( | 91 ui.taskMenuButton.addEventListener( |
| 92 'select', this.onTaskItemClicked_.bind(this)); | 92 'select', this.onTaskItemClicked_.bind(this)); |
| 93 this.selectionHandler_.addEventListener( | 93 this.selectionHandler_.addEventListener( |
| 94 FileSelectionHandler.EventType.CHANGE, | 94 FileSelectionHandler.EventType.CHANGE, |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 * @return {boolean} True if default task command is executable. | 325 * @return {boolean} True if default task command is executable. |
| 326 */ | 326 */ |
| 327 TaskController.prototype.canExecuteDefaultTask = function() { | 327 TaskController.prototype.canExecuteDefaultTask = function() { |
| 328 return this.canExecuteDefaultTask_; | 328 return this.canExecuteDefaultTask_; |
| 329 }; | 329 }; |
| 330 | 330 |
| 331 /** | 331 /** |
| 332 * Returns whether open with command can be executed or not. | 332 * Returns whether open with command can be executed or not. |
| 333 * @return {boolean} True if open with command is executable. | 333 * @return {boolean} True if open with command is executable. |
| 334 */ | 334 */ |
| 335 TaskController.prototype.canExecuteOpenWith = function() { | 335 TaskController.prototype.canExecuteMoreActions = function() { |
| 336 return this.canExecuteOpenWith_; | 336 return this.canExecuteMoreActions_; |
| 337 }; | 337 }; |
| 338 | 338 |
| 339 /** | 339 /** |
| 340 * Updates tasks menu item to match passed task items. | 340 * Updates tasks menu item to match passed task items. |
| 341 * | 341 * |
| 342 * @param {!Array<!Object>} items List of items. | 342 * @param {!Array<!Object>} items List of items. |
| 343 * @private | 343 * @private |
| 344 */ | 344 */ |
| 345 TaskController.prototype.updateContextMenuTaskItems_ = function(items) { | 345 TaskController.prototype.updateContextMenuTaskItems_ = function(items) { |
| 346 // When only one task is available, show it as default item. | 346 // Always show a default item in case at least one task is available, even |
| 347 if (items.length === 1) { | 347 // if there is no corresponding default task (i.e. the available task is |
| 348 var taskItem = items[0]; | 348 // a generic handler). |
| 349 if (items.length >= 1) { |
| 350 var defaultTask = FileTasks.getDefaultTask( |
| 351 items, items[0] /* task to use in case of no default */); |
| 349 | 352 |
| 350 if (taskItem.iconType) { | 353 if (defaultTask.iconType) { |
| 351 this.ui_.fileContextMenu.defaultTaskMenuItem.style.backgroundImage = ''; | 354 this.ui_.fileContextMenu.defaultTaskMenuItem.style.backgroundImage = ''; |
| 352 this.ui_.fileContextMenu.defaultTaskMenuItem.setAttribute( | 355 this.ui_.fileContextMenu.defaultTaskMenuItem.setAttribute( |
| 353 'file-type-icon', taskItem.iconType); | 356 'file-type-icon', defaultTask.iconType); |
| 354 } else if (taskItem.iconUrl) { | 357 } else if (defaultTask.iconUrl) { |
| 355 this.ui_.fileContextMenu.defaultTaskMenuItem.style.backgroundImage = | 358 this.ui_.fileContextMenu.defaultTaskMenuItem.style.backgroundImage = |
| 356 'url(' + taskItem.iconUrl + ')'; | 359 'url(' + defaultTask.iconUrl + ')'; |
| 357 } else { | 360 } else { |
| 358 this.ui_.fileContextMenu.defaultTaskMenuItem.style.backgroundImage = ''; | 361 this.ui_.fileContextMenu.defaultTaskMenuItem.style.backgroundImage = ''; |
| 359 } | 362 } |
| 360 | 363 |
| 361 this.ui_.fileContextMenu.defaultTaskMenuItem.label = | 364 this.ui_.fileContextMenu.defaultTaskMenuItem.label = |
| 362 taskItem.taskId === FileTasks.ZIP_UNPACKER_TASK_ID ? | 365 defaultTask.taskId === FileTasks.ZIP_UNPACKER_TASK_ID ? |
| 363 str('TASK_OPEN') : taskItem.title; | 366 str('TASK_OPEN') : defaultTask.title; |
| 364 this.ui_.fileContextMenu.defaultTaskMenuItem.disabled = | 367 this.ui_.fileContextMenu.defaultTaskMenuItem.disabled = |
| 365 !!taskItem.disabled; | 368 !!defaultTask.disabled; |
| 366 this.ui_.fileContextMenu.defaultTaskMenuItem.taskId = taskItem.taskId; | 369 this.ui_.fileContextMenu.defaultTaskMenuItem.taskId = defaultTask.taskId; |
| 367 } | 370 } |
| 368 | 371 |
| 369 this.canExecuteDefaultTask_ = items.length === 1; | 372 this.canExecuteDefaultTask_ = items.length >= 1; |
| 370 this.defaultTaskCommand_.canExecuteChange(this.ui_.listContainer.element); | 373 this.defaultTaskCommand_.canExecuteChange(this.ui_.listContainer.element); |
| 371 | 374 |
| 372 this.canExecuteOpenWith_ = items.length > 1; | 375 this.canExecuteMoreActions_ = items.length > 1; |
| 373 this.openWithCommand_.canExecuteChange(this.ui_.listContainer.element); | 376 this.moreActionsCommand_.canExecuteChange(this.ui_.listContainer.element); |
| 374 | 377 |
| 375 this.ui_.fileContextMenu.tasksSeparator.hidden = items.length === 0; | 378 this.ui_.fileContextMenu.tasksSeparator.hidden = items.length === 0; |
| 376 }; | 379 }; |
| 377 | 380 |
| 378 /** | 381 /** |
| 379 * @param {FileEntry} entry | 382 * @param {FileEntry} entry |
| 380 */ | 383 */ |
| 381 TaskController.prototype.executeEntryTask = function(entry) { | 384 TaskController.prototype.executeEntryTask = function(entry) { |
| 382 this.metadataModel_.get([entry], ['contentMimeType']).then( | 385 this.metadataModel_.get([entry], ['contentMimeType']).then( |
| 383 function(props) { | 386 function(props) { |
| 384 FileTasks.create( | 387 FileTasks.create( |
| 385 this.volumeManager_, this.metadataModel_, this.directoryModel_, | 388 this.volumeManager_, this.metadataModel_, this.directoryModel_, |
| 386 this.ui_, [entry], [props[0].contentMimeType || null]) | 389 this.ui_, [entry], [props[0].contentMimeType || null]) |
| 387 .then(function(tasks) { | 390 .then(function(tasks) { |
| 388 tasks.executeDefault(); | 391 tasks.executeDefault(); |
| 389 }); | 392 }); |
| 390 }.bind(this)); | 393 }.bind(this)); |
| 391 }; | 394 }; |
| OLD | NEW |