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

Side by Side Diff: chrome/browser/resources/file_manager/js/volume_list.js

Issue 22167002: Cleanup: Remove unnecessary property: VolumeList.currentVolume_ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comment Created 7 years, 4 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
« 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * A volume list model. This model combines the 2 lists. 8 * A volume list model. This model combines the 2 lists.
9 * @param {cr.ui.ArrayDataModel} volumesList The first list of the model. 9 * @param {cr.ui.ArrayDataModel} volumesList The first list of the model.
10 * @param {cr.ui.ArrayDataModel} pinnedList The second list of the model. 10 * @param {cr.ui.ArrayDataModel} pinnedList The second list of the model.
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 this.directoryModel_ = directoryModel; 179 this.directoryModel_ = directoryModel;
180 this.volumeManager_ = VolumeManager.getInstance(); 180 this.volumeManager_ = VolumeManager.getInstance();
181 this.selectionModel = new cr.ui.ListSingleSelectionModel(); 181 this.selectionModel = new cr.ui.ListSingleSelectionModel();
182 182
183 this.directoryModel_.addEventListener('directory-changed', 183 this.directoryModel_.addEventListener('directory-changed',
184 this.onCurrentDirectoryChanged_.bind(this)); 184 this.onCurrentDirectoryChanged_.bind(this));
185 this.selectionModel.addEventListener( 185 this.selectionModel.addEventListener(
186 'change', this.onSelectionChange_.bind(this)); 186 'change', this.onSelectionChange_.bind(this));
187 this.selectionModel.addEventListener( 187 this.selectionModel.addEventListener(
188 'beforeChange', this.onBeforeSelectionChange_.bind(this)); 188 'beforeChange', this.onBeforeSelectionChange_.bind(this));
189 this.currentVolume_ = null;
190
191 189
192 this.scrollBar_ = new ScrollBar(); 190 this.scrollBar_ = new ScrollBar();
193 this.scrollBar_.initialize(this.parentNode, this); 191 this.scrollBar_.initialize(this.parentNode, this);
194 192
195 // Overriding default role 'list' set by cr.ui.List.decorate() to 'listbox' 193 // Overriding default role 'list' set by cr.ui.List.decorate() to 'listbox'
196 // role for better accessibility on ChromeOS. 194 // role for better accessibility on ChromeOS.
197 this.setAttribute('role', 'listbox'); 195 this.setAttribute('role', 'listbox');
198 196
199 var self = this; 197 var self = this;
200 this.itemConstructor = function(path) { 198 this.itemConstructor = function(path) {
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 /** 305 /**
308 * Selects the n-th volume from the list. 306 * Selects the n-th volume from the list.
309 * @param {number} index Volume index. 307 * @param {number} index Volume index.
310 * @return {boolean} True for success, otherwise false. 308 * @return {boolean} True for success, otherwise false.
311 */ 309 */
312 VolumeList.prototype.selectByIndex = function(index) { 310 VolumeList.prototype.selectByIndex = function(index) {
313 if (index < 0 || index > this.dataModel.length - 1) 311 if (index < 0 || index > this.dataModel.length - 1)
314 return false; 312 return false;
315 313
316 var newPath = this.dataModel.item(index); 314 var newPath = this.dataModel.item(index);
317 if (!newPath || this.currentVolume_ == newPath) 315 if (!newPath)
318 return false; 316 return false;
319 317
320 this.currentVolume_ = newPath; 318 // Prevents double-moving to the current directory.
mtomasz 2013/08/06 03:46:20 The problem here is that it won't work when being
mtomasz 2013/08/06 03:48:35 Sorry, I misunderstood this method. Please ignore
321 this.directoryModel_.changeDirectory(this.currentVolume_); 319 if (this.directoryModel_.getCurrentDirEntry().fullPath == newPath)
320 return false;
321
322 this.directoryModel_.changeDirectory(newPath);
322 return true; 323 return true;
323 }; 324 };
324 325
325 /** 326 /**
326 * Handler before root item change. 327 * Handler before root item change.
327 * @param {Event} event The event. 328 * @param {Event} event The event.
328 * @private 329 * @private
329 */ 330 */
330 VolumeList.prototype.onBeforeSelectionChange_ = function(event) { 331 VolumeList.prototype.onBeforeSelectionChange_ = function(event) {
331 if (event.changes.length == 1 && !event.changes[0].selected) 332 if (event.changes.length == 1 && !event.changes[0].selected)
(...skipping 16 matching lines...) Expand all
348 349
349 /** 350 /**
350 * Invoked when the current directory is changed. 351 * Invoked when the current directory is changed.
351 * @param {Event} event The event. 352 * @param {Event} event The event.
352 * @private 353 * @private
353 */ 354 */
354 VolumeList.prototype.onCurrentDirectoryChanged_ = function(event) { 355 VolumeList.prototype.onCurrentDirectoryChanged_ = function(event) {
355 var path = event.newDirEntry.fullPath || this.dataModel.getCurrentDirPath(); 356 var path = event.newDirEntry.fullPath || this.dataModel.getCurrentDirPath();
356 var newRootPath = PathUtil.getRootPath(path); 357 var newRootPath = PathUtil.getRootPath(path);
357 358
358 // Sets |this.currentVolume_| in advance to prevent |onSelectionChange_()|
359 // from calling |DirectoryModel.ChangeDirectory()| again.
360 this.currentVolume_ = newRootPath;
361
362 // Synchronizes the volume list selection with the current directory, after 359 // Synchronizes the volume list selection with the current directory, after
363 // it is changed outside of the volume list. 360 // it is changed outside of the volume list.
364 361
365 // (1) Select the nearest parent directory (including the pinned directories). 362 // (1) Select the nearest parent directory (including the pinned directories).
366 var bestMatchIndex = -1; 363 var bestMatchIndex = -1;
367 var bestMatchSubStringLen = 0; 364 var bestMatchSubStringLen = 0;
368 for (var i = 0; i < this.dataModel.length; i++) { 365 for (var i = 0; i < this.dataModel.length; i++) {
369 var itemPath = this.dataModel.item(i); 366 var itemPath = this.dataModel.item(i);
370 if (path.indexOf(itemPath) == 0) { 367 if (path.indexOf(itemPath) == 0) {
371 if (bestMatchSubStringLen < itemPath.length) { 368 if (bestMatchSubStringLen < itemPath.length) {
(...skipping 15 matching lines...) Expand all
387 var itemPath = this.dataModel.item(i); 384 var itemPath = this.dataModel.item(i);
388 if (PathUtil.getRootPath(itemPath) == newRootPath) { 385 if (PathUtil.getRootPath(itemPath) == newRootPath) {
389 // Not to invoke the handler of this instance, sets the guard. 386 // Not to invoke the handler of this instance, sets the guard.
390 this.dontHandleSelectionEvent_ = true; 387 this.dontHandleSelectionEvent_ = true;
391 this.selectionModel.selectedIndex = i; 388 this.selectionModel.selectedIndex = i;
392 this.dontHandleSelectionEvent_ = false; 389 this.dontHandleSelectionEvent_ = false;
393 return; 390 return;
394 } 391 }
395 } 392 }
396 }; 393 };
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