Chromium Code Reviews| Index: chrome/browser/resources/file_manager/foreground/js/default_action_dialog.js |
| diff --git a/chrome/browser/resources/file_manager/foreground/js/default_action_dialog.js b/chrome/browser/resources/file_manager/foreground/js/default_action_dialog.js |
| index a5c8290a2397b3b6b0097df240bb7167a14787e0..6179165097c772cea214584d88ab73d89e1660b2 100644 |
| --- a/chrome/browser/resources/file_manager/foreground/js/default_action_dialog.js |
| +++ b/chrome/browser/resources/file_manager/foreground/js/default_action_dialog.js |
| @@ -36,6 +36,8 @@ cr.define('cr.filebrowser', function() { |
| // but doesn't exceed predefined size. |
| this.list_.autoExpands = true; |
| this.list_.activateItemAtIndex = this.activateItemAtIndex_.bind(this); |
| + this.selectionModel_.addEventListener( |
| + t'change', this.onSelected_.bind(this)); |
|
hirono
2013/12/13 03:31:09
nit: remove t.
|
| this.initialFocusElement_ = this.list_; |
| @@ -93,14 +95,17 @@ cr.define('cr.filebrowser', function() { |
| * @param {string} message Message in dialog caption. |
| * @param {Array.<Object>} items Items to render in the list. |
| * @param {number} defaultIndex Item to select by default. |
| - * @param {function(Object=)} opt_onOk OK callback with the selected item. |
| - * @param {function()=} opt_onCancel Cancel callback. |
| + * @param {function(Object)} onSelected Callback with the selected item. |
| + * @param {function()=} opt_onCancel Cancel callback with no selected item. |
| */ |
| DefaultActionDialog.prototype.show = function(title, message, items, |
| - defaultIndex, opt_onOk, opt_onCancel) { |
| + defaultIndex, onSelectedItem, opt_onCancel) { |
| - var show = FileManagerDialogBase.prototype.showOkCancelDialog.call( |
| - this, title, message, opt_onOk, opt_onCancel); |
| + this.onSelectedItemCallback_ = onSelectedItem; |
| + this.onCancelledCallback_ = opt_onCancel || function() {}; |
| + |
| + var show = FileManagerDialogBase.prototype.showTitleAndTextDialog.call( |
| + this, title, message); |
| if (!show) { |
| console.error('DefaultActionDialog can\'t be shown.'); |
| @@ -128,15 +133,15 @@ cr.define('cr.filebrowser', function() { |
| */ |
| DefaultActionDialog.prototype.activateItemAtIndex_ = function(index) { |
| this.hide(); |
| - this.onOk_(this.dataModel_.item(index)); |
| + this.onSelectedItemCallback_(this.dataModel_.item(index)); |
| }; |
| /** |
| * Closes dialog and invokes callback with currently-selected item. |
| - * @override |
| */ |
| - DefaultActionDialog.prototype.onOkClick_ = function() { |
| - this.activateItemAtIndex_(this.selectionModel_.selectedIndex); |
| + DefaultActionDialog.prototype.onSelected_ = function() { |
| + if (this.selectionModel_.selectedIndex !== -1) |
| + this.activateItemAtIndex_(this.selectionModel_.selectedIndex); |
| }; |
| /** |
| @@ -145,10 +150,10 @@ cr.define('cr.filebrowser', function() { |
| DefaultActionDialog.prototype.onContainerKeyDown_ = function(event) { |
| // Handle Escape. |
| if (event.keyCode == 27) { |
| - this.onCancelClick_(event); |
| + this.hide(); |
| event.preventDefault(); |
| } else if (event.keyCode == 32 || event.keyCode == 13) { |
| - this.onOkClick_(); |
| + this.onSelected_(); |
| event.preventDefault(); |
| } |
| }; |