Chromium Code Reviews| 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..c2f009d1d5918164542af14291e100be5cca5efd 100644 |
| --- a/chrome/browser/resources/file_manager/js/file_manager.js |
| +++ b/chrome/browser/resources/file_manager/js/file_manager.js |
| @@ -1471,10 +1471,14 @@ 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, |
| this.shouldShowUnmount_(selection.urls))); |
| + // This needs to be done in sparate function, as check requires |
| + // asynchronous function calls. |
| + this.DisplayFormattingTask1_(selection.entries); |
| } |
| cacheNextFile(); |
| @@ -1549,8 +1553,6 @@ FileManager.prototype = { |
| title: '' |
| }); |
| } |
| - |
| - this.taskButtons_.innerHTML = ''; |
| for (var i = 0; i < tasksList.length; i++) { |
| var task = tasksList[i]; |
| @@ -1586,19 +1588,65 @@ FileManager.prototype = { |
| task.title = str('UNMOUNT_ARCHIVE'); |
| } |
| } |
| + this.renderTaskButton_(task); |
| + } |
| + }; |
| - 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.DisplayFormattingTask1_ = function(entries) { |
|
rginda
2011/08/10 23:08:09
JavaScript naming convention has leadingLowercase
sidor.dev
2011/08/10 23:51:21
Done.
|
| + if (entries.length != 1) |
| + return; |
| + var self = this; |
| + chrome.fileBrowserPrivate.getMountPoints( |
| + this.DisplayFormattingTask2_.bind(this, entries[0].fullPath)); |
| + }; |
| + |
| + FileManager.prototype.DisplayFormattingTask2_ = function(mountPath, |
|
rginda
2011/08/10 23:08:09
The convention elsewhere in this file is to declar
sidor.dev
2011/08/10 23:51:21
Done.
|
| + mountPoints) { |
| + var normalize = function(x) { |
| + if(x[0] == '/') |
| + return x.slice(1); |
| + else |
| + return x; |
| + } |
| + this.mountPoints_ = mountPoints; |
| + for (var i = 0; i < mountPoints.length; ++i) { |
|
rginda
2011/08/10 23:08:09
i++
sidor.dev
2011/08/10 23:51:21
Done. Out of curiosity - why is that a convention
|
| + if (mountPoints[i].mountType == "device" && |
| + normalize(mountPoints[i].mountPath) == normalize(mountPath)) { |
| + chrome.fileBrowserPrivate.getVolumeMetadata(mountPoints[i].sourceUrl, |
| + this.DisplayFormattingTask3_.bind(this)); |
| + return; |
| + } |
| + } |
| + }; |
| + |
| + FileManager.prototype.DisplayFormattingTask3_ = function(volumeMetadata) { |
|
rginda
2011/08/10 23:08:09
and onVolumeMetadataFound
sidor.dev
2011/08/10 23:51:21
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); |
|
rginda
2011/08/10 23:08:09
You should probably omit the entries parameter to
sidor.dev
2011/08/10 23:51:21
Done.
|
| } |
| }; |
| @@ -1666,6 +1714,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]); |
| } |
| }; |