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

Unified Diff: chrome/browser/resources/file_manager/js/file_manager.js

Issue 10411018: [FileBrowser] Added DefaultAction dialog to choose default action. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed comments. Created 8 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: chrome/browser/resources/file_manager/js/file_manager.js
diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js
index 719a4eea128aa196ac63ad830085e122d0d208c6..be72895e7561f2c2f7e5af135bf63e8a1364e8e3 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -529,6 +529,8 @@ FileManager.prototype = {
this.alert = new d.AlertDialog(this.dialogDom_);
this.confirm = new d.ConfirmDialog(this.dialogDom_);
this.prompt = new d.PromptDialog(this.dialogDom_);
+ this.defaultTaskPicker =
+ new cr.filebrowser.DefaultActionDialog(this.dialogDom_);
};
/**
@@ -2499,6 +2501,15 @@ FileManager.prototype = {
};
/**
+ * Creates combobox item based on task.
+ * @param {Object} task Task to convert.
+ * @return {Object} Item appendable to combobox drop-down list.
+ */
+ FileManager.prototype.createComboboxItem_ = function(task) {
+ return { label: task.title, iconUrl: task.iconUrl, task: task };
+ }
+
+ /**
* Callback called when tasks for selected files are determined.
* @param {Object} selection Selection is passed here, since this.selection
* can change before tasks were found, and we should be accurate.
@@ -2508,7 +2519,8 @@ FileManager.prototype = {
this.taskItems_.clear();
var defaultTask = null;
- var tasksCount = 0;
+ var dropDownItems = [];
+
for (var i = 0; i < tasksList.length; i++) {
var task = tasksList[i];
@@ -2567,15 +2579,38 @@ FileManager.prototype = {
task.title = str('INSTALL_CRX');
}
}
- this.taskItems_.addItem(this.renderTaskItem_(task));
- tasksCount++;
- if (defaultTask == null) defaultTask = task;
+
+ if (defaultTask == null) {
+ defaultTask = task;
+ this.taskItems_.defaultItem = this.createComboboxItem_(task);
+ task.title = task.title + ' ' + str('DEFAULT_ACTION_LABEL');
+ dropDownItems.push(this.createComboboxItem_(task));
+ } else {
+ dropDownItems.push(this.createComboboxItem_(task));
+ }
}
- this.taskItems_.hidden = tasksCount == 0;
- if (tasksCount > 1) {
- // Duplicate default task in drop-down list.
- this.taskItems_.addItem(this.renderTaskItem_(defaultTask));
+ var defaultIdx = 0;
+ this.taskItems_.hidden = dropDownItems.length == 0;
+
+ if (dropDownItems.length > 1) {
+ dropDownItems.sort(function(a, b) {
+ return a.label.localeCompare(b.label);
+ });
+
+ for (var j = 0; j < dropDownItems.length; j++) {
+ this.taskItems_.addDropDownItem(dropDownItems[j]);
+ if (dropDownItems[j].task.taskId == defaultTask.taskId) {
+ defaultIdx = j;
+ }
+ }
+
+ this.taskItems_.addSeparator();
+ this.taskItems_.addDropDownItem({
+ label: str('CHANGE_DEFAULT_MENU_ITEM'),
+ items: dropDownItems,
+ defaultIdx: defaultIdx
+ });
}
selection.tasksList = tasksList;
@@ -2586,22 +2621,6 @@ FileManager.prototype = {
}
};
- FileManager.prototype.renderTaskItem_ = function(task) {
- var item = this.document_.createElement('div');
- item.className = 'task-item';
- item.task = task;
-
- var img = this.document_.createElement('img');
- img.src = task.iconUrl;
- item.appendChild(img);
-
- var label = this.document_.createElement('div');
- label.appendChild(this.document_.createTextNode(task.title));
- item.appendChild(label);
-
- return item;
- };
-
FileManager.prototype.getExtensionId_ = function() {
return chrome.extension.getURL('').split('/')[2];
};
@@ -2613,10 +2632,55 @@ FileManager.prototype = {
}
};
+ /**
+ * Task combobox handler.
+ *
+ * @param {Object} event Event containing task which was clicked.
+ */
FileManager.prototype.onTaskItemClicked_ = function(event) {
- this.dispatchFileTask_(event.item.task.taskId, this.selection.urls);
+ if (event.item.task) {
+ // Task field doesn't exist on change-default dropdown item.
+ this.dispatchFileTask_(event.item.task.taskId, this.selection.urls);
+ } else {
+ var extensions = [];
+
+ for (var i = 0; i < this.selection.urls.length; i++) {
+ var match = /\.(\w+)$/g.exec(this.selection.urls[i]);
+ if (match) {
+ var ext = match[1].toUpperCase();
+ if (extensions.indexOf(ext) == -1) {
+ extensions.push(ext);
+ }
+ }
+ }
+
+ var format = '';
+
+ if (extensions.length != 1) {
+ format = extensions[0];
+ }
+
+ // Change default was clicked. We should open "change default" dialog.
+ this.defaultTaskPicker.show(
+ strf('CHANGE_DEFAULT_CAPTION', format),
+ event.item.items, event.item.defaultIdx,
+ this.onDefaultTaskDone_.bind(this));
+ }
};
+
+ /**
+ * Set's given task as default, when this task is applicable.
+ * @param {Object} task Task to set as default.
+ */
+ FileManager.prototype.onDefaultTaskDone_ = function(task) {
+ chrome.fileBrowserPrivate.setDefaultTask(task.taskId);
+
+ chrome.fileBrowserPrivate.getFileTasks(
+ this.selection.urls,
+ this.onTasksFound_.bind(this, this.selection));
+ }
+
/**
* Dispatches default task for the current selection. If tasks are not ready
* yet, dispatches after task are available.

Powered by Google App Engine
This is Rietveld 408576698