| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 * cr.ui.List internally. | 309 * cr.ui.List internally. |
| 310 * @param {string} path Path of the directory to be rendered. | 310 * @param {string} path Path of the directory to be rendered. |
| 311 * @return {NavigationListItem} Rendered element. | 311 * @return {NavigationListItem} Rendered element. |
| 312 * @private | 312 * @private |
| 313 */ | 313 */ |
| 314 NavigationList.prototype.renderRoot_ = function(path) { | 314 NavigationList.prototype.renderRoot_ = function(path) { |
| 315 var item = new NavigationListItem(); | 315 var item = new NavigationListItem(); |
| 316 item.setPath(path); | 316 item.setPath(path); |
| 317 | 317 |
| 318 var handleClick = function() { | 318 var handleClick = function() { |
| 319 if (item.selected && path !== this.directoryModel_.getCurrentDirPath()) | 319 if (item.selected && path !== this.directoryModel_.getCurrentDirPath()) { |
| 320 metrics.recordUserAction('FolderShortcut.Navigate'); |
| 320 this.changeDirectory_(path); | 321 this.changeDirectory_(path); |
| 322 } |
| 321 }.bind(this); | 323 }.bind(this); |
| 322 item.addEventListener('click', handleClick); | 324 item.addEventListener('click', handleClick); |
| 323 | 325 |
| 324 var handleEject = function() { | 326 var handleEject = function() { |
| 325 var unmountCommand = cr.doc.querySelector('command#unmount'); | 327 var unmountCommand = cr.doc.querySelector('command#unmount'); |
| 326 // Let's make sure 'canExecute' state of the command is properly set for | 328 // Let's make sure 'canExecute' state of the command is properly set for |
| 327 // the root before executing it. | 329 // the root before executing it. |
| 328 unmountCommand.canExecuteChange(item); | 330 unmountCommand.canExecuteChange(item); |
| 329 unmountCommand.execute(item); | 331 unmountCommand.execute(item); |
| 330 }; | 332 }; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 NavigationList.prototype.setContextMenu = function(menu) { | 366 NavigationList.prototype.setContextMenu = function(menu) { |
| 365 this.contextMenu_ = menu; | 367 this.contextMenu_ = menu; |
| 366 | 368 |
| 367 for (var i = 0; i < this.dataModel.length; i++) { | 369 for (var i = 0; i < this.dataModel.length; i++) { |
| 368 this.getListItemByIndex(i).maybeSetContextMenu(this.contextMenu_); | 370 this.getListItemByIndex(i).maybeSetContextMenu(this.contextMenu_); |
| 369 } | 371 } |
| 370 }; | 372 }; |
| 371 | 373 |
| 372 /** | 374 /** |
| 373 * Selects the n-th item from the list. | 375 * Selects the n-th item from the list. |
| 376 * |
| 374 * @param {number} index Item index. | 377 * @param {number} index Item index. |
| 375 * @return {boolean} True for success, otherwise false. | 378 * @return {boolean} True for success, otherwise false. |
| 376 */ | 379 */ |
| 377 NavigationList.prototype.selectByIndex = function(index) { | 380 NavigationList.prototype.selectByIndex = function(index) { |
| 378 if (index < 0 || index > this.dataModel.length - 1) | 381 if (index < 0 || index > this.dataModel.length - 1) |
| 379 return false; | 382 return false; |
| 380 | 383 |
| 381 var newPath = this.dataModel.item(index); | 384 var newPath = this.dataModel.item(index); |
| 382 if (!newPath) | 385 if (!newPath) |
| 383 return false; | 386 return false; |
| 384 | 387 |
| 385 // Prevents double-moving to the current directory. | 388 // Prevents double-moving to the current directory. |
| 389 // eg. When user clicks the item, changing directory has already been done in |
| 390 // click handler. |
| 386 if (this.directoryModel_.getCurrentDirEntry().fullPath == newPath) | 391 if (this.directoryModel_.getCurrentDirEntry().fullPath == newPath) |
| 387 return false; | 392 return false; |
| 388 | 393 |
| 394 metrics.recordUserAction('FolderShortcut.Navigate'); |
| 389 this.changeDirectory_(newPath); | 395 this.changeDirectory_(newPath); |
| 390 return true; | 396 return true; |
| 391 }; | 397 }; |
| 392 | 398 |
| 393 /** | 399 /** |
| 394 * Handler before root item change. | 400 * Handler before root item change. |
| 395 * @param {Event} event The event. | 401 * @param {Event} event The event. |
| 396 * @private | 402 * @private |
| 397 */ | 403 */ |
| 398 NavigationList.prototype.onBeforeSelectionChange_ = function(event) { | 404 NavigationList.prototype.onBeforeSelectionChange_ = function(event) { |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 var itemPath = this.dataModel.item(i); | 475 var itemPath = this.dataModel.item(i); |
| 470 if (PathUtil.getRootPath(itemPath) == newRootPath) { | 476 if (PathUtil.getRootPath(itemPath) == newRootPath) { |
| 471 // Not to invoke the handler of this instance, sets the guard. | 477 // Not to invoke the handler of this instance, sets the guard. |
| 472 this.dontHandleSelectionEvent_ = true; | 478 this.dontHandleSelectionEvent_ = true; |
| 473 this.selectionModel.selectedIndex = i; | 479 this.selectionModel.selectedIndex = i; |
| 474 this.dontHandleSelectionEvent_ = false; | 480 this.dontHandleSelectionEvent_ = false; |
| 475 return; | 481 return; |
| 476 } | 482 } |
| 477 } | 483 } |
| 478 }; | 484 }; |
| OLD | NEW |