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

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

Issue 1617243004: Stop checking for null selectionModel field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove unneeded code Created 4 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 cr.define('options', function() { 5 cr.define('options', function() {
6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel; 6 /** @const */ var ArrayDataModel = cr.ui.ArrayDataModel;
7 /** @const */ var DeletableItem = options.DeletableItem; 7 /** @const */ var DeletableItem = options.DeletableItem;
8 /** @const */ var DeletableItemList = options.DeletableItemList; 8 /** @const */ var DeletableItemList = options.DeletableItemList;
9 /** @const */ var List = cr.ui.List; 9 /** @const */ var List = cr.ui.List;
10 /** @const */ var ListItem = cr.ui.ListItem; 10 /** @const */ var ListItem = cr.ui.ListItem;
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 this.load_(languageCodes); 382 this.load_(languageCodes);
383 }, 383 },
384 384
385 /** 385 /**
386 * Loads given language list. 386 * Loads given language list.
387 * @param {!Array} languageCodes List of language codes. 387 * @param {!Array} languageCodes List of language codes.
388 * @private 388 * @private
389 */ 389 */
390 load_: function(languageCodes) { 390 load_: function(languageCodes) {
391 // Preserve the original selected index. See comments below. 391 // Preserve the original selected index. See comments below.
392 var originalSelectedIndex = (this.selectionModel ? 392 var originalSelectedIndex = this.selectionModel.selectedIndex;
393 this.selectionModel.selectedIndex : -1);
394 this.dataModel = new ArrayDataModel(languageCodes); 393 this.dataModel = new ArrayDataModel(languageCodes);
395 if (originalSelectedIndex >= 0 && 394 if (originalSelectedIndex >= 0 &&
396 originalSelectedIndex < this.dataModel.length) { 395 originalSelectedIndex < this.dataModel.length) {
397 // Restore the original selected index if the selected index is 396 // Restore the original selected index if the selected index is
398 // valid after the data model is loaded. This is neeeded to keep 397 // valid after the data model is loaded. This is needed to keep
399 // the selected language after the languge is added or removed. 398 // the selected language after the languge is added or removed.
400 this.selectionModel.selectedIndex = originalSelectedIndex; 399 this.selectionModel.selectedIndex = originalSelectedIndex;
401 // The lead index should be updated too. 400 // The lead index should be updated too.
402 this.selectionModel.leadIndex = originalSelectedIndex; 401 this.selectionModel.leadIndex = originalSelectedIndex;
403 } else if (this.dataModel.length > 0) {
404 // Otherwise, select the first item if it's not empty.
405 // Note that ListSingleSelectionModel won't select an item
406 // automatically, hence we manually select the first item here.
407 this.selectionModel.selectedIndex = 0;
Dan Beam 2016/02/09 19:14:47 why are you removing this?
Kevin Bailey 2016/02/09 22:19:07 Sorry, left-over from a misunderstanding. Restored
408 } 402 }
409 }, 403 },
410 404
411 /** 405 /**
412 * Saves the preference. 406 * Saves the preference.
413 */ 407 */
414 savePreference_: function() { 408 savePreference_: function() {
415 chrome.send('updateLanguageList', [this.dataModel.slice()]); 409 chrome.send('updateLanguageList', [this.dataModel.slice()]);
416 cr.dispatchSimpleEvent(this, 'save'); 410 cr.dispatchSimpleEvent(this, 'save');
417 }, 411 },
(...skipping 18 matching lines...) Expand all
436 } 430 }
437 return filteredLanguageCodes; 431 return filteredLanguageCodes;
438 }, 432 },
439 }; 433 };
440 434
441 return { 435 return {
442 LanguageList: LanguageList, 436 LanguageList: LanguageList,
443 LanguageListItem: LanguageListItem 437 LanguageListItem: LanguageListItem
444 }; 438 };
445 }); 439 });
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698