Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * DefaultActionDialog contains a message, a list box, an ok button, and a | 9 * DefaultActionDialog contains a message, a list box, an ok button, and a |
| 10 * cancel button. | 10 * cancel button. |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 86 return result; | 86 return result; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 /** | 89 /** |
| 90 * Shows dialog. | 90 * Shows dialog. |
| 91 * | 91 * |
| 92 * @param {string} title Title in dialog caption. | 92 * @param {string} title Title in dialog caption. |
| 93 * @param {string} message Message in dialog caption. | 93 * @param {string} message Message in dialog caption. |
| 94 * @param {Array.<Object>} items Items to render in the list. | 94 * @param {Array.<Object>} items Items to render in the list. |
| 95 * @param {number} defaultIndex Item to select by default. | 95 * @param {number} defaultIndex Item to select by default. |
| 96 * @param {function(Object=)} opt_onOk OK callback with the selected item. | 96 * @param {function(Object=)} onSelected Callback with the selected item. |
|
hirono
2013/12/09 06:30:16
An argument of the callback function seems not to
yoshiki
2013/12/12 13:22:25
Done.
| |
| 97 * @param {function()=} opt_onCancel Cancel callback. | 97 * @param {function()=} opt_onCancel Cancel callback with no selected item. |
| 98 */ | 98 */ |
| 99 DefaultActionDialog.prototype.show = function(title, message, items, | 99 DefaultActionDialog.prototype.show = function(title, message, items, |
|
hirono
2013/12/09 06:30:16
Could you move the file into the js/ui directory?
yoshiki
2013/12/12 13:22:25
I think so, but there are some other files which s
| |
| 100 defaultIndex, opt_onOk, opt_onCancel) { | 100 defaultIndex, onSelectedItem, opt_onCancel) { |
| 101 | 101 |
| 102 var show = FileManagerDialogBase.prototype.showOkCancelDialog.call( | 102 this.onSelectedItemCallback_ = onSelectedItem; |
| 103 this, title, message, opt_onOk, opt_onCancel); | 103 this.onCancelledCallback_ = opt_onCancel || function() {}; |
| 104 | |
| 105 var show = FileManagerDialogBase.prototype.showTitleAndTextDialog.call( | |
| 106 this, title, message); | |
| 104 | 107 |
| 105 if (!show) { | 108 if (!show) { |
| 106 console.error('DefaultActionDialog can\'t be shown.'); | 109 console.error('DefaultActionDialog can\'t be shown.'); |
| 107 return; | 110 return; |
| 108 } | 111 } |
| 109 | 112 |
| 110 if (!message) { | 113 if (!message) { |
| 111 this.text_.setAttribute('hidden', 'hidden'); | 114 this.text_.setAttribute('hidden', 'hidden'); |
| 112 } else { | 115 } else { |
| 113 this.text_.removeAttribute('hidden'); | 116 this.text_.removeAttribute('hidden'); |
| 114 } | 117 } |
| 115 | 118 |
| 116 this.list_.startBatchUpdates(); | 119 this.list_.startBatchUpdates(); |
| 117 this.dataModel_.splice(0, this.dataModel_.length); | 120 this.dataModel_.splice(0, this.dataModel_.length); |
| 118 for (var i = 0; i < items.length; i++) { | 121 for (var i = 0; i < items.length; i++) { |
| 119 this.dataModel_.push(items[i]); | 122 this.dataModel_.push(items[i]); |
| 120 } | 123 } |
| 121 this.selectionModel_.selectedIndex = defaultIndex; | 124 this.selectionModel_.selectedIndex = defaultIndex; |
| 122 this.list_.endBatchUpdates(); | 125 this.list_.endBatchUpdates(); |
| 123 }; | 126 }; |
| 124 | 127 |
| 125 /** | 128 /** |
| 126 * List activation handler. Closes dialog and calls 'ok' callback. | 129 * List activation handler. Closes dialog and calls 'ok' callback. |
| 127 * @param {number} index Activated index. | 130 * @param {number} index Activated index. |
| 128 */ | 131 */ |
| 129 DefaultActionDialog.prototype.activateItemAtIndex_ = function(index) { | 132 DefaultActionDialog.prototype.activateItemAtIndex_ = function(index) { |
| 130 this.hide(); | 133 this.hide(); |
| 131 this.onOk_(this.dataModel_.item(index)); | 134 this.onSelectedItemCallback_(this.dataModel_.item(index)); |
| 132 }; | 135 }; |
| 133 | 136 |
| 134 /** | 137 /** |
| 135 * Closes dialog and invokes callback with currently-selected item. | 138 * Closes dialog and invokes callback with currently-selected item. |
| 136 * @override | 139 * @override |
|
hirono
2013/12/09 06:30:16
This is no longer override method.
yoshiki
2013/12/12 13:22:25
Done.
| |
| 137 */ | 140 */ |
| 138 DefaultActionDialog.prototype.onOkClick_ = function() { | 141 DefaultActionDialog.prototype.onSelected_ = function() { |
| 139 this.activateItemAtIndex_(this.selectionModel_.selectedIndex); | 142 this.activateItemAtIndex_(this.selectionModel_.selectedIndex); |
| 140 }; | 143 }; |
| 141 | 144 |
| 142 /** | 145 /** |
| 143 * @override | 146 * @override |
| 144 */ | 147 */ |
| 145 DefaultActionDialog.prototype.onContainerKeyDown_ = function(event) { | 148 DefaultActionDialog.prototype.onContainerKeyDown_ = function(event) { |
| 146 // Handle Escape. | 149 // Handle Escape. |
| 147 if (event.keyCode == 27) { | 150 if (event.keyCode == 27) { |
| 148 this.onCancelClick_(event); | 151 this.hide(); |
| 149 event.preventDefault(); | 152 event.preventDefault(); |
| 150 } else if (event.keyCode == 32 || event.keyCode == 13) { | 153 } else if (event.keyCode == 32 || event.keyCode == 13) { |
| 151 this.onOkClick_(); | 154 this.onSelected_(); |
|
hirono
2013/12/09 06:30:16
According to the comments of crbug.com/222941, cli
yoshiki
2013/12/12 13:22:25
Done.
| |
| 152 event.preventDefault(); | 155 event.preventDefault(); |
| 153 } | 156 } |
| 154 }; | 157 }; |
| 155 | 158 |
| 156 return {DefaultActionDialog: DefaultActionDialog}; | 159 return {DefaultActionDialog: DefaultActionDialog}; |
| 157 }); | 160 }); |
| OLD | NEW |