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 4ecc60e594ca8096e84a4805dc9102edcd289dbd..c76a826df6f36caa7cc40049d2d2479431104c28 100644 |
--- a/chrome/browser/resources/file_manager/js/file_manager.js |
+++ b/chrome/browser/resources/file_manager/js/file_manager.js |
@@ -54,6 +54,9 @@ function FileManager(dialogDom, rootEntries, params) { |
this.defaultPath_ = this.params_.defaultPath || '/'; |
+ // Optional list of file types. |
+ this.fileTypes_ = this.params_.typeList; |
+ |
this.showCheckboxes_ = |
(this.dialogType_ == FileManager.DialogType.FULL_PAGE || |
this.dialogType_ == FileManager.DialogType.SELECT_OPEN_MULTI_FILE); |
@@ -546,6 +549,40 @@ FileManager.prototype = { |
}; |
/** |
+ * Encodes filename to compose file URL. |
+ */ |
+ FileManager.prototype.encodeFileName_ = function(fileName) { |
+ fileName = encodeURI(fileName); |
rginda
2011/06/01 16:53:51
If you switch to encodeURIComponent you won't need
SeRya
2011/06/02 08:42:40
Done.
|
+ |
+ // '#' would be treated as ananchor mark of the url. Escape it. |
+ fileName = fileName.replace(/#/g, '%23'); |
+ return fileName; |
+ }; |
+ |
+ /** |
+ * "Save a file" dislog is suttposed to have a combo box with available |
rginda
2011/06/01 16:53:51
dislog is suttposed => dialog is supposed
SeRya
2011/06/02 08:42:40
Done.
|
+ * file types. Selecting an item filter files by extension and specifies how |
rginda
2011/06/01 16:53:51
filters files
SeRya
2011/06/02 08:42:40
Done.
|
+ * file should be saved. |
+ * @return {intener} Index of selected type from this.fileTypes_ + 1. 0 |
+ * means value is not specified. |
+ */ |
+ FileManager.prototype.getSelectedFilterIndex_= function(fileName) { |
+ // TODO(serya): Implement the combo box |
+ // For now try to guess choice by file extension. |
+ if (!this.fileTypes_ || this.fileTypes_.length == 0) return 0; |
+ |
+ var extension = /\.[^\.]+$/.exec(fileName); |
+ extension = extension ? extension[0].substring(1).toLowerCase() : ""; |
+ var result = 0; // Use first type by default. |
+ for (var i = 0; i < this.fileTypes_.length; i++) { |
+ if (this.fileTypes_[i].extensions.indexOf(extension)) { |
+ result = i; |
+ } |
+ } |
+ return result + 1; // 1-based index. |
+ }; |
+ |
+ /** |
* Force the canExecute events to be dispatched. |
*/ |
FileManager.prototype.updateCommands_ = function() { |
@@ -2061,8 +2098,9 @@ FileManager.prototype = { |
if (!filename) |
throw new Error('Missing filename!'); |
- chrome.fileBrowserPrivate.selectFile(currentDirUrl + encodeURI(filename), |
- 0); |
+ chrome.fileBrowserPrivate.selectFile( |
+ currentDirUrl + this.encodeFileName_(filename), |
+ this.getSelectedFilterIndex_(filename)); |
window.close(); |
return; |
} |
@@ -2083,7 +2121,7 @@ FileManager.prototype = { |
continue; |
} |
- ary.push(currentDirUrl + encodeURI(entry.name)); |
+ ary.push(currentDirUrl + this.encodeFileName_(entry.name)); |
} |
// Multi-file selection has no other restrictions. |
@@ -2112,7 +2150,8 @@ FileManager.prototype = { |
throw new Error('Selected entry is not a file!'); |
} |
- chrome.fileBrowserPrivate.selectFile(ary[0], 0); |
+ chrome.fileBrowserPrivate.selectFile( |
+ ary[0], this.getSelectedFilterIndex_(ary[0])); |
window.close(); |
}; |