| 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 * A navigation list model. This model combines the 2 lists. | 8 * A navigation 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 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 * @param {string} path Path of the directory to be rendered. | 306 * @param {string} path Path of the directory to be rendered. |
| 307 * @return {NavigationListItem} Rendered element. | 307 * @return {NavigationListItem} Rendered element. |
| 308 * @private | 308 * @private |
| 309 */ | 309 */ |
| 310 NavigationList.prototype.renderRoot_ = function(path) { | 310 NavigationList.prototype.renderRoot_ = function(path) { |
| 311 var item = new NavigationListItem(); | 311 var item = new NavigationListItem(); |
| 312 item.setPath(path); | 312 item.setPath(path); |
| 313 | 313 |
| 314 var handleClick = function() { | 314 var handleClick = function() { |
| 315 if (item.selected && path !== this.directoryModel_.getCurrentDirPath()) { | 315 if (item.selected && path !== this.directoryModel_.getCurrentDirPath()) { |
| 316 metrics.recordUserAction('FolderShortcut.Navigate'); |
| 316 this.directoryModel_.changeDirectory(path); | 317 this.directoryModel_.changeDirectory(path); |
| 317 } | 318 } |
| 318 }.bind(this); | 319 }.bind(this); |
| 319 item.addEventListener('click', handleClick); | 320 item.addEventListener('click', handleClick); |
| 320 | 321 |
| 321 var handleEject = function() { | 322 var handleEject = function() { |
| 322 var unmountCommand = cr.doc.querySelector('command#unmount'); | 323 var unmountCommand = cr.doc.querySelector('command#unmount'); |
| 323 // Let's make sure 'canExecute' state of the command is properly set for | 324 // Let's make sure 'canExecute' state of the command is properly set for |
| 324 // the root before executing it. | 325 // the root before executing it. |
| 325 unmountCommand.canExecuteChange(item); | 326 unmountCommand.canExecuteChange(item); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 342 NavigationList.prototype.setContextMenu = function(menu) { | 343 NavigationList.prototype.setContextMenu = function(menu) { |
| 343 this.contextMenu_ = menu; | 344 this.contextMenu_ = menu; |
| 344 | 345 |
| 345 for (var i = 0; i < this.dataModel.length; i++) { | 346 for (var i = 0; i < this.dataModel.length; i++) { |
| 346 this.getListItemByIndex(i).maybeSetContextMenu(this.contextMenu_); | 347 this.getListItemByIndex(i).maybeSetContextMenu(this.contextMenu_); |
| 347 } | 348 } |
| 348 }; | 349 }; |
| 349 | 350 |
| 350 /** | 351 /** |
| 351 * Selects the n-th item from the list. | 352 * Selects the n-th item from the list. |
| 353 * |
| 352 * @param {number} index Item index. | 354 * @param {number} index Item index. |
| 353 * @return {boolean} True for success, otherwise false. | 355 * @return {boolean} True for success, otherwise false. |
| 354 */ | 356 */ |
| 355 NavigationList.prototype.selectByIndex = function(index) { | 357 NavigationList.prototype.selectByIndex = function(index) { |
| 356 if (index < 0 || index > this.dataModel.length - 1) | 358 if (index < 0 || index > this.dataModel.length - 1) |
| 357 return false; | 359 return false; |
| 358 | 360 |
| 359 var newPath = this.dataModel.item(index); | 361 var newPath = this.dataModel.item(index); |
| 360 if (!newPath) | 362 if (!newPath) |
| 361 return false; | 363 return false; |
| 362 | 364 |
| 363 // Prevents double-moving to the current directory. | 365 // Prevents double-moving to the current directory. |
| 366 // eg. When user clicks the item, changing directory has already been done in |
| 367 // click handler. |
| 364 if (this.directoryModel_.getCurrentDirEntry().fullPath == newPath) | 368 if (this.directoryModel_.getCurrentDirEntry().fullPath == newPath) |
| 365 return false; | 369 return false; |
| 366 | 370 |
| 371 metrics.recordUserAction('FolderShortcut.Navigate'); |
| 367 this.directoryModel_.changeDirectory(newPath); | 372 this.directoryModel_.changeDirectory(newPath); |
| 368 return true; | 373 return true; |
| 369 }; | 374 }; |
| 370 | 375 |
| 371 /** | 376 /** |
| 372 * Handler before root item change. | 377 * Handler before root item change. |
| 373 * @param {Event} event The event. | 378 * @param {Event} event The event. |
| 374 * @private | 379 * @private |
| 375 */ | 380 */ |
| 376 NavigationList.prototype.onBeforeSelectionChange_ = function(event) { | 381 NavigationList.prototype.onBeforeSelectionChange_ = function(event) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 var itemPath = this.dataModel.item(i); | 452 var itemPath = this.dataModel.item(i); |
| 448 if (PathUtil.getRootPath(itemPath) == newRootPath) { | 453 if (PathUtil.getRootPath(itemPath) == newRootPath) { |
| 449 // Not to invoke the handler of this instance, sets the guard. | 454 // Not to invoke the handler of this instance, sets the guard. |
| 450 this.dontHandleSelectionEvent_ = true; | 455 this.dontHandleSelectionEvent_ = true; |
| 451 this.selectionModel.selectedIndex = i; | 456 this.selectionModel.selectedIndex = i; |
| 452 this.dontHandleSelectionEvent_ = false; | 457 this.dontHandleSelectionEvent_ = false; |
| 453 return; | 458 return; |
| 454 } | 459 } |
| 455 } | 460 } |
| 456 }; | 461 }; |
| OLD | NEW |