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

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

Issue 7583041: Adding a format device button to UI. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: more localizing + style Created 9 years, 4 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 f3f490c84969ee016d510aee70dce34fd0bf2908..a3bd0d748d1c75599eccd5d8272ea343bc486394 100644
--- a/chrome/browser/resources/file_manager/js/file_manager.js
+++ b/chrome/browser/resources/file_manager/js/file_manager.js
@@ -1471,6 +1471,7 @@ FileManager.prototype = {
if (this.dialogType_ == FileManager.DialogType.FULL_PAGE) {
// Since unmount task cannot be defined in terms of file patterns,
// we manually include it here, if all selected items are mount points.
+ this.taskButtons_.innerHTML = '';
chrome.fileBrowserPrivate.getFileTasks(
selection.urls,
this.onTasksFound_.bind(this,
@@ -1549,8 +1550,6 @@ FileManager.prototype = {
title: ''
});
}
-
- this.taskButtons_.innerHTML = '';
for (var i = 0; i < tasksList.length; i++) {
var task = tasksList[i];
@@ -1586,20 +1585,79 @@ FileManager.prototype = {
task.title = str('UNMOUNT_ARCHIVE');
}
}
+ this.renderTaskButton_(task);
+ }
+ // This needs to be done in sparate function, as check requires
+ // asynchronous function calls.
+ this.maybeRenderFormattingTask_();
+ };
- var button = this.document_.createElement('button');
- button.addEventListener('click', this.onTaskButtonClicked_.bind(this));
- button.className = 'task-button';
- button.task = task;
+ FileManager.prototype.renderTaskButton_ = function(task) {
+ var button = this.document_.createElement('button');
+ button.addEventListener('click', this.onTaskButtonClicked_.bind(this));
+ button.className = 'task-button';
+ button.task = task;
- var img = this.document_.createElement('img');
- img.src = task.iconUrl;
+ var img = this.document_.createElement('img');
+ img.src = task.iconUrl;
+
+ button.appendChild(img);
+ button.appendChild(this.document_.createTextNode(task.title));
- button.appendChild(img);
- button.appendChild(this.document_.createTextNode(task.title));
+ this.taskButtons_.appendChild(button);
+ };
- this.taskButtons_.appendChild(button);
+ /**
+ * Checks whether formatting task should be displayed and if the answer is
+ * affirmative renders it. Includes asynchronous calls, so it's splitted into
+ * three parts.
+ */
+ FileManager.prototype.maybeRenderFormattingTask_ = function() {
+ // Not to make unnecesary getMountPoints() call we doublecheck if there is
+ // only one selected entry.
+ if(this.selection.entries.length != 1)
+ return;
+
+ function onMountPointsFound(mountPoints) {
+ this.mountPoints_ = mountPoints;
+
+ function normalize(x) {
+ if(x[0] == '/')
+ return x.slice(1);
+ else
+ return x;
+ }
+
+ function onVolumeMetadataFound(volumeMetadata) {
+ if (volumeMetadata.deviceType == "flash") {
+ if (this.selection.entries.length != 1 ||
+ normalize(this.selection.entries[0].fullPath) !=
+ normalize(volumeMetadata.mountPath)) {
+ return;
+ }
+ var task = {
+ taskId: this.getExtensionId_() + '|format-device',
+ iconUrl: chrome.extension.getURL('images/filetype_generic.png'),
+ title: str('FORMAT_DEVICE')
+ };
+ this.renderTaskButton_(task);
+ }
+ }
+
+ if(this.selection.entries.length != 1)
+ return;
+ var selectedPath = this.selection.entries[0].fullPath;
+ for (var i = 0; i < mountPoints.length; i++) {
+ if (mountPoints[i].mountType == "device" &&
+ normalize(mountPoints[i].mountPath) == normalize(selectedPath)) {
+ chrome.fileBrowserPrivate.getVolumeMetadata(mountPoints[i].sourceUrl,
+ onVolumeMetadataFound.bind(this));
+ return;
+ }
+ }
}
+
+ chrome.fileBrowserPrivate.getMountPoints(onMountPointsFound.bind(this));
rginda 2011/08/11 20:20:14 The convention for nested functions is to create a
sidor.dev 2011/08/12 02:05:20 Done.
};
FileManager.prototype.getExtensionId_ = function() {
@@ -1666,6 +1724,10 @@ FileManager.prototype = {
for (var index = 0; index < urls.length; ++index) {
chrome.fileBrowserPrivate.removeMount(urls[index]);
}
+ } else if (id == 'format-device') {
+ if (!confirm(str('FORMATTING_WARNING')))
rginda 2011/08/11 20:20:14 App modal dialogs are no longer allowed here. You
sidor.dev 2011/08/12 02:05:20 Done.
+ return;
+ chrome.fileBrowserPrivate.formatDevice(urls[0]);
}
};

Powered by Google App Engine
This is Rietveld 408576698