| 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 var CommandUtil = {}; | 5 var CommandUtil = {}; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * Extracts root on which command event was dispatched. | 8 * Extracts root on which command event was dispatched. |
| 9 * | 9 * |
| 10 * @param {Event} event Command event for which to retrieve root to operate on. | 10 * @param {Event} event Command event for which to retrieve root to operate on. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 /** | 33 /** |
| 34 * Checks if command can be executed on gdata. | 34 * Checks if command can be executed on gdata. |
| 35 * @param {Event} event Command event to mark. | 35 * @param {Event} event Command event to mark. |
| 36 * @param {FileManager} fileManager FileManager to use. | 36 * @param {FileManager} fileManager FileManager to use. |
| 37 */ | 37 */ |
| 38 CommandUtil.canExecuteOnGDataOnly = function(event, fileManager) { | 38 CommandUtil.canExecuteOnGDataOnly = function(event, fileManager) { |
| 39 event.canExecute = fileManager.isOnGData(); | 39 event.canExecute = fileManager.isOnGData(); |
| 40 }; | 40 }; |
| 41 | 41 |
| 42 /** | 42 /** |
| 43 * Returns a single selected/passed entry or null. |
| 44 * @param {Event} event Command event. |
| 45 * @param {FileManager} fileManager FileManager to use. |
| 46 * @return {FileEntry} The entry or null. |
| 47 */ |
| 48 CommandUtil.getSingleEntry = function(event, fileManager) { |
| 49 if (event.target.entry) { |
| 50 return event.target.entry; |
| 51 } |
| 52 var selection = fileManager.getSelection(); |
| 53 if (selection.totalCount == 1) { |
| 54 return selection.entries[0]; |
| 55 } |
| 56 return null; |
| 57 }; |
| 58 |
| 59 /** |
| 43 * Registers handler on specific command on specific node. | 60 * Registers handler on specific command on specific node. |
| 44 * @param {Node} node Node to register command handler on. | 61 * @param {Node} node Node to register command handler on. |
| 45 * @param {string} commandId Command id to respond to. | 62 * @param {string} commandId Command id to respond to. |
| 46 * @param {{execute:function, canExecute:function}} handler Handler to use. | 63 * @param {{execute:function, canExecute:function}} handler Handler to use. |
| 47 * @param {Object...} var_args Additional arguments to pass to handler. | 64 * @param {Object...} var_args Additional arguments to pass to handler. |
| 48 */ | 65 */ |
| 49 CommandUtil.registerCommand = function(node, commandId, handler, var_args) { | 66 CommandUtil.registerCommand = function(node, commandId, handler, var_args) { |
| 50 var args = Array.prototype.slice.call(arguments, 3); | 67 var args = Array.prototype.slice.call(arguments, 3); |
| 51 | 68 |
| 52 node.addEventListener('command', function(event) { | 69 node.addEventListener('command', function(event) { |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 Commands.searchCommand = { | 318 Commands.searchCommand = { |
| 302 execute: function(event, fileManager, elmnt) { | 319 execute: function(event, fileManager, elmnt) { |
| 303 elmnt.focus(); | 320 elmnt.focus(); |
| 304 }, | 321 }, |
| 305 canExecute: function(event, fileManager) { | 322 canExecute: function(event, fileManager) { |
| 306 event.canExecute = !fileManager.isRenamingInProgress(); | 323 event.canExecute = !fileManager.isRenamingInProgress(); |
| 307 } | 324 } |
| 308 }; | 325 }; |
| 309 | 326 |
| 310 /** | 327 /** |
| 328 * Flips 'available offline' flag on the file. |
| 329 */ |
| 330 Commands.togglePinnedCommand = { |
| 331 execute: function(event, fileManager) { |
| 332 var pin = !event.command.checked; |
| 333 var entry = CommandUtil.getSingleEntry(event, fileManager); |
| 334 |
| 335 function showError(filesystem) { |
| 336 fileManager.alert.showHtml(str('GDATA_OUT_OF_SPACE_HEADER'), |
| 337 strf('GDATA_OUT_OF_SPACE_MESSAGE', |
| 338 unescape(entry.name), |
| 339 util.bytesToSi(filesystem.size))); |
| 340 } |
| 341 |
| 342 function callback(props) { |
| 343 var fileProps = props[0]; |
| 344 if (fileProps.errorCode && pin) { |
| 345 fileManager.metadataCache_.get(entry, 'filesystem', showError); |
| 346 } |
| 347 // We don't have update events yet, so clear the cached data. |
| 348 fileManager.metadataCache_.clear(entry, 'gdata'); |
| 349 fileManager.metadataCache_.get(entry, 'gdata', function(gdata) { |
| 350 fileManager.updateMetadataInUI_('gdata', [entry.toURL()], [gdata]); |
| 351 }); |
| 352 } |
| 353 |
| 354 chrome.fileBrowserPrivate.pinGDataFile([entry.toURL()], pin, callback); |
| 355 }, |
| 356 canExecute: function(event, fileManager) { |
| 357 var entry = CommandUtil.getSingleEntry(event, fileManager); |
| 358 var gdata = entry && fileManager.metadataCache_.getCached(entry, 'gdata'); |
| 359 |
| 360 if (!fileManager.isOnGData() || entry.isDirectory || !gdata || |
| 361 gdata.hosted) { |
| 362 event.canExecute = false; |
| 363 event.command.setHidden(true); |
| 364 } else { |
| 365 event.canExecute = true; |
| 366 event.command.setHidden(false); |
| 367 event.command.checked = gdata.pinned; |
| 368 } |
| 369 } |
| 370 }; |
| 371 |
| 372 /** |
| 311 * Creates zip file for current selection. | 373 * Creates zip file for current selection. |
| 312 */ | 374 */ |
| 313 Commands.zipSelectionCommand = { | 375 Commands.zipSelectionCommand = { |
| 314 execute: function(event, fileManager) { | 376 execute: function(event, fileManager) { |
| 315 var dirEntry = fileManager.directoryModel_.getCurrentDirEntry(); | 377 var dirEntry = fileManager.directoryModel_.getCurrentDirEntry(); |
| 316 var selectionEntries = fileManager.getSelection().entries; | 378 var selectionEntries = fileManager.getSelection().entries; |
| 317 fileManager.copyManager_.zipSelection(dirEntry, fileManager.isOnGData(), | 379 fileManager.copyManager_.zipSelection(dirEntry, fileManager.isOnGData(), |
| 318 selectionEntries); | 380 selectionEntries); |
| 319 }, | 381 }, |
| 320 canExecute: function(event, fileManager) { | 382 canExecute: function(event, fileManager) { |
| 321 var selection = fileManager.getSelection(); | 383 var selection = fileManager.getSelection(); |
| 322 event.canExecute = !fileManager.isOnGData() && selection && | 384 event.canExecute = !fileManager.isOnGData() && selection && |
| 323 selection.totalCount > 0; | 385 selection.totalCount > 0; |
| 324 } | 386 } |
| 325 }; | 387 }; |
| OLD | NEW |