Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 cr.define('options', function() { | 5 cr.define('options', function() { |
| 6 const OptionsPage = options.OptionsPage; | 6 const OptionsPage = options.OptionsPage; |
| 7 const ArrayDataModel = cr.ui.ArrayDataModel; | 7 const ArrayDataModel = cr.ui.ArrayDataModel; |
| 8 const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; | 8 const ListSingleSelectionModel = cr.ui.ListSingleSelectionModel; |
| 9 | 9 |
| 10 /** | 10 /** |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 30 this.list_ = $('searchEngineList') | 30 this.list_ = $('searchEngineList') |
| 31 options.search_engines.SearchEngineList.decorate(this.list_); | 31 options.search_engines.SearchEngineList.decorate(this.list_); |
| 32 var selectionModel = new ListSingleSelectionModel; | 32 var selectionModel = new ListSingleSelectionModel; |
| 33 this.list_.selectionModel = selectionModel; | 33 this.list_.selectionModel = selectionModel; |
| 34 this.list_.autoExpands = true; | 34 this.list_.autoExpands = true; |
| 35 | 35 |
| 36 selectionModel.addEventListener('change', | 36 selectionModel.addEventListener('change', |
| 37 this.selectionChanged_.bind(this)); | 37 this.selectionChanged_.bind(this)); |
| 38 | 38 |
| 39 var self = this; | 39 var self = this; |
| 40 $('addSearchEngineButton').onclick = function(event) { | 40 // This is a temporary hack to allow the "Make Default" button to |
|
arv (Not doing code reviews)
2011/01/11 23:29:29
Why are we removing the selection again?
stuartmorgan
2011/01/12 00:26:51
In the DOMUI pref list model, selection == edit. T
| |
| 41 chrome.send('editSearchEngine', ["-1"]); | 41 // continue working despite the new list behavior of removing selection |
| 42 OptionsPage.showOverlay('editSearchEngineOverlay'); | 42 // on focus loss. |
| 43 }; | 43 // Once drag-and-drop is supported, so items can be moved into the default |
| 44 $('editSearchEngineButton').onclick = function(event) { | 44 // section, this button will go away entirely. |
| 45 chrome.send('editSearchEngine', [self.selectedModelIndex_]); | 45 $('makeDefaultSearchEngineButton').onmousedown = function(event) { |
| 46 OptionsPage.showOverlay('editSearchEngineOverlay'); | 46 self.pendingDefaultEngine_ = self.list_.selectedItem; |
| 47 }; | 47 }; |
| 48 $('makeDefaultSearchEngineButton').onclick = function(event) { | 48 $('makeDefaultSearchEngineButton').onclick = function(event) { |
| 49 chrome.send('managerSetDefaultSearchEngine', | 49 chrome.send('managerSetDefaultSearchEngine', |
| 50 [self.selectedModelIndex_]); | 50 [self.pendingDefaultEngine_['modelIndex']]); |
| 51 self.pendingDefaultEngine_ = null; | |
| 51 }; | 52 }; |
| 52 | |
| 53 // Remove Windows-style accelerators from button labels. | |
| 54 // TODO(stuartmorgan): Remove this once the strings are updated. | |
| 55 $('addSearchEngineButton').textContent = | |
| 56 localStrings.getStringWithoutAccelerator('addSearchEngineButton'); | |
| 57 }, | 53 }, |
| 58 | 54 |
| 59 /** | 55 /** |
| 60 * Updates the search engine list with the given entries. | 56 * Updates the search engine list with the given entries. |
| 61 * @private | 57 * @private |
| 62 * @param {Array} engineList List of available search engines. | 58 * @param {Array} engineList List of available search engines. |
| 63 */ | 59 */ |
| 64 updateSearchEngineList_: function(engineList) { | 60 updateSearchEngineList_: function(engineList) { |
| 65 this.list_.dataModel = new ArrayDataModel(engineList); | 61 var model = new ArrayDataModel(engineList); |
| 62 var placeholder = {}; | |
| 63 placeholder['modelIndex'] = '-1'; | |
|
arv (Not doing code reviews)
2011/01/11 23:29:29
Should this be a number instead of a string?
arv (Not doing code reviews)
2011/01/11 23:29:29
var placeHolder = {
'modelIndex': -1
};
or just
stuartmorgan
2011/01/12 00:26:51
modelIndex only really used as a chrome.send argum
stuartmorgan
2011/01/12 00:26:51
Done.
| |
| 64 model.push(placeholder); | |
| 65 this.list_.dataModel = model; | |
| 66 }, | 66 }, |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Returns the currently selected list item's underlying model index. | |
| 70 * @private | |
| 71 */ | |
| 72 get selectedModelIndex_() { | |
| 73 var listIndex = this.list_.selectionModel.selectedIndex; | |
| 74 return this.list_.dataModel.item(listIndex)['modelIndex']; | |
| 75 }, | |
| 76 | |
| 77 /** | |
| 78 * Callback from the selection model when the selection changes. | 69 * Callback from the selection model when the selection changes. |
| 79 * @private | 70 * @private |
| 80 * @param {!cr.Event} e Event with change info. | 71 * @param {!cr.Event} e Event with change info. |
| 81 */ | 72 */ |
| 82 selectionChanged_: function(e) { | 73 selectionChanged_: function(e) { |
| 83 var selectedIndex = this.list_.selectionModel.selectedIndex; | 74 var engine = this.list_.selectedItem || this.pendingDefaultEngine_; |
| 84 var engine = selectedIndex != -1 ? | |
| 85 this.list_.dataModel.item(selectedIndex) : null; | |
| 86 | |
| 87 $('editSearchEngineButton').disabled = engine == null; | |
| 88 $('makeDefaultSearchEngineButton').disabled = | 75 $('makeDefaultSearchEngineButton').disabled = |
| 89 !(engine && engine['canBeDefault']); | 76 !(engine && engine['canBeDefault']); |
| 90 }, | 77 }, |
| 91 }; | 78 }; |
| 92 | 79 |
| 93 SearchEngineManager.updateSearchEngineList = function(engineList) { | 80 SearchEngineManager.updateSearchEngineList = function(engineList) { |
| 94 SearchEngineManager.getInstance().updateSearchEngineList_(engineList); | 81 SearchEngineManager.getInstance().updateSearchEngineList_(engineList); |
| 95 }; | 82 }; |
| 96 | 83 |
| 84 SearchEngineManager.validityCheckCallback = function(validity, modelIndex) { | |
| 85 SearchEngineManager.getInstance().list_.validationComplete(validity, | |
| 86 modelIndex); | |
| 87 }; | |
| 88 | |
| 97 // Export | 89 // Export |
| 98 return { | 90 return { |
| 99 SearchEngineManager: SearchEngineManager | 91 SearchEngineManager: SearchEngineManager |
| 100 }; | 92 }; |
| 101 | 93 |
| 102 }); | 94 }); |
| 103 | 95 |
| OLD | NEW |