| Index: chrome/browser/resources/file_manager/js/file_manager_commands.js
|
| ===================================================================
|
| --- chrome/browser/resources/file_manager/js/file_manager_commands.js (revision 169329)
|
| +++ chrome/browser/resources/file_manager/js/file_manager_commands.js (working copy)
|
| @@ -40,6 +40,23 @@
|
| };
|
|
|
| /**
|
| + * Returns a single selected/passed entry or null.
|
| + * @param {Event} event Command event.
|
| + * @param {FileManager} fileManager FileManager to use.
|
| + * @return {FileEntry} The entry or null.
|
| + */
|
| +CommandUtil.getSingleEntry = function(event, fileManager) {
|
| + if (event.target.entry) {
|
| + return event.target.entry;
|
| + }
|
| + var selection = fileManager.getSelection();
|
| + if (selection.totalCount == 1) {
|
| + return selection.entries[0];
|
| + }
|
| + return null;
|
| +};
|
| +
|
| +/**
|
| * Registers handler on specific command on specific node.
|
| * @param {Node} node Node to register command handler on.
|
| * @param {string} commandId Command id to respond to.
|
| @@ -308,6 +325,51 @@
|
| };
|
|
|
| /**
|
| + * Flips 'available offline' flag on the file.
|
| + */
|
| +Commands.togglePinnedCommand = {
|
| + execute: function(event, fileManager) {
|
| + var pin = !event.command.checked;
|
| + var entry = CommandUtil.getSingleEntry(event, fileManager);
|
| +
|
| + function showError(filesystem) {
|
| + fileManager.alert.showHtml(str('GDATA_OUT_OF_SPACE_HEADER'),
|
| + strf('GDATA_OUT_OF_SPACE_MESSAGE',
|
| + unescape(entry.name),
|
| + util.bytesToSi(filesystem.size)));
|
| + }
|
| +
|
| + function callback(props) {
|
| + var fileProps = props[0];
|
| + if (fileProps.errorCode && pin) {
|
| + fileManager.metadataCache_.get(entry, 'filesystem', showError);
|
| + }
|
| + // We don't have update events yet, so clear the cached data.
|
| + fileManager.metadataCache_.clear(entry, 'gdata');
|
| + fileManager.metadataCache_.get(entry, 'gdata', function(gdata) {
|
| + fileManager.updateMetadataInUI_('gdata', [entry.toURL()], [gdata]);
|
| + });
|
| + }
|
| +
|
| + chrome.fileBrowserPrivate.pinGDataFile([entry.toURL()], pin, callback);
|
| + },
|
| + canExecute: function(event, fileManager) {
|
| + var entry = CommandUtil.getSingleEntry(event, fileManager);
|
| + var gdata = entry && fileManager.metadataCache_.getCached(entry, 'gdata');
|
| +
|
| + if (!fileManager.isOnGData() || entry.isDirectory || !gdata ||
|
| + gdata.hosted) {
|
| + event.canExecute = false;
|
| + event.command.setHidden(true);
|
| + } else {
|
| + event.canExecute = true;
|
| + event.command.setHidden(false);
|
| + event.command.checked = gdata.pinned;
|
| + }
|
| + }
|
| +};
|
| +
|
| +/**
|
| * Creates zip file for current selection.
|
| */
|
| Commands.zipSelectionCommand = {
|
|
|