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..caa833f3f7ea7f01b0e85ad494341be15360e1ac 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,74 @@ 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_(); |
+ }; |
+ |
+ 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; |
+ |
+ button.appendChild(img); |
+ button.appendChild(this.document_.createTextNode(task.title)); |
- var button = this.document_.createElement('button'); |
- button.addEventListener('click', this.onTaskButtonClicked_.bind(this)); |
- button.className = 'task-button'; |
- button.task = task; |
+ this.taskButtons_.appendChild(button); |
+ }; |
- var img = this.document_.createElement('img'); |
- img.src = task.iconUrl; |
+ /** |
+ * 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; |
- button.appendChild(img); |
- button.appendChild(this.document_.createTextNode(task.title)); |
+ function onMountPointsFound(mountPoints) { |
+ this.mountPoints_ = mountPoints; |
- this.taskButtons_.appendChild(button); |
+ function normalize(x) { |
+ if(x[0] == '/') |
+ return x.slice(1); |
+ else |
+ return x; |
+ } |
+ |
+ function onVolumeMetadataFound(volumeMetadata) { |
tbarzic
2011/08/11 00:58:18
what if selection has changed by now?
sidor
2011/08/11 04:28:51
Hmm... Then we are screwed. But hey, to change the
tbarzic
2011/08/11 04:49:48
maybe you could do something like
if (this.selecti
sidor.dev
2011/08/11 18:39:43
Done.
|
+ if (volumeMetadata.deviceType == "flash") { |
+ 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 maybeMountPath = this.selection.entries[0].fullPath; |
tbarzic
2011/08/11 00:58:18
why maybe here?
sidor
2011/08/11 04:28:51
Because it might be a regular directory path.
tbarzic
2011/08/11 04:49:48
maybe entryPath or selectedPath would be better na
sidor.dev
2011/08/11 18:39:43
Done.
|
+ for (var i = 0; i < mountPoints.length; i++) { |
+ if (mountPoints[i].mountType == "device" && |
+ normalize(mountPoints[i].mountPath) == normalize(maybeMountPath)) { |
+ chrome.fileBrowserPrivate.getVolumeMetadata(mountPoints[i].sourceUrl, |
+ onVolumeMetadataFound.bind(this)); |
+ return; |
+ } |
+ } |
} |
+ |
+ chrome.fileBrowserPrivate.getMountPoints(onMountPointsFound.bind(this)); |
}; |
FileManager.prototype.getExtensionId_ = function() { |
@@ -1666,6 +1719,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'))) |
+ return; |
+ chrome.fileBrowserPrivate.formatDevice(urls[0]); |
} |
}; |