| 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 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 * cr.ui.List internally. | 287 * cr.ui.List internally. |
| 288 * @param {string} path Path of the directory to be rendered. | 288 * @param {string} path Path of the directory to be rendered. |
| 289 * @return {NavigationListItem} Rendered element. | 289 * @return {NavigationListItem} Rendered element. |
| 290 * @private | 290 * @private |
| 291 */ | 291 */ |
| 292 NavigationList.prototype.renderRoot_ = function(path) { | 292 NavigationList.prototype.renderRoot_ = function(path) { |
| 293 var item = new NavigationListItem(); | 293 var item = new NavigationListItem(); |
| 294 item.setPath(path); | 294 item.setPath(path); |
| 295 | 295 |
| 296 var handleClick = function() { | 296 var handleClick = function() { |
| 297 if (item.selected && path !== this.directoryModel_.getCurrentDirPath()) | 297 if (item.selected && path !== this.directoryModel_.getCurrentDirPath()) { |
| 298 metrics.recordUserAction('FolderShortcut.Navigate'); |
| 298 this.changeDirectory_(path); | 299 this.changeDirectory_(path); |
| 300 } |
| 299 }.bind(this); | 301 }.bind(this); |
| 300 item.addEventListener('click', handleClick); | 302 item.addEventListener('click', handleClick); |
| 301 | 303 |
| 302 var handleEject = function() { | 304 var handleEject = function() { |
| 303 var unmountCommand = cr.doc.querySelector('command#unmount'); | 305 var unmountCommand = cr.doc.querySelector('command#unmount'); |
| 304 // Let's make sure 'canExecute' state of the command is properly set for | 306 // Let's make sure 'canExecute' state of the command is properly set for |
| 305 // the root before executing it. | 307 // the root before executing it. |
| 306 unmountCommand.canExecuteChange(item); | 308 unmountCommand.canExecuteChange(item); |
| 307 unmountCommand.execute(item); | 309 unmountCommand.execute(item); |
| 308 }; | 310 }; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 NavigationList.prototype.setContextMenu = function(menu) { | 344 NavigationList.prototype.setContextMenu = function(menu) { |
| 343 this.contextMenu_ = menu; | 345 this.contextMenu_ = menu; |
| 344 | 346 |
| 345 for (var i = 0; i < this.dataModel.length; i++) { | 347 for (var i = 0; i < this.dataModel.length; i++) { |
| 346 this.getListItemByIndex(i).maybeSetContextMenu(this.contextMenu_); | 348 this.getListItemByIndex(i).maybeSetContextMenu(this.contextMenu_); |
| 347 } | 349 } |
| 348 }; | 350 }; |
| 349 | 351 |
| 350 /** | 352 /** |
| 351 * Selects the n-th item from the list. | 353 * Selects the n-th item from the list. |
| 354 * |
| 352 * @param {number} index Item index. | 355 * @param {number} index Item index. |
| 353 * @return {boolean} True for success, otherwise false. | 356 * @return {boolean} True for success, otherwise false. |
| 354 */ | 357 */ |
| 355 NavigationList.prototype.selectByIndex = function(index) { | 358 NavigationList.prototype.selectByIndex = function(index) { |
| 356 if (index < 0 || index > this.dataModel.length - 1) | 359 if (index < 0 || index > this.dataModel.length - 1) |
| 357 return false; | 360 return false; |
| 358 | 361 |
| 359 var newPath = this.dataModel.item(index); | 362 var newPath = this.dataModel.item(index); |
| 360 if (!newPath) | 363 if (!newPath) |
| 361 return false; | 364 return false; |
| 362 | 365 |
| 363 // Prevents double-moving to the current directory. | 366 // Prevents double-moving to the current directory. |
| 367 // eg. When user clicks the item, changing directory has already been done in |
| 368 // click handler. |
| 364 if (this.directoryModel_.getCurrentDirEntry().fullPath == newPath) | 369 if (this.directoryModel_.getCurrentDirEntry().fullPath == newPath) |
| 365 return false; | 370 return false; |
| 366 | 371 |
| 372 metrics.recordUserAction('FolderShortcut.Navigate'); |
| 367 this.changeDirectory_(newPath); | 373 this.changeDirectory_(newPath); |
| 368 return true; | 374 return true; |
| 369 }; | 375 }; |
| 370 | 376 |
| 371 /** | 377 /** |
| 372 * Handler before root item change. | 378 * Handler before root item change. |
| 373 * @param {Event} event The event. | 379 * @param {Event} event The event. |
| 374 * @private | 380 * @private |
| 375 */ | 381 */ |
| 376 NavigationList.prototype.onBeforeSelectionChange_ = function(event) { | 382 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); | 453 var itemPath = this.dataModel.item(i); |
| 448 if (PathUtil.getRootPath(itemPath) == newRootPath) { | 454 if (PathUtil.getRootPath(itemPath) == newRootPath) { |
| 449 // Not to invoke the handler of this instance, sets the guard. | 455 // Not to invoke the handler of this instance, sets the guard. |
| 450 this.dontHandleSelectionEvent_ = true; | 456 this.dontHandleSelectionEvent_ = true; |
| 451 this.selectionModel.selectedIndex = i; | 457 this.selectionModel.selectedIndex = i; |
| 452 this.dontHandleSelectionEvent_ = false; | 458 this.dontHandleSelectionEvent_ = false; |
| 453 return; | 459 return; |
| 454 } | 460 } |
| 455 } | 461 } |
| 456 }; | 462 }; |
| OLD | NEW |