diff options
author | rginda@chromium.org <rginda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 18:24:16 +0000 |
---|---|---|
committer | rginda@chromium.org <rginda@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-06 18:24:16 +0000 |
commit | 0bae436a5250ce7494ccd07ddd75d4bc1a6559c8 (patch) | |
tree | 873d702666ef42f511af1c0f22274bdc6f1f210c | |
parent | 70503b2e6a0c8adce71d7e18c726e7f3f7c9b0c1 (diff) | |
download | chromium_src-0bae436a5250ce7494ccd07ddd75d4bc1a6559c8.zip chromium_src-0bae436a5250ce7494ccd07ddd75d4bc1a6559c8.tar.gz chromium_src-0bae436a5250ce7494ccd07ddd75d4bc1a6559c8.tar.bz2 |
implement dialog-type logic
These changes make the file manager pay proper attention to the type of dialog requested.
BUG=chromium-os:13843
TEST=manual testing using harness.html and js console output.
Review URL: http://codereview.chromium.org/6693079
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80661 0039d316-1c4b-4281-b951-d872f2087c98
9 files changed, 129 insertions, 23 deletions
diff --git a/chrome/browser/resources/file_manager/css/file_manager.css b/chrome/browser/resources/file_manager/css/file_manager.css index 4b89896..cacdce2 100644 --- a/chrome/browser/resources/file_manager/css/file_manager.css +++ b/chrome/browser/resources/file_manager/css/file_manager.css @@ -10,8 +10,6 @@ body { -webkit-box-orient: vertical; -webkit-user-select: none; display: -webkit-box; - font-family: sans-serif; - font-size: 13px; height: 100%; margin: 0; padding: 0; @@ -211,6 +209,21 @@ body { white-space: nowrap; } +.filename-label { + -webkit-box-orient: horizontal; + color: #666; + display: -webkit-box; + font-weight: bold; + padding-top: 4px; + padding-right: 4px; +} + +.filename-input { + -webkit-box-orient: horizontal; + -webkit-box-flex: 1; + display: -webkit-box; +} + /* A horizontal spring. */ .horizontal-spacer { -webkit-box-orient: horizontal; diff --git a/chrome/browser/resources/file_manager/harness.html b/chrome/browser/resources/file_manager/harness.html index a42758b..c462d3b 100644 --- a/chrome/browser/resources/file_manager/harness.html +++ b/chrome/browser/resources/file_manager/harness.html @@ -36,8 +36,12 @@ <script src='js/harness.js'></script> </head> <body> + [ <a href='?{"type":"saveas-file"}'>Save File</a> | + <a href='?{"type":"open-file"}'>Open File</a> | + <a href='?{"type":"open-multi-file"}'>Open Files</a> | + <a href='?{"type":"folder"}'>Select Folder</a> ] <div id=screen> - <iframe id=dialog src='main.html'></iframe> + <iframe id=dialog></iframe> </div> <div> <button onclick='harness.onClearClick(event)'>Reset Filesystem</button> diff --git a/chrome/browser/resources/file_manager/js/file_manager.js b/chrome/browser/resources/file_manager/js/file_manager.js index 470e66c..a6a2ad4 100644 --- a/chrome/browser/resources/file_manager/js/file_manager.js +++ b/chrome/browser/resources/file_manager/js/file_manager.js @@ -281,14 +281,26 @@ FileManager.prototype = { this.previewImage_ = this.dialogDom_.querySelector('.preview-img'); this.previewFilename_ = this.dialogDom_.querySelector('.preview-filename'); this.previewSummary_ = this.dialogDom_.querySelector('.preview-summary'); + this.filenameInput_ = this.dialogDom_.querySelector('.filename-input'); this.okButton_ = this.dialogDom_.querySelector('.ok'); this.cancelButton_ = this.dialogDom_.querySelector('.cancel'); + if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { + this.filenameInput_.addEventListener( + 'keyup', this.onFilenameInputKeyUp_.bind(this)); + this.filenameInput_.addEventListener( + 'focus', this.onFilenameInputFocus_.bind(this)); + } else { + var label = this.dialogDom_.querySelector('.filename-label'); + label.style.visibility = 'hidden'; + this.filenameInput_.style.visibility = 'hidden'; + } + this.okButton_.addEventListener('click', this.onOk_.bind(this)); this.cancelButton_.addEventListener('click', this.onCancel_.bind(this)); - this.dialogDom_.querySelector('.preview-label').textContent = - str('PREVIEW_COLUMN_LABEL'); + // Populate the static localized strings. + i18nTemplate.process(this.document_, localStrings.templateData); // Set up the detail table. var dataModel = new cr.ui.table.TableDataModel([]); @@ -312,6 +324,10 @@ FileManager.prototype = { this.table.dataModel = dataModel; this.table.columnModel = new cr.ui.table.TableColumnModel(columns); + if (this.dialogType_ != FileManager.DialogType.SELECT_OPEN_MULTI_FILE) { + this.table.selectionModel = new cr.ui.table.TableSingleSelectionModel(); + } + this.table.addEventListener( 'dblclick', this.onDetailDoubleClick_.bind(this)); this.table.selectionModel.addEventListener( @@ -325,7 +341,6 @@ FileManager.prototype = { FileManager.prototype.initDialogType_ = function() { var defaultTitle; var okLabel = str('OPEN_LABEL'); - var cancelLabel = str('CANCEL_LABEL'); switch (this.dialogType_) { case FileManager.DialogType.SELECT_FOLDER: @@ -350,7 +365,6 @@ FileManager.prototype = { } this.okButton_.textContent = okLabel; - this.cancelButton_.textContent = cancelLabel; dialogTitle = this.params_.title || defaultTitle; this.dialogDom_.querySelector('.dialog-title').textContent = dialogTitle; @@ -688,8 +702,9 @@ FileManager.prototype = { selectable = (this.selection.directoryCount == 0 && this.selection.fileCount >= 1); } else if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { - // TODO(rginda): save-as logic. - selectable = false; + selectable = this.selection.leadEntry && this.selection.leadEntry.isFile; + if (selectable) + this.filenameInput_.value = this.selection.leadEntry.name; } else { throw new Error('Unknown dialog type'); } @@ -744,6 +759,27 @@ FileManager.prototype = { reader.readEntries(onReadSome); }; + FileManager.prototype.onFilenameInputKeyUp_ = function(event) { + this.okButton_.disabled = this.filenameInput_.value.length == 0; + }; + + FileManager.prototype.onFilenameInputFocus_ = function(event) { + var input = this.filenameInput_; + + // On focus we want to select everything but the extension, but + // Chrome will select-all after the focus event completes. We + // schedule a timeout to alter the focus after that happens. + setTimeout(function() { + var selectionEnd = input.value.lastIndexOf('.'); + if (selectionEnd == -1) { + input.select(); + } else { + input.selectionStart = 0; + input.selectionEnd = selectionEnd; + } + }, 0); + }; + /** * Handle a click of the cancel button. * @@ -762,10 +798,26 @@ FileManager.prototype = { * @param {Event} event The click event. */ FileManager.prototype.onOk_ = function(event) { + if (this.dialogType_ == FileManager.DialogType.SELECT_SAVEAS_FILE) { + // Save-as doesn't require a valid selection from the list, since + // we're going to take the filename from the text input. + var filename = this.filenameInput_.value; + if (!filename) + throw new Error('Missing filename!'); + + chrome.fileBrowserPrivate.selectFile(this.currentDirEntry_.fullPath + + '/' + filename, 0); + return; + } + var ary = []; var selectedIndexes = this.table.selectionModel.selectedIndexes; + + // All other dialog types require at least one selected list item. + // The logic to control whether or not the ok button is enabled should + // prevent us from ever getting here, but we sanity check to be sure. if (!selectedIndexes.length) - return; + throw new Error('Nothing selected!'); for (var i = 0; i < selectedIndexes.length; i++) { var entry = this.table.dataModel.item(selectedIndexes[i]); @@ -774,10 +826,28 @@ FileManager.prototype = { continue; } - ary.push(entry); + ary.push(entry.fullPath); + } + + // Multi-file selection has no other restrictions. + if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILES) { + chrome.fileBrowserPrivate.selectFiles(ary); + return; + } + + // Everything else must have exactly one. + if (ary.length > 1) + throw new Error('Too many files selected!'); + + if (this.dialogType_ == FileManager.DialogType.SELECT_FOLDER) { + if (!this.selection.leadEntry.isDirectory) + throw new Error('Selected entry is not a folder!'); + } else if (this.dialogType_ == FileManager.DialogType.SELECT_OPEN_FILE) { + if (!this.selection.leadEntry.isFile) { + throw new Error('Selected entry is not a file!'); } - chrome.fileBrowserPrivate.selectFiles(ary); + chrome.fileBrowserPrivate.selectFile(ary[0], 0); }; })(); diff --git a/chrome/browser/resources/file_manager/js/harness.js b/chrome/browser/resources/file_manager/js/harness.js index 00c662aa..2bc625c 100644 --- a/chrome/browser/resources/file_manager/js/harness.js +++ b/chrome/browser/resources/file_manager/js/harness.js @@ -23,6 +23,9 @@ var harness = { window.requestFileSystem(window.PERSISTENT, 16 * 1024 * 1024, onFilesystem, util.flog('Error initializing filesystem')); + + var iframe = document.getElementById('dialog'); + iframe.setAttribute('src', 'main.html' + document.location.search); }, /** diff --git a/chrome/browser/resources/file_manager/js/main.js b/chrome/browser/resources/file_manager/js/main.js index cd2f978..3ffa5cc 100644 --- a/chrome/browser/resources/file_manager/js/main.js +++ b/chrome/browser/resources/file_manager/js/main.js @@ -13,12 +13,20 @@ var fileManager; * Called by main.html after the dom has been parsed. */ function init() { + var params; + function onFileSystemFound(filesystem) { FileManager.initStrings(function () { - fileManager = new FileManager(document.body, filesystem); + fileManager = new FileManager(document.body, filesystem, params); }); }; + if (document.location.search) { + var json = decodeURIComponent(document.location.search.substr(1)); + console.log('params: ' + json); + params = JSON.parse(json); + } + util.installFileErrorToString(); chrome.fileBrowserPrivate.requestLocalFileSystem(onFileSystemFound); diff --git a/chrome/browser/resources/file_manager/js/mock_chrome.js b/chrome/browser/resources/file_manager/js/mock_chrome.js index 31cd40b..6060d4a 100644 --- a/chrome/browser/resources/file_manager/js/mock_chrome.js +++ b/chrome/browser/resources/file_manager/js/mock_chrome.js @@ -26,7 +26,6 @@ chrome.fileBrowserPrivate = { selectFiles: function(selectedFiles) { console.log('selectFiles called: ' + selectedFiles.length + ' files selected'); - console.log(selectedFiles); }, /** @@ -34,7 +33,6 @@ chrome.fileBrowserPrivate = { */ selectFile: function(selectedFile, index) { console.log('selectFile called: ' + selectedFile + ', ' + index); - console.log(selectedFile); }, /** @@ -51,11 +49,13 @@ chrome.fileBrowserPrivate = { // Keep this list in sync with the strings in generated_resources.grd and // extension_file_manager_api.cc! callback({ - LOCALE_FMT_DATE_SHORT: '%b %d, %Y', + LOCALE_FMT_DATE_SHORT: '%b %-d, %Y', LOCALE_MONTHS_SHORT: 'Jan^Feb^Mar^Apr^May^Jun^Jul^Aug^Sep^Oct^Nov^Dec', LOCALE_DAYS_SHORT: 'Sun^Mon^Tue^Wed^Thu^Fri^Sat', - SHORT_DATE_FORMAT: '%b %-d, %Y', + BODY_FONT_FAMILY: 'sans-serif', + BODY_FONT_SIZE: '13px', + FILES_DISPLAYED_SUMMARY: '%1 Files Displayed', FILES_SELECTED_SUMMARY: '%1 Files Selected', FILE_IS_DIRECTORY: 'Folder', @@ -67,6 +67,8 @@ chrome.fileBrowserPrivate = { DATE_COLUMN_LABEL: 'Date', PREVIEW_COLUMN_LABEL: 'Preview', + FILENAME_LABEL: 'File Name', + CANCEL_LABEL: 'Cancel', OPEN_LABEL: 'Open', SAVE_LABEL: 'Save', @@ -74,7 +76,7 @@ chrome.fileBrowserPrivate = { SELECT_FOLDER_TITLE: 'Select a folder to open', SELECT_OPEN_FILE_TITLE: 'Select a file to open', SELECT_OPEN_MULTI_FILE_TITLE: 'Select one or more files', - SELECT_SAVEAS_FILE: 'Select a file to save as', + SELECT_SAVEAS_FILE_TITLE: 'Select a file to save as', COMPUTING_SELECTION: 'Computing selection...', NOTHING_SELECTED: 'No files selected', diff --git a/chrome/browser/resources/file_manager/main.html b/chrome/browser/resources/file_manager/main.html index baea97c..25abc42 100644 --- a/chrome/browser/resources/file_manager/main.html +++ b/chrome/browser/resources/file_manager/main.html @@ -14,6 +14,7 @@ var script = ['local_strings.js', + 'i18n_template.js', 'cr.js', 'cr/locale.js', @@ -68,7 +69,8 @@ <script src="js/file_manager.js"></script> <script src="js/main.js"></script> </head> - <body> + <body i18n-values=".style.fontFamily:BODY_FONT_FAMILY; + .style.fontSize:BODY_FONT_SIZE"> <div class=dialog-title>[TITLE]</div> <div class=dialog-header> <div class=breadcrumbs></div> @@ -79,7 +81,8 @@ <div class=preview-container> <div class=table-header style='width:100%'> <div class=table-header-cell> - <div class='preview-label table-header-label'>[PREVIEW]</div> + <div class='preview-label table-header-label' + i18n-content=PREVIEW_COLUMN_LABEL>[PREVIEW]</div> </div> </div> <div class=preview-filename></div> @@ -89,10 +92,11 @@ </div> </div> <div class=dialog-footer> - <!-- TODO(rginda): Text input for file name. --> + <div class=filename-label i18n-content=FILENAME_LABEL>[FILENAME]</div> + <input type=text class=filename-input spellcheck=false> <div class=horizontal-spacer></div> <button class=ok disabled>[OK]</button> - <button class=cancel>[CANCEL]</button> + <button class=cancel i18n-content=CANCEL_LABEL>[CANCEL]</button> </div> <script>init();</script> diff --git a/chrome/browser/resources/shared/js/cr/ui/table/table_single_selection_model.js b/chrome/browser/resources/shared/js/cr/ui/table/table_single_selection_model.js index cc7a51f..181e6b8 100644 --- a/chrome/browser/resources/shared/js/cr/ui/table/table_single_selection_model.js +++ b/chrome/browser/resources/shared/js/cr/ui/table/table_single_selection_model.js @@ -45,7 +45,7 @@ cr.define('cr.ui.table', function() { * @param {number} itemsAdded Number of items added. */ adjust: function(index, itemsRemoved, itemsAdded) { - ListSelectionModel.prototype.adjust.call( + ListSingleSelectionModel.prototype.adjust.call( this, this.length, itemsRemoved, itemsAdded); } }; diff --git a/chrome/browser/resources/shared_resources.grd b/chrome/browser/resources/shared_resources.grd index 53a048f..6ebd623 100644 --- a/chrome/browser/resources/shared_resources.grd +++ b/chrome/browser/resources/shared_resources.grd @@ -40,6 +40,8 @@ without changes to the corresponding grd file. paaaae --> file="shared/js/cr/event_target.js" type="BINDATA" /> <include name="IDR_SHARED_JS_CR_LINK_CONTROLLER" file="shared/js/cr/link_controller.js" type="BINDATA" /> + <include name="IDR_SHARED_JS_CR_LOCALE" + file="shared/js/cr/locale.js" type="BINDATA" /> <include name="IDR_SHARED_JS_CR_PROMISE" file="shared/js/cr/promise.js" type="BINDATA" /> <include name="IDR_SHARED_JS_CR_UI" |