Commit c4cf4056 authored by Sasha Morrissey's avatar Sasha Morrissey Committed by Commit Bot

Add 'Manage in Drive' button to Files App context menu

Adds a 'Manage in Drive' button to the context menu for entries in the
Files app for ChromeOS.

Creates a new DriveManageAction which appears enabled only for
non-directory entries (for now) in Drive when offline mode is not
enabled. Uses getEntryProperties() for the entry to get its
'alternateUrl' (provided by the Drive Sync API) and navigates to this
URL in the browser.

'Manage in Drive', ensure the browser window opens and navigates to the
file.

Test: Right-click on a file in Google Drive in the File Manager, select
Bug: 831480
Cq-Include-Trybots: master.tryserver.chromium.linux:closure_compilation
Change-Id: Ieaa359b9e825bef166ea25ec23ae1693681d91f7
Reviewed-on: https://chromium-review.googlesource.com/1011465
Commit-Queue: Sasha Morrissey <sashab@chromium.org>
Reviewed-by: default avatarNaoki Fukino <fukino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#556375}
parent 0d8d7017
...@@ -628,6 +628,9 @@ ...@@ -628,6 +628,9 @@
<message name="IDS_FILE_BROWSER_SHARE_BUTTON_LABEL" desc="Menu item's label, showing dialog to share the selected Google Drive files. This message is also used as a tooltip label and a spoken feedback label of a button which also shows the dialog to share the files. The translation should be consistent with the sharing dialog's title in Google Drive Web UI."> <message name="IDS_FILE_BROWSER_SHARE_BUTTON_LABEL" desc="Menu item's label, showing dialog to share the selected Google Drive files. This message is also used as a tooltip label and a spoken feedback label of a button which also shows the dialog to share the files. The translation should be consistent with the sharing dialog's title in Google Drive Web UI.">
Share with others Share with others
</message> </message>
<message name="IDS_FILE_BROWSER_MANAGE_IN_DRIVE_BUTTON_LABEL" desc="Menu item's label, showing dialog to open the selected Google Drive files in the Drive webpage for managing sharing permissions, etc.">
Manage in Drive
</message>
<message name="IDS_FILE_BROWSER_TOGGLE_HIDDEN_FILES_COMMAND_LABEL" desc="Label for menu or button with checkmark that toggles visibility of hidden files."> <message name="IDS_FILE_BROWSER_TOGGLE_HIDDEN_FILES_COMMAND_LABEL" desc="Label for menu or button with checkmark that toggles visibility of hidden files.">
Show hidden files Show hidden files
</message> </message>
......
...@@ -156,6 +156,8 @@ void FillEntryPropertiesValueForDrive(const drive::ResourceEntry& entry_proto, ...@@ -156,6 +156,8 @@ void FillEntryPropertiesValueForDrive(const drive::ResourceEntry& entry_proto,
properties->available_when_metered.reset( properties->available_when_metered.reset(
new bool(file_specific_info.cache_state().is_present() || new bool(file_specific_info.cache_state().is_present() ||
file_specific_info.is_hosted_document())); file_specific_info.is_hosted_document()));
properties->alternate_url.reset(
new std::string(file_specific_info.alternate_url()));
} }
// Creates entry definition list for (metadata) search result info list. // Creates entry definition list for (metadata) search result info list.
......
...@@ -699,6 +699,8 @@ ExtensionFunction::ResponseAction FileManagerPrivateGetStringsFunction::Run() { ...@@ -699,6 +699,8 @@ ExtensionFunction::ResponseAction FileManagerPrivateGetStringsFunction::Run() {
SET_STRING("TOGGLE_HIDDEN_FILES_COMMAND_LABEL", SET_STRING("TOGGLE_HIDDEN_FILES_COMMAND_LABEL",
IDS_FILE_BROWSER_TOGGLE_HIDDEN_FILES_COMMAND_LABEL); IDS_FILE_BROWSER_TOGGLE_HIDDEN_FILES_COMMAND_LABEL);
SET_STRING("SHARE_BUTTON_LABEL", IDS_FILE_BROWSER_SHARE_BUTTON_LABEL); SET_STRING("SHARE_BUTTON_LABEL", IDS_FILE_BROWSER_SHARE_BUTTON_LABEL);
SET_STRING("MANAGE_IN_DRIVE_BUTTON_LABEL",
IDS_FILE_BROWSER_MANAGE_IN_DRIVE_BUTTON_LABEL);
SET_STRING("CHANGE_TO_LISTVIEW_BUTTON_LABEL", SET_STRING("CHANGE_TO_LISTVIEW_BUTTON_LABEL",
IDS_FILE_BROWSER_CHANGE_TO_LISTVIEW_BUTTON_LABEL); IDS_FILE_BROWSER_CHANGE_TO_LISTVIEW_BUTTON_LABEL);
SET_STRING("CHANGE_TO_THUMBNAILVIEW_BUTTON_LABEL", SET_STRING("CHANGE_TO_THUMBNAILVIEW_BUTTON_LABEL",
......
...@@ -175,7 +175,8 @@ enum EntryPropertyName { ...@@ -175,7 +175,8 @@ enum EntryPropertyName {
sharedWithMe, sharedWithMe,
shared, shared,
starred, starred,
externalFileUrl externalFileUrl,
alternateUrl
}; };
// Entry property visibility for setEntryTag(); // Entry property visibility for setEntryTag();
...@@ -301,8 +302,11 @@ dictionary EntryProperties { ...@@ -301,8 +302,11 @@ dictionary EntryProperties {
// True if the entry is starred by the user. // True if the entry is starred by the user.
boolean? starred; boolean? starred;
// External file URL to open the file in browser. // externalfile:// URL to open the file in browser.
DOMString? externalFileUrl; DOMString? externalFileUrl;
// https:// URL to open the file in the Drive website.
DOMString? alternateUrl;
}; };
// Information about total and remaining size on the mount point. // Information about total and remaining size on the mount point.
......
...@@ -30,6 +30,7 @@ var IconSet; ...@@ -30,6 +30,7 @@ var IconSet;
* thumbnailUrl: (string|undefined), * thumbnailUrl: (string|undefined),
* croppedThumbnailUrl: (string|undefined), * croppedThumbnailUrl: (string|undefined),
* externalFileUrl: (string|undefined), * externalFileUrl: (string|undefined),
* alternateUrl: (string|undefined),
* imageWidth: (number|undefined), * imageWidth: (number|undefined),
* imageHeight: (number|undefined), * imageHeight: (number|undefined),
* imageRotation: (number|undefined), * imageRotation: (number|undefined),
......
...@@ -3,16 +3,22 @@ ...@@ -3,16 +3,22 @@
// found in the LICENSE file. // found in the LICENSE file.
/** /**
* A single action, that can be taken on a set of entries.
* @interface * @interface
*/ */
function Action() { function Action() {
} }
/**
* Executes this action on the set of entries.
*/
Action.prototype.execute = function() { Action.prototype.execute = function() {
}; };
/** /**
* @return {boolean} * Checks whether this action can execute on the set of entries.
*
* @return {boolean} True if the function can execute, false if not.
*/ */
Action.prototype.canExecute = function() { Action.prototype.canExecute = function() {
}; };
...@@ -400,7 +406,97 @@ DriveRemoveFolderShortcutAction.prototype.getTitle = function() { ...@@ -400,7 +406,97 @@ DriveRemoveFolderShortcutAction.prototype.getTitle = function() {
return null; return null;
}; };
/** /**
* Opens the entry in Drive Web for the user to manage permissions etc.
*
* @param {!Entry} entry The entry to open the 'Manage' page for.
* @param {!ActionModelUI} ui
* @param {!VolumeManagerWrapper} volumeManager
* @implements {Action}
* @constructor
* @struct
*/
function DriveManageAction(entry, volumeManager, ui) {
/**
* The entry to open the 'Manage' page for.
*
* @private {!Entry}
* @const
*/
this.entry_ = entry;
/**
* @private {!VolumeManagerWrapper}
* @const
*/
this.volumeManager_ = volumeManager;
/**
* @private {!ActionModelUI}
* @const
*/
this.ui_ = ui;
}
/**
* Creates a new DriveManageAction object.
* |entries| must contain only a single entry.
*
* @param {!Array<!Entry>} entries
* @param {!ActionModelUI} ui
* @param {!VolumeManagerWrapper} volumeManager
* @return {DriveManageAction}
*/
DriveManageAction.create = function(entries, volumeManager, ui) {
if (entries.length !== 1)
return null;
return new DriveManageAction(entries[0], volumeManager, ui);
};
/**
* @override
*/
DriveManageAction.prototype.execute = function() {
chrome.fileManagerPrivate.getEntryProperties(
[this.entry_], ['alternateUrl'], function(results) {
if (chrome.runtime.lastError) {
console.error(chrome.runtime.lastError.message);
return;
}
if (results.length == 1) {
console.error(
'getEntryProperties for alternateUrl should return 1 entry ' +
'(returned ' + results.length + ')');
return;
}
util.visitURL(results[0].alternateUrl);
}.bind(this));
};
/**
* @override
*/
DriveManageAction.prototype.canExecute = function() {
// For now, only allow managing of regular files (not directories).
return !this.entry_.isDirectory &&
this.volumeManager_.getDriveConnectionState().type !==
VolumeManagerCommon.DriveConnectionType.OFFLINE &&
!util.isTeamDriveRoot(this.entry_);
};
/**
* @return {?string}
*/
DriveManageAction.prototype.getTitle = function() {
return null;
};
/**
* A custom action set by the FSP API.
*
* @param {!Array<!Entry>} entries * @param {!Array<!Entry>} entries
* @param {string} id * @param {string} id
* @param {?string} title * @param {?string} title
...@@ -464,7 +560,8 @@ CustomAction.prototype.getTitle = function() { ...@@ -464,7 +560,8 @@ CustomAction.prototype.getTitle = function() {
}; };
/** /**
* Represents a set of actions for a set of entries. * Represents a set of actions for a set of entries. Includes actions set
* locally in JS, as well as those retrieved from the FSP API.
* *
* @param {!VolumeManagerWrapper} volumeManager * @param {!VolumeManagerWrapper} volumeManager
* @param {!MetadataModel} metadataModel * @param {!MetadataModel} metadataModel
...@@ -556,10 +653,13 @@ ActionsModel.CommonActionId = { ...@@ -556,10 +653,13 @@ ActionsModel.CommonActionId = {
*/ */
ActionsModel.InternalActionId = { ActionsModel.InternalActionId = {
CREATE_FOLDER_SHORTCUT: 'create-folder-shortcut', CREATE_FOLDER_SHORTCUT: 'create-folder-shortcut',
REMOVE_FOLDER_SHORTCUT: 'remove-folder-shortcut' REMOVE_FOLDER_SHORTCUT: 'remove-folder-shortcut',
MANAGE_IN_DRIVE: 'manage-in-drive'
}; };
/** /**
* Initializes the ActionsModel, including populating the list of available
* actions for the given entries.
* @return {!Promise} * @return {!Promise}
*/ */
ActionsModel.prototype.initialize = function() { ActionsModel.prototype.initialize = function() {
...@@ -632,6 +732,14 @@ ActionsModel.prototype.initialize = function() { ...@@ -632,6 +732,14 @@ ActionsModel.prototype.initialize = function() {
actions[ActionsModel.InternalActionId.REMOVE_FOLDER_SHORTCUT] = actions[ActionsModel.InternalActionId.REMOVE_FOLDER_SHORTCUT] =
removeFolderShortcutAction; removeFolderShortcutAction;
} }
var manageInDriveAction = DriveManageAction.create(
this.entries_, this.volumeManager_, this.ui_);
if (manageInDriveAction) {
actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE] =
manageInDriveAction;
}
fulfill(actions); fulfill(actions);
break; break;
......
...@@ -66,7 +66,7 @@ function MockUI() { ...@@ -66,7 +66,7 @@ function MockUI() {
showHtml: function() { showHtml: function() {
} }
}; };
}; }
function setUp() { function setUp() {
window.chrome = { window.chrome = {
...@@ -99,6 +99,9 @@ function setUp() { ...@@ -99,6 +99,9 @@ function setUp() {
ui = new MockUI(); ui = new MockUI();
} }
/**
* Tests that the correct actions are available for a directory in Google Drive.
*/
function testDriveDirectoryEntry(callback) { function testDriveDirectoryEntry(callback) {
driveFileSystem.entries['/test'] = driveFileSystem.entries['/test'] =
new MockDirectoryEntry(driveFileSystem, '/test', {}); new MockDirectoryEntry(driveFileSystem, '/test', {});
...@@ -111,8 +114,9 @@ function testDriveDirectoryEntry(callback) { ...@@ -111,8 +114,9 @@ function testDriveDirectoryEntry(callback) {
}); });
return reportPromise(model.initialize().then(function() { return reportPromise(model.initialize().then(function() {
var actions = model.getActions(); var actions = model.getActions();
assertEquals(2, Object.keys(actions).length); assertEquals(3, Object.keys(actions).length);
// 'Share' should be disabled in offline mode.
var shareAction = actions[ActionsModel.CommonActionId.SHARE]; var shareAction = actions[ActionsModel.CommonActionId.SHARE];
assertTrue(!!shareAction); assertTrue(!!shareAction);
volumeManager.driveConnectionState = { volumeManager.driveConnectionState = {
...@@ -120,6 +124,13 @@ function testDriveDirectoryEntry(callback) { ...@@ -120,6 +124,13 @@ function testDriveDirectoryEntry(callback) {
}; };
assertFalse(shareAction.canExecute()); assertFalse(shareAction.canExecute());
// 'Manage in Drive' should be disabled for directories.
var manageInDriveAction =
actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
assertTrue(!!manageInDriveAction);
assertFalse(manageInDriveAction.canExecute());
// 'Create Shortcut' should be enabled, until it's executed, then disabled.
var createFolderShortcutAction = var createFolderShortcutAction =
actions[ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT]; actions[ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT];
assertTrue(!!createFolderShortcutAction); assertTrue(!!createFolderShortcutAction);
...@@ -138,8 +149,12 @@ function testDriveDirectoryEntry(callback) { ...@@ -138,8 +149,12 @@ function testDriveDirectoryEntry(callback) {
return model.initialize(); return model.initialize();
}).then(function() { }).then(function() {
var actions = model.getActions(); var actions = model.getActions();
assertEquals(3, Object.keys(actions).length); assertEquals(4, Object.keys(actions).length);
assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]);
assertTrue(!!actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE]);
assertTrue(!!actions[ActionsModel.InternalActionId.REMOVE_FOLDER_SHORTCUT]);
// 'Create shortcut' should be disabled.
var createFolderShortcutAction = var createFolderShortcutAction =
actions[ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT]; actions[ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT];
assertTrue(!!createFolderShortcutAction); assertTrue(!!createFolderShortcutAction);
...@@ -148,6 +163,9 @@ function testDriveDirectoryEntry(callback) { ...@@ -148,6 +163,9 @@ function testDriveDirectoryEntry(callback) {
}), callback); }), callback);
} }
/**
* Tests that the correct actions are available for a file in Google Drive.
*/
function testDriveFileEntry(callback) { function testDriveFileEntry(callback) {
driveFileSystem.entries['/test.txt'] = driveFileSystem.entries['/test.txt'] =
new MockFileEntry(driveFileSystem, '/test.txt', {}); new MockFileEntry(driveFileSystem, '/test.txt', {});
...@@ -161,14 +179,21 @@ function testDriveFileEntry(callback) { ...@@ -161,14 +179,21 @@ function testDriveFileEntry(callback) {
}; };
return reportPromise(model.initialize().then(function() { return reportPromise(model.initialize().then(function() {
var actions = model.getActions(); var actions = model.getActions();
assertEquals(2, Object.keys(actions).length); assertEquals(3, Object.keys(actions).length);
assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]); assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]);
// 'Save for Offline' should be enabled.
var saveForOfflineAction = var saveForOfflineAction =
actions[ActionsModel.CommonActionId.SAVE_FOR_OFFLINE]; actions[ActionsModel.CommonActionId.SAVE_FOR_OFFLINE];
assertTrue(!!saveForOfflineAction); assertTrue(!!saveForOfflineAction);
assertTrue(saveForOfflineAction.canExecute()); assertTrue(saveForOfflineAction.canExecute());
// 'Manage in Drive' should be enabled.
var manageInDriveAction =
actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
assertTrue(!!manageInDriveAction);
assertTrue(manageInDriveAction.canExecute());
chrome.fileManagerPrivate.pinDriveFile = function(entry, pin, callback) { chrome.fileManagerPrivate.pinDriveFile = function(entry, pin, callback) {
metadataModel.properties.pinned = true; metadataModel.properties.pinned = true;
assertEquals(driveFileSystem.entries['/test.txt'], entry); assertEquals(driveFileSystem.entries['/test.txt'], entry);
...@@ -196,14 +221,21 @@ function testDriveFileEntry(callback) { ...@@ -196,14 +221,21 @@ function testDriveFileEntry(callback) {
return model.initialize(); return model.initialize();
}).then(function() { }).then(function() {
var actions = model.getActions(); var actions = model.getActions();
assertEquals(2, Object.keys(actions).length); assertEquals(3, Object.keys(actions).length);
assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]); assertTrue(!!actions[ActionsModel.CommonActionId.SHARE]);
// 'Offline not Necessary' should be enabled.
var offlineNotNecessaryAction = var offlineNotNecessaryAction =
actions[ActionsModel.CommonActionId.OFFLINE_NOT_NECESSARY]; actions[ActionsModel.CommonActionId.OFFLINE_NOT_NECESSARY];
assertTrue(!!offlineNotNecessaryAction); assertTrue(!!offlineNotNecessaryAction);
assertTrue(offlineNotNecessaryAction.canExecute()); assertTrue(offlineNotNecessaryAction.canExecute());
// 'Manage in Drive' should be enabled.
var manageInDriveAction =
actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
assertTrue(!!manageInDriveAction);
assertTrue(manageInDriveAction.canExecute());
chrome.fileManagerPrivate.pinDriveFile = function(entry, pin, callback) { chrome.fileManagerPrivate.pinDriveFile = function(entry, pin, callback) {
metadataModel.properties.pinned = false; metadataModel.properties.pinned = false;
assertEquals(driveFileSystem.entries['/test.txt'], entry); assertEquals(driveFileSystem.entries['/test.txt'], entry);
...@@ -224,7 +256,10 @@ function testDriveFileEntry(callback) { ...@@ -224,7 +256,10 @@ function testDriveFileEntry(callback) {
}), callback); }), callback);
} }
function testTeamDriveEntry(callback) { /**
* Tests that a Team Drive Root entry has the correct actions available.
*/
function testTeamDriveRootEntry(callback) {
driveFileSystem.entries['/team_drives/ABC Team'] = driveFileSystem.entries['/team_drives/ABC Team'] =
new MockDirectoryEntry(driveFileSystem, '/team_drives/ABC Team', {}); new MockDirectoryEntry(driveFileSystem, '/team_drives/ABC Team', {});
...@@ -234,16 +269,99 @@ function testTeamDriveEntry(callback) { ...@@ -234,16 +269,99 @@ function testTeamDriveEntry(callback) {
return reportPromise( return reportPromise(
model.initialize().then(function() { model.initialize().then(function() {
var actions = model.getActions(); var actions = model.getActions();
assertEquals(1, Object.keys(actions).length); assertEquals(2, Object.keys(actions).length);
// "share" action is disabled for Team Drive entries. // "share" action is disabled for Team Drive Root entries.
var shareAction = actions[ActionsModel.CommonActionId.SHARE]; var shareAction = actions[ActionsModel.CommonActionId.SHARE];
assertTrue(!!shareAction); assertTrue(!!shareAction);
assertFalse(shareAction.canExecute()); assertFalse(shareAction.canExecute());
// "manage in drive" action is disabled for Team Drive Root entries.
var manageAction =
actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
assertTrue(!!manageAction);
assertFalse(manageAction.canExecute());
}),
callback);
}
/**
* Tests that a Team Drive directory entry has the correct actions available.
*/
function testTeamDriveDirectoryEntry(callback) {
driveFileSystem.entries['/team_drives/ABC Team/Folder 1'] =
new MockDirectoryEntry(
driveFileSystem, '/team_drives/ABC Team/Folder 1', {});
var model = new ActionsModel(
volumeManager, metadataModel, shortcutsModel, driveSyncHandler, ui,
[driveFileSystem.entries['/team_drives/ABC Team/Folder 1']]);
return reportPromise(
model.initialize().then(function() {
var actions = model.getActions();
assertEquals(3, Object.keys(actions).length);
// "share" action is enabled for Team Drive directories.
var shareAction = actions[ActionsModel.CommonActionId.SHARE];
assertTrue(!!shareAction);
assertTrue(shareAction.canExecute());
// "manage in drive" action is disabled for Team Drive directories.
var manageAction =
actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
assertTrue(!!manageAction);
assertFalse(manageAction.canExecute());
// 'Create shortcut' should be enabled.
var createFolderShortcutAction =
actions[ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT];
assertTrue(!!createFolderShortcutAction);
assertTrue(createFolderShortcutAction.canExecute());
}),
callback);
}
/**
* Tests that a Team Drive file entry has the correct actions available.
*/
function testTeamDriveFileEntry(callback) {
driveFileSystem.entries['/team_drives/ABC Team/Folder 1/test.txt'] =
new MockFileEntry(
driveFileSystem, '/team_drives/ABC Team/Folder 1/test.txt', {});
var model = new ActionsModel(
volumeManager, metadataModel, shortcutsModel, driveSyncHandler, ui,
[driveFileSystem.entries['/team_drives/ABC Team/Folder 1/test.txt']]);
metadataModel.properties = {hosted: false, pinned: false};
return reportPromise(
model.initialize().then(function() {
var actions = model.getActions();
assertEquals(3, Object.keys(actions).length);
// "save for offline" action is enabled for Team Drive file entries.
var saveForOfflineAction =
actions[ActionsModel.CommonActionId.SAVE_FOR_OFFLINE];
assertTrue(!!saveForOfflineAction);
assertTrue(saveForOfflineAction.canExecute());
// "share" action is enabled for Team Drive file entries.
var shareAction = actions[ActionsModel.CommonActionId.SHARE];
assertTrue(!!shareAction);
assertTrue(shareAction.canExecute());
// "manage in drive" action is enabled for Team Drive file entries.
var manageAction =
actions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
assertTrue(!!manageAction);
assertTrue(manageAction.canExecute());
}), }),
callback); callback);
} }
/**
* Tests that if actions are provided with getCustomActions(), they appear
* correctly for the file.
*/
function testProvidedEntry(callback) { function testProvidedEntry(callback) {
providedFileSystem.entries['/test'] = providedFileSystem.entries['/test'] =
new MockDirectoryEntry(providedFileSystem, '/test', {}); new MockDirectoryEntry(providedFileSystem, '/test', {});
...@@ -311,6 +429,9 @@ function testProvidedEntry(callback) { ...@@ -311,6 +429,9 @@ function testProvidedEntry(callback) {
}), callback); }), callback);
} }
/**
* Tests that no actions are available when getCustomActions() throws an error.
*/
function testProvidedEntryWithError(callback) { function testProvidedEntryWithError(callback) {
providedFileSystem.entries['/test'] = providedFileSystem.entries['/test'] =
new MockDirectoryEntry(providedFileSystem, '/test', {}); new MockDirectoryEntry(providedFileSystem, '/test', {});
......
...@@ -1504,6 +1504,41 @@ CommandHandler.COMMANDS_['share'] = /** @type {Command} */ ({ ...@@ -1504,6 +1504,41 @@ CommandHandler.COMMANDS_['share'] = /** @type {Command} */ ({
} }
}); });
/**
* Opens the file in Drive for the user to manage sharing permissions etc.
* @type {Command}
*/
CommandHandler.COMMANDS_['manage-in-drive'] = /** @type {Command} */ ({
/**
* @param {!Event} event Command event.
* @param {!CommandHandlerDeps} fileManager The file manager instance.
*/
execute: function(event, fileManager) {
var actionsModel =
fileManager.actionsController.getActionsModelFor(event.target);
var action = actionsModel ?
actionsModel.getAction(ActionsModel.InternalActionId.MANAGE_IN_DRIVE) :
null;
if (action)
action.execute();
},
/**
* @param {!Event} event Command event.
* @param {!CommandHandlerDeps} fileManager CommandHandlerDeps to use.
*/
canExecute: function(event, fileManager) {
var actionsModel =
fileManager.actionsController.getActionsModelFor(event.target);
var action = actionsModel ?
actionsModel.getAction(ActionsModel.InternalActionId.MANAGE_IN_DRIVE) :
null;
event.canExecute = action && action.canExecute();
if (actionsModel)
event.command.setHidden(!action);
}
});
/** /**
* Creates a shortcut of the selected folder (single only). * Creates a shortcut of the selected folder (single only).
* @type {Command} * @type {Command}
......
...@@ -67,6 +67,18 @@ ActionsSubmenu.prototype.setActionsModel = function(actionsModel) { ...@@ -67,6 +67,18 @@ ActionsSubmenu.prototype.setActionsModel = function(actionsModel) {
} }
util.queryDecoratedElement('#share', cr.ui.Command).canExecuteChange(); util.queryDecoratedElement('#share', cr.ui.Command).canExecuteChange();
// Then add the Manage in Drive item (if available).
var manageInDriveAction =
remainingActions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
if (manageInDriveAction) {
var menuItem = this.addMenuItem_({});
menuItem.command = '#manage-in-drive';
menuItem.classList.toggle('hide-on-toolbar', true);
delete remainingActions[ActionsModel.InternalActionId.MANAGE_IN_DRIVE];
}
util.queryDecoratedElement('#manage-in-drive', cr.ui.Command)
.canExecuteChange();
// Managing shortcuts is shown just before custom actions. // Managing shortcuts is shown just before custom actions.
var createFolderShortcutAction = remainingActions[ var createFolderShortcutAction = remainingActions[
ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT]; ActionsModel.InternalActionId.CREATE_FOLDER_SHORTCUT];
......
...@@ -13,6 +13,7 @@ function queryRequiredElement(selectors, opt_context) { ...@@ -13,6 +13,7 @@ function queryRequiredElement(selectors, opt_context) {
</script> </script>
<command id="share" label="Share"></command> <command id="share" label="Share"></command>
<command id="manage-in-drive" i18n-values="Manage in Drive"></command>
<command id="toggle-pinned" label="Toggle pinned"></command> <command id="toggle-pinned" label="Toggle pinned"></command>
<command id="create-folder-shortcut" label="Create folder shortcut"></command> <command id="create-folder-shortcut" label="Create folder shortcut"></command>
<command id="remove-folder-shortcut" label="Remove folder shortcut"></command> <command id="remove-folder-shortcut" label="Remove folder shortcut"></command>
......
...@@ -152,6 +152,8 @@ ...@@ -152,6 +152,8 @@
<command id="share" i18n-values="label:SHARE_BUTTON_LABEL" disabled hidden <command id="share" i18n-values="label:SHARE_BUTTON_LABEL" disabled hidden
shortcut="." hide-shortcut-text> shortcut="." hide-shortcut-text>
<command id="manage-in-drive"
i18n-values="label:MANAGE_IN_DRIVE_BUTTON_LABEL" disabled hidden>
<command id="zoom-in" shortcut="=|Ctrl"> <command id="zoom-in" shortcut="=|Ctrl">
<command id="zoom-out" shortcut="-|Ctrl"> <command id="zoom-out" shortcut="-|Ctrl">
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment