Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/resources/options/search_engine_manager.js

Issue 6352004: DOMUI Prefs: Add inline buttons for setting the default search engine (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 14 matching lines...) Expand all
25 list_: null, 25 list_: null,
26 26
27 initializePage: function() { 27 initializePage: function() {
28 OptionsPage.prototype.initializePage.call(this); 28 OptionsPage.prototype.initializePage.call(this);
29 29
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
36 selectionModel.addEventListener('change',
37 this.selectionChanged_.bind(this));
38
39 var self = this;
40 // This is a temporary hack to allow the "Make Default" button to
41 // continue working despite the new list behavior of removing selection
42 // on focus loss.
43 // Once drag-and-drop is supported, so items can be moved into the default
44 // section, this button will go away entirely.
45 $('makeDefaultSearchEngineButton').onmousedown = function(event) {
46 self.pendingDefaultEngine_ = self.list_.selectedItem;
47 };
48 $('makeDefaultSearchEngineButton').onclick = function(event) {
49 chrome.send('managerSetDefaultSearchEngine',
50 [self.pendingDefaultEngine_['modelIndex']]);
51 self.pendingDefaultEngine_ = null;
52 };
53 }, 35 },
54 36
55 /** 37 /**
56 * Updates the search engine list with the given entries. 38 * Updates the search engine list with the given entries.
57 * @private 39 * @private
58 * @param {Array} engineList List of available search engines. 40 * @param {Array} engineList List of available search engines.
59 */ 41 */
60 updateSearchEngineList_: function(engineList) { 42 updateSearchEngineList_: function(engineList) {
61 var model = new ArrayDataModel(engineList); 43 var model = new ArrayDataModel(engineList);
62 model.push({ 44 model.push({
63 'modelIndex': '-1' 45 'modelIndex': '-1'
64 }); 46 });
65 this.list_.dataModel = model; 47 this.list_.dataModel = model;
66 }, 48 },
67
68 /**
69 * Callback from the selection model when the selection changes.
70 * @private
71 * @param {!cr.Event} e Event with change info.
72 */
73 selectionChanged_: function(e) {
74 var engine = this.list_.selectedItem || this.pendingDefaultEngine_;
75 $('makeDefaultSearchEngineButton').disabled =
76 !(engine && engine['canBeDefault']);
77 },
78 }; 49 };
79 50
80 SearchEngineManager.updateSearchEngineList = function(engineList) { 51 SearchEngineManager.updateSearchEngineList = function(engineList) {
81 SearchEngineManager.getInstance().updateSearchEngineList_(engineList); 52 SearchEngineManager.getInstance().updateSearchEngineList_(engineList);
82 }; 53 };
83 54
84 SearchEngineManager.validityCheckCallback = function(validity, modelIndex) { 55 SearchEngineManager.validityCheckCallback = function(validity, modelIndex) {
85 SearchEngineManager.getInstance().list_.validationComplete(validity, 56 SearchEngineManager.getInstance().list_.validationComplete(validity,
86 modelIndex); 57 modelIndex);
87 }; 58 };
88 59
89 // Export 60 // Export
90 return { 61 return {
91 SearchEngineManager: SearchEngineManager 62 SearchEngineManager: SearchEngineManager
92 }; 63 };
93 64
94 }); 65 });
95 66
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698