Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: ui/file_manager/file_manager/foreground/js/file_tasks.js

Issue 1872223002: Add verbs API to file handlers. Modify the Chrome OS UI so that it displayes the internationalized … (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move back to "open-with" for the id of the more actions dialog, as it breaks some browsers tests, a… Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/file_manager/foreground/js/file_tasks.js
diff --git a/ui/file_manager/file_manager/foreground/js/file_tasks.js b/ui/file_manager/file_manager/foreground/js/file_tasks.js
index 1096215199a1d6691d7d238adef44fd5e7bc1e8b..89f5402dee2c1797fcfbfe058297ed9932e3d822 100644
--- a/ui/file_manager/file_manager/foreground/js/file_tasks.js
+++ b/ui/file_manager/file_manager/foreground/js/file_tasks.js
@@ -141,19 +141,7 @@ FileTasks.create = function(volumeManager, metadataModel, directoryModel, ui,
});
var defaultTaskPromise = tasksPromise.then(function(tasks) {
- for (var i = 0; i < tasks.length; i++) {
- if (tasks[i].isDefault) {
- return tasks[i];
- }
- }
- // If we haven't picked a default task yet, then just pick the first one
- // which is not generic file handler.
- for (var i = 0; i < tasks.length; i++) {
- if (!tasks[i].isGenericFileHandler) {
- return tasks[i];
- }
- }
- return null;
+ return FileTasks.getDefaultTask(tasks);
});
return Promise.all([tasksPromise, defaultTaskPromise]).then(
@@ -380,6 +368,29 @@ FileTasks.annotateTasks_ = function(tasks, entries) {
if (!task.iconType && taskParts[1] === 'web-intent') {
task.iconType = 'generic';
}
+
+ // Add verb to title.
+ if (task.verb) {
+ var verb_button_label = 'OPEN_WITH_VERB_BUTTON_LABEL'; // Default.
+ switch (task.verb) {
+ case chrome.fileManagerPrivate.Verb.ADD_TO:
+ verb_button_label = 'ADD_TO_VERB_BUTTON_LABEL';
+ break;
+ case chrome.fileManagerPrivate.Verb.PACK_WITH:
+ verb_button_label = 'PACK_WITH_VERB_BUTTON_LABEL';
+ break;
+ case chrome.fileManagerPrivate.Verb.SHARE_WITH:
+ verb_button_label = 'SHARE_WITH_VERB_BUTTON_LABEL';
+ break;
+ case chrome.fileManagerPrivate.Verb.OPEN_WITH:
+ // Nothing to do as same as initialization button label.
+ break;
+ default:
+ console.error('Invalid task verb: ' + task.verb + '.');
+ }
+ task.title = loadTimeData.getStringF(verb_button_label, task.title);
+ }
+
result.push(task);
}
@@ -720,7 +731,7 @@ FileTasks.prototype.display = function(combobutton) {
} else {
combobutton.defaultItem = {
type: FileTasks.TaskMenuButtonItemType.ShowMenu,
- label: str('OPEN_WITH_BUTTON_LABEL')
+ label: str('MORE_ACTIONS_BUTTON_LABEL')
};
}
@@ -846,3 +857,31 @@ FileTasks.prototype.showTaskPicker = function(taskDialog, title, message,
onSuccess(item.task);
});
};
+
+/**
+ * Gets the default task from tasks. In case there is no such task (i.e. all
+ * tasks are generic file handlers), then return opt_taskToUseIfNoDefault or
+ * null.
+ *
+ * @param {!Array<!Object>} tasks The list of tasks from where to choose the
+ * default task.
+ * @param {!Object=} opt_taskToUseIfNoDefault The task to return in case there
+ * is no default task available in tasks.
+ * @return {Object} opt_taskToUseIfNoDefault or null in case
+ * opt_taskToUseIfNoDefault is undefined.
+ */
+FileTasks.getDefaultTask = function(tasks, opt_taskToUseIfNoDefault) {
+ for (var i = 0; i < tasks.length; i++) {
+ if (tasks[i].isDefault) {
+ return tasks[i];
+ }
+ }
+ // If we haven't picked a default task yet, then just pick the first one
+ // which is not generic file handler.
+ for (var i = 0; i < tasks.length; i++) {
+ if (!tasks[i].isGenericFileHandler) {
+ return tasks[i];
+ }
+ }
+ return opt_taskToUseIfNoDefault || null;
+};

Powered by Google App Engine
This is Rietveld 408576698