Commit d3add75d authored by Luciano Pacheco's avatar Luciano Pacheco Committed by Commit Bot

Convert directory_tree.js to const/let using lebab

Command used:
$ lebab --replace \
    ui/file_manager/file_manager/foreground/js/ui/directory_tree.js \
    --transform let

Lebab: https://github.com/lebab/lebab

No change in behaviour.

Bug: 778674
Change-Id: I4693f3da54d904bbb9e115bc5f413f67d867707a
Reviewed-on: https://chromium-review.googlesource.com/c/1298817
Commit-Queue: Luciano Pacheco <lucmult@chromium.org>
Reviewed-by: default avatarStuart Langley <slangley@chromium.org>
Reviewed-by: default avatarJoel Hockey <joelhockey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602989}
parent 4533f28f
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Instead, we separate their implementations to this separate object and call * Instead, we separate their implementations to this separate object and call
* it with setting 'this' from DirectoryTree/Item. * it with setting 'this' from DirectoryTree/Item.
*/ */
var DirectoryItemTreeBaseMethods = {}; const DirectoryItemTreeBaseMethods = {};
/** /**
* Finds an item by entry and returns it. * Finds an item by entry and returns it.
...@@ -20,8 +20,8 @@ var DirectoryItemTreeBaseMethods = {}; ...@@ -20,8 +20,8 @@ var DirectoryItemTreeBaseMethods = {};
* @this {(DirectoryItem|DirectoryTree)} * @this {(DirectoryItem|DirectoryTree)}
*/ */
DirectoryItemTreeBaseMethods.getItemByEntry = function(entry) { DirectoryItemTreeBaseMethods.getItemByEntry = function(entry) {
for (var i = 0; i < this.items.length; i++) { for (let i = 0; i < this.items.length; i++) {
var item = this.items[i]; const item = this.items[i];
if (!item.entry) if (!item.entry)
continue; continue;
if (util.isSameEntry(item.entry, entry)) { if (util.isSameEntry(item.entry, entry)) {
...@@ -60,8 +60,8 @@ DirectoryItemTreeBaseMethods.getItemByEntry = function(entry) { ...@@ -60,8 +60,8 @@ DirectoryItemTreeBaseMethods.getItemByEntry = function(entry) {
* @this {(DirectoryItem|VolumeItem|DirectoryTree)} * @this {(DirectoryItem|VolumeItem|DirectoryTree)}
*/ */
DirectoryItemTreeBaseMethods.searchAndSelectByEntry = function(entry) { DirectoryItemTreeBaseMethods.searchAndSelectByEntry = function(entry) {
for (var i = 0; i < this.items.length; i++) { for (let i = 0; i < this.items.length; i++) {
var item = this.items[i]; const item = this.items[i];
if (!item.entry) if (!item.entry)
continue; continue;
...@@ -98,8 +98,8 @@ DirectoryItemTreeBaseMethods.searchAndSelectByEntry = function(entry) { ...@@ -98,8 +98,8 @@ DirectoryItemTreeBaseMethods.searchAndSelectByEntry = function(entry) {
*/ */
DirectoryItemTreeBaseMethods.recordUMASelectedEntry = function( DirectoryItemTreeBaseMethods.recordUMASelectedEntry = function(
e, rootType, isRootEntry) { e, rootType, isRootEntry) {
var expandIconSelected = e.target.classList.contains('expand-icon'); const expandIconSelected = e.target.classList.contains('expand-icon');
var metricName = 'Location.OnEntrySelected.TopLevel'; let metricName = 'Location.OnEntrySelected.TopLevel';
if (!expandIconSelected && isRootEntry) { if (!expandIconSelected && isRootEntry) {
metricName = 'Location.OnEntrySelected.TopLevel'; metricName = 'Location.OnEntrySelected.TopLevel';
} else if (!expandIconSelected && !isRootEntry) { } else if (!expandIconSelected && !isRootEntry) {
...@@ -110,13 +110,13 @@ DirectoryItemTreeBaseMethods.recordUMASelectedEntry = function( ...@@ -110,13 +110,13 @@ DirectoryItemTreeBaseMethods.recordUMASelectedEntry = function(
metricName = 'Location.OnEntryExpandedOrCollapsed.NonTopLevel'; metricName = 'Location.OnEntryExpandedOrCollapsed.NonTopLevel';
} }
metrics.recordEnum(metricName, rootType, VolumeManagerCommon.RootTypesForUMA); metrics.recordEnum(
metricName, rootType, VolumeManagerCommon.RootTypesForUMA);
}; };
Object.freeze(DirectoryItemTreeBaseMethods); Object.freeze(DirectoryItemTreeBaseMethods);
var TREE_ITEM_INNER_HTML = const TREE_ITEM_INNER_HTML = '<div class="tree-row">' +
'<div class="tree-row">' +
' <paper-ripple fit class="recenteringTouch"></paper-ripple>' + ' <paper-ripple fit class="recenteringTouch"></paper-ripple>' +
' <span class="expand-icon"></span>' + ' <span class="expand-icon"></span>' +
' <span class="icon"></span>' + ' <span class="icon"></span>' +
...@@ -137,10 +137,10 @@ var TREE_ITEM_INNER_HTML = ...@@ -137,10 +137,10 @@ var TREE_ITEM_INNER_HTML =
* @constructor * @constructor
*/ */
function DirectoryItem(label, tree) { function DirectoryItem(label, tree) {
var item = /** @type {DirectoryItem} */ (new cr.ui.TreeItem()); const item = /** @type {DirectoryItem} */ (new cr.ui.TreeItem());
// Get the original label id defined by TreeItem, before overwriting // Get the original label id defined by TreeItem, before overwriting
// prototype. // prototype.
var labelId = item.labelElement.id; const labelId = item.labelElement.id;
item.__proto__ = DirectoryItem.prototype; item.__proto__ = DirectoryItem.prototype;
if (window.IN_TEST) { if (window.IN_TEST) {
item.setAttribute('dir-type', 'DirectoryItem'); item.setAttribute('dir-type', 'DirectoryItem');
...@@ -282,15 +282,16 @@ DirectoryItem.prototype.onMetadataUpdated_ = function(event) { ...@@ -282,15 +282,16 @@ DirectoryItem.prototype.onMetadataUpdated_ = function(event) {
* @this {DirectoryItem} * @this {DirectoryItem}
*/ */
DirectoryItem.prototype.updateSubElementsFromList = function(recursive) { DirectoryItem.prototype.updateSubElementsFromList = function(recursive) {
var index = 0; let index = 0;
var tree = this.parentTree_; const tree = this.parentTree_;
var item; let item;
while (this.entries_[index]) { while (this.entries_[index]) {
var currentEntry = this.entries_[index]; const currentEntry = this.entries_[index];
var currentElement = this.items[index]; const currentElement = this.items[index];
var label = util.getEntryLabel( const label =
tree.volumeManager_.getLocationInfo(currentEntry), util.getEntryLabel(
currentEntry) || ''; tree.volumeManager_.getLocationInfo(currentEntry), currentEntry) ||
'';
if (index >= this.items.length) { if (index >= this.items.length) {
// If currentEntry carries its navigationModel we generate an item // If currentEntry carries its navigationModel we generate an item
...@@ -334,7 +335,7 @@ DirectoryItem.prototype.updateSubElementsFromList = function(recursive) { ...@@ -334,7 +335,7 @@ DirectoryItem.prototype.updateSubElementsFromList = function(recursive) {
} }
} }
var removedChild; let removedChild;
while (removedChild = this.items[index]) { while (removedChild = this.items[index]) {
this.remove(removedChild); this.remove(removedChild);
} }
...@@ -395,7 +396,7 @@ DirectoryItem.prototype.remove = function(child) { ...@@ -395,7 +396,7 @@ DirectoryItem.prototype.remove = function(child) {
* to the ambiguous may-have-children state. * to the ambiguous may-have-children state.
*/ */
DirectoryItem.prototype.clearHasChildren = function() { DirectoryItem.prototype.clearHasChildren = function() {
var rowItem = this.firstElementChild; const rowItem = this.firstElementChild;
this.removeAttribute('has-children'); this.removeAttribute('has-children');
rowItem.removeAttribute('has-children'); rowItem.removeAttribute('has-children');
}; };
...@@ -461,8 +462,8 @@ DirectoryItem.prototype.onCollapse_ = function(e) { ...@@ -461,8 +462,8 @@ DirectoryItem.prototype.onCollapse_ = function(e) {
// to update recursively when items expand this proactively // to update recursively when items expand this proactively
// collapses all children to avoid having to traverse large // collapses all children to avoid having to traverse large
// parts of the tree when reopened. // parts of the tree when reopened.
for (var i = 0; i < this.items.length; i++) { for (let i = 0; i < this.items.length; i++) {
var item = this.items[i]; const item = this.items[i];
if (item.expanded) { if (item.expanded) {
item.expanded = false; item.expanded = false;
...@@ -492,7 +493,7 @@ DirectoryItem.prototype.handleClick = function(e) { ...@@ -492,7 +493,7 @@ DirectoryItem.prototype.handleClick = function(e) {
// If this is DriveVolumeItem, the UMA has already been recorded. // If this is DriveVolumeItem, the UMA has already been recorded.
if (!(this instanceof DriveVolumeItem)) { if (!(this instanceof DriveVolumeItem)) {
var location = this.tree.volumeManager.getLocationInfo(this.entry); const location = this.tree.volumeManager.getLocationInfo(this.entry);
DirectoryItemTreeBaseMethods.recordUMASelectedEntry.call( DirectoryItemTreeBaseMethods.recordUMASelectedEntry.call(
this, e, location.rootType, location.isRootEntry); this, e, location.rootType, location.isRootEntry);
} }
...@@ -557,8 +558,8 @@ DirectoryItem.prototype.updateItemByEntry = function(changedDirectoryEntry) { ...@@ -557,8 +558,8 @@ DirectoryItem.prototype.updateItemByEntry = function(changedDirectoryEntry) {
} }
// Traverse the entire subtree to find the changed element. // Traverse the entire subtree to find the changed element.
for (var i = 0; i < this.items.length; i++) { for (let i = 0; i < this.items.length; i++) {
var item = this.items[i]; const item = this.items[i];
if (!item.entry) if (!item.entry)
continue; continue;
if (util.isDescendantEntry(item.entry, changedDirectoryEntry) || if (util.isDescendantEntry(item.entry, changedDirectoryEntry) ||
...@@ -625,7 +626,7 @@ DirectoryItem.prototype.activate = function() { ...@@ -625,7 +626,7 @@ DirectoryItem.prototype.activate = function() {
* @constructor * @constructor
*/ */
function SubDirectoryItem(label, dirEntry, parentDirItem, tree) { function SubDirectoryItem(label, dirEntry, parentDirItem, tree) {
var item = new DirectoryItem(label, tree); const item = new DirectoryItem(label, tree);
item.__proto__ = SubDirectoryItem.prototype; item.__proto__ = SubDirectoryItem.prototype;
if (window.IN_TEST) if (window.IN_TEST)
...@@ -639,9 +640,9 @@ function SubDirectoryItem(label, dirEntry, parentDirItem, tree) { ...@@ -639,9 +640,9 @@ function SubDirectoryItem(label, dirEntry, parentDirItem, tree) {
} }
// Sets up icons of the item. // Sets up icons of the item.
var icon = item.querySelector('.icon'); const icon = item.querySelector('.icon');
icon.classList.add('item-icon'); icon.classList.add('item-icon');
var location = tree.volumeManager.getLocationInfo(item.entry); const location = tree.volumeManager.getLocationInfo(item.entry);
if (location && location.rootType && location.isRootEntry) { if (location && location.rootType && location.isRootEntry) {
icon.setAttribute('volume-type-icon', location.rootType); icon.setAttribute('volume-type-icon', location.rootType);
if (window.IN_TEST && location.volumeInfo) { if (window.IN_TEST && location.volumeInfo) {
...@@ -685,7 +686,7 @@ SubDirectoryItem.prototype = { ...@@ -685,7 +686,7 @@ SubDirectoryItem.prototype = {
* @override * @override
*/ */
SubDirectoryItem.prototype.updateSharedStatusIcon = function() { SubDirectoryItem.prototype.updateSharedStatusIcon = function() {
var icon = this.querySelector('.icon'); const icon = this.querySelector('.icon');
const metadata = const metadata =
this.parentTree_.metadataModel.getCache([this.dirEntry_], ['shared']); this.parentTree_.metadataModel.getCache([this.dirEntry_], ['shared']);
icon.classList.toggle('shared', !!(metadata[0] && metadata[0].shared)); icon.classList.toggle('shared', !!(metadata[0] && metadata[0].shared));
...@@ -702,7 +703,7 @@ SubDirectoryItem.prototype.updateSharedStatusIcon = function() { ...@@ -702,7 +703,7 @@ SubDirectoryItem.prototype.updateSharedStatusIcon = function() {
* @constructor * @constructor
*/ */
function EntryListItem(rootType, modelItem, tree) { function EntryListItem(rootType, modelItem, tree) {
var item = new DirectoryItem(modelItem.label, tree); const item = new DirectoryItem(modelItem.label, tree);
// Get the original label id defined by TreeItem, before overwriting // Get the original label id defined by TreeItem, before overwriting
// prototype. // prototype.
item.__proto__ = EntryListItem.prototype; item.__proto__ = EntryListItem.prototype;
...@@ -715,7 +716,7 @@ function EntryListItem(rootType, modelItem, tree) { ...@@ -715,7 +716,7 @@ function EntryListItem(rootType, modelItem, tree) {
item.dirEntry_ = modelItem.entry; item.dirEntry_ = modelItem.entry;
item.parentTree_ = tree; item.parentTree_ = tree;
var icon = queryRequiredElement('.icon', item); const icon = queryRequiredElement('.icon', item);
icon.classList.add('item-icon'); icon.classList.add('item-icon');
icon.setAttribute('root-type-icon', rootType); icon.setAttribute('root-type-icon', rootType);
return item; return item;
...@@ -795,7 +796,7 @@ EntryListItem.prototype.updateSubDirectories = function( ...@@ -795,7 +796,7 @@ EntryListItem.prototype.updateSubDirectories = function(
* @constructor * @constructor
*/ */
function VolumeItem(modelItem, tree) { function VolumeItem(modelItem, tree) {
var item = /** @type {VolumeItem} */ ( const item = /** @type {VolumeItem} */ (
new DirectoryItem(modelItem.volumeInfo.label, tree)); new DirectoryItem(modelItem.volumeInfo.label, tree));
item.__proto__ = VolumeItem.prototype; item.__proto__ = VolumeItem.prototype;
...@@ -892,8 +893,8 @@ VolumeItem.prototype.updateSubDirectories = function( ...@@ -892,8 +893,8 @@ VolumeItem.prototype.updateSubDirectories = function(
* @override * @override
*/ */
VolumeItem.prototype.activate = function() { VolumeItem.prototype.activate = function() {
var directoryModel = this.parentTree_.directoryModel; const directoryModel = this.parentTree_.directoryModel;
var onEntryResolved = (entry) => { const onEntryResolved = (entry) => {
// Changes directory to the model item's root directory if needed. // Changes directory to the model item's root directory if needed.
if (!util.isSameEntry(directoryModel.getCurrentDirEntry(), entry)) { if (!util.isSameEntry(directoryModel.getCurrentDirEntry(), entry)) {
metrics.recordUserAction('FolderShortcut.Navigate'); metrics.recordUserAction('FolderShortcut.Navigate');
...@@ -920,7 +921,7 @@ VolumeItem.prototype.activate = function() { ...@@ -920,7 +921,7 @@ VolumeItem.prototype.activate = function() {
*/ */
VolumeItem.prototype.setupIcon_ = function(icon, volumeInfo) { VolumeItem.prototype.setupIcon_ = function(icon, volumeInfo) {
icon.classList.add('item-icon'); icon.classList.add('item-icon');
var backgroundImage = const backgroundImage =
util.iconSetToCSSBackgroundImageValue(volumeInfo.iconSet); util.iconSetToCSSBackgroundImageValue(volumeInfo.iconSet);
if (backgroundImage !== 'none') { if (backgroundImage !== 'none') {
// The icon div is not yet added to DOM, therefore it is impossible to // The icon div is not yet added to DOM, therefore it is impossible to
...@@ -945,7 +946,7 @@ VolumeItem.prototype.setupIcon_ = function(icon, volumeInfo) { ...@@ -945,7 +946,7 @@ VolumeItem.prototype.setupIcon_ = function(icon, volumeInfo) {
* @private * @private
*/ */
VolumeItem.prototype.setupEjectButton_ = function(rowElement) { VolumeItem.prototype.setupEjectButton_ = function(rowElement) {
var ejectButton = cr.doc.createElement('button'); const ejectButton = cr.doc.createElement('button');
// Block other mouse handlers. // Block other mouse handlers.
ejectButton.addEventListener('mouseup', (event) => { ejectButton.addEventListener('mouseup', (event) => {
event.stopPropagation(); event.stopPropagation();
...@@ -958,7 +959,7 @@ VolumeItem.prototype.setupEjectButton_ = function(rowElement) { ...@@ -958,7 +959,7 @@ VolumeItem.prototype.setupEjectButton_ = function(rowElement) {
ejectButton.setAttribute('tabindex', '0'); ejectButton.setAttribute('tabindex', '0');
ejectButton.addEventListener('click', (event) => { ejectButton.addEventListener('click', (event) => {
event.stopPropagation(); event.stopPropagation();
var unmountCommand = cr.doc.querySelector('command#unmount'); const unmountCommand = cr.doc.querySelector('command#unmount');
// Let's make sure 'canExecute' state of the command is properly set for // Let's make sure 'canExecute' state of the command is properly set for
// the root before executing it. // the root before executing it.
unmountCommand.canExecuteChange(this); unmountCommand.canExecuteChange(this);
...@@ -967,7 +968,7 @@ VolumeItem.prototype.setupEjectButton_ = function(rowElement) { ...@@ -967,7 +968,7 @@ VolumeItem.prototype.setupEjectButton_ = function(rowElement) {
rowElement.appendChild(ejectButton); rowElement.appendChild(ejectButton);
// Add paper-ripple effect on the eject button. // Add paper-ripple effect on the eject button.
var ripple = cr.doc.createElement('paper-ripple'); const ripple = cr.doc.createElement('paper-ripple');
ripple.setAttribute('fit', ''); ripple.setAttribute('fit', '');
ripple.className = 'circle recenteringTouch'; ripple.className = 'circle recenteringTouch';
ejectButton.appendChild(ripple); ejectButton.appendChild(ripple);
...@@ -979,7 +980,7 @@ VolumeItem.prototype.setupEjectButton_ = function(rowElement) { ...@@ -979,7 +980,7 @@ VolumeItem.prototype.setupEjectButton_ = function(rowElement) {
* @private * @private
*/ */
VolumeItem.prototype.setupRenamePlaceholder_ = function(rowElement) { VolumeItem.prototype.setupRenamePlaceholder_ = function(rowElement) {
var placeholder = cr.doc.createElement('span'); const placeholder = cr.doc.createElement('span');
placeholder.className = 'rename-placeholder'; placeholder.className = 'rename-placeholder';
rowElement.appendChild(placeholder); rowElement.appendChild(placeholder);
}; };
...@@ -998,7 +999,7 @@ VolumeItem.prototype.setupRenamePlaceholder_ = function(rowElement) { ...@@ -998,7 +999,7 @@ VolumeItem.prototype.setupRenamePlaceholder_ = function(rowElement) {
* @constructor * @constructor
*/ */
function DriveVolumeItem(modelItem, tree) { function DriveVolumeItem(modelItem, tree) {
var item = new VolumeItem(modelItem, tree); const item = new VolumeItem(modelItem, tree);
item.__proto__ = DriveVolumeItem.prototype; item.__proto__ = DriveVolumeItem.prototype;
item.classList.add('drive-volume'); item.classList.add('drive-volume');
if (window.IN_TEST) if (window.IN_TEST)
...@@ -1068,7 +1069,7 @@ DriveVolumeItem.prototype.createTeamDrivesGrandRoot_ = function() { ...@@ -1068,7 +1069,7 @@ DriveVolumeItem.prototype.createTeamDrivesGrandRoot_ = function() {
} }
let index; let index;
for (var i = 0; i < this.items.length; i++) { for (let i = 0; i < this.items.length; i++) {
const entry = this.items[i] && this.items[i].entry; const entry = this.items[i] && this.items[i].entry;
if (entry && util.isSameEntry(entry, teamDriveGrandRoot)) { if (entry && util.isSameEntry(entry, teamDriveGrandRoot)) {
index = i; index = i;
...@@ -1190,22 +1191,22 @@ DriveVolumeItem.prototype.updateSubDirectories = function(recursive) { ...@@ -1190,22 +1191,22 @@ DriveVolumeItem.prototype.updateSubDirectories = function(recursive) {
if (!this.entry || this.hasChildren) if (!this.entry || this.hasChildren)
return; return;
var entries = [this.entry]; let entries = [this.entry];
var teamDrivesDisplayRoot = this.volumeInfo_.teamDriveDisplayRoot; const teamDrivesDisplayRoot = this.volumeInfo_.teamDriveDisplayRoot;
if (!!teamDrivesDisplayRoot) { if (!!teamDrivesDisplayRoot) {
entries.push(teamDrivesDisplayRoot); entries.push(teamDrivesDisplayRoot);
} }
var computersDisplayRoot = this.volumeInfo_.computersDisplayRoot; const computersDisplayRoot = this.volumeInfo_.computersDisplayRoot;
if (!!computersDisplayRoot) { if (!!computersDisplayRoot) {
entries.push(computersDisplayRoot); entries.push(computersDisplayRoot);
} }
// Drive volume has children including fake entries (offline, recent, ...) // Drive volume has children including fake entries (offline, recent, ...)
var fakeEntries = []; const fakeEntries = [];
if (this.parentTree_.fakeEntriesVisible_) { if (this.parentTree_.fakeEntriesVisible_) {
for (var key in this.volumeInfo_.fakeEntries) for (const key in this.volumeInfo_.fakeEntries)
fakeEntries.push(this.volumeInfo_.fakeEntries[key]); fakeEntries.push(this.volumeInfo_.fakeEntries[key]);
// This list is sorted by URL on purpose. // This list is sorted by URL on purpose.
fakeEntries.sort((a, b) => { fakeEntries.sort((a, b) => {
...@@ -1216,7 +1217,7 @@ DriveVolumeItem.prototype.updateSubDirectories = function(recursive) { ...@@ -1216,7 +1217,7 @@ DriveVolumeItem.prototype.updateSubDirectories = function(recursive) {
entries = entries.concat(fakeEntries); entries = entries.concat(fakeEntries);
} }
for (var i = 0; i < entries.length; i++) { for (let i = 0; i < entries.length; i++) {
// Only create the team drives root if there is at least 1 team drive. // Only create the team drives root if there is at least 1 team drive.
const entry = entries[i]; const entry = entries[i];
if (entry === teamDrivesDisplayRoot) { if (entry === teamDrivesDisplayRoot) {
...@@ -1316,10 +1317,10 @@ DriveVolumeItem.prototype.computersIndexPosition_ = function() { ...@@ -1316,10 +1317,10 @@ DriveVolumeItem.prototype.computersIndexPosition_ = function() {
* @constructor * @constructor
*/ */
function ShortcutItem(modelItem, tree) { function ShortcutItem(modelItem, tree) {
var item = /** @type {ShortcutItem} */ (new cr.ui.TreeItem()); const item = /** @type {ShortcutItem} */ (new cr.ui.TreeItem());
// Get the original label id defined by TreeItem, before overwriting // Get the original label id defined by TreeItem, before overwriting
// prototype. // prototype.
var labelId = item.labelElement.id; const labelId = item.labelElement.id;
item.__proto__ = ShortcutItem.prototype; item.__proto__ = ShortcutItem.prototype;
if (window.IN_TEST) if (window.IN_TEST)
...@@ -1331,7 +1332,7 @@ function ShortcutItem(modelItem, tree) { ...@@ -1331,7 +1332,7 @@ function ShortcutItem(modelItem, tree) {
item.innerHTML = TREE_ITEM_INNER_HTML; item.innerHTML = TREE_ITEM_INNER_HTML;
item.labelElement.id = labelId; item.labelElement.id = labelId;
var icon = item.querySelector('.icon'); const icon = item.querySelector('.icon');
icon.classList.add('item-icon'); icon.classList.add('item-icon');
icon.setAttribute('volume-type-icon', 'shortcut'); icon.setAttribute('volume-type-icon', 'shortcut');
...@@ -1390,7 +1391,7 @@ ShortcutItem.prototype.handleClick = function(e) { ...@@ -1390,7 +1391,7 @@ ShortcutItem.prototype.handleClick = function(e) {
// Resets file selection when a volume is clicked. // Resets file selection when a volume is clicked.
this.parentTree_.directoryModel.clearSelection(); this.parentTree_.directoryModel.clearSelection();
var location = this.tree.volumeManager.getLocationInfo(this.entry); const location = this.tree.volumeManager.getLocationInfo(this.entry);
DirectoryItemTreeBaseMethods.recordUMASelectedEntry.call( DirectoryItemTreeBaseMethods.recordUMASelectedEntry.call(
this, e, location.rootType, location.isRootEntry); this, e, location.rootType, location.isRootEntry);
}; };
...@@ -1417,8 +1418,8 @@ ShortcutItem.prototype.setContextMenu_ = function(menu) { ...@@ -1417,8 +1418,8 @@ ShortcutItem.prototype.setContextMenu_ = function(menu) {
* Change current entry to the entry corresponding to this shortcut. * Change current entry to the entry corresponding to this shortcut.
*/ */
ShortcutItem.prototype.activate = function() { ShortcutItem.prototype.activate = function() {
var directoryModel = this.parentTree_.directoryModel; const directoryModel = this.parentTree_.directoryModel;
var onEntryResolved = (entry) => { const onEntryResolved = (entry) => {
// Changes directory to the model item's root directory if needed. // Changes directory to the model item's root directory if needed.
if (!util.isSameEntry(directoryModel.getCurrentDirEntry(), entry)) { if (!util.isSameEntry(directoryModel.getCurrentDirEntry(), entry)) {
metrics.recordUserAction('FolderShortcut.Navigate'); metrics.recordUserAction('FolderShortcut.Navigate');
...@@ -1451,10 +1452,10 @@ ShortcutItem.prototype.activate = function() { ...@@ -1451,10 +1452,10 @@ ShortcutItem.prototype.activate = function() {
* @constructor * @constructor
*/ */
function FakeItem(rootType, modelItem, tree) { function FakeItem(rootType, modelItem, tree) {
var item = new cr.ui.TreeItem(); const item = new cr.ui.TreeItem();
// Get the original label id defined by TreeItem, before overwriting // Get the original label id defined by TreeItem, before overwriting
// prototype. // prototype.
var labelId = item.labelElement.id; const labelId = item.labelElement.id;
item.__proto__ = FakeItem.prototype; item.__proto__ = FakeItem.prototype;
if (window.IN_TEST) { if (window.IN_TEST) {
item.setAttribute('dir-type', 'FakeItem'); item.setAttribute('dir-type', 'FakeItem');
...@@ -1470,7 +1471,7 @@ function FakeItem(rootType, modelItem, tree) { ...@@ -1470,7 +1471,7 @@ function FakeItem(rootType, modelItem, tree) {
item.label = modelItem.label; item.label = modelItem.label;
item.directoryModel_ = tree.directoryModel; item.directoryModel_ = tree.directoryModel;
var icon = queryRequiredElement('.icon', item); const icon = queryRequiredElement('.icon', item);
icon.classList.add('item-icon'); icon.classList.add('item-icon');
icon.setAttribute('root-type-icon', rootType); icon.setAttribute('root-type-icon', rootType);
...@@ -1684,13 +1685,13 @@ DirectoryTree.createDirectoryItem = function(modelItem, tree) { ...@@ -1684,13 +1685,13 @@ DirectoryTree.createDirectoryItem = function(modelItem, tree) {
DirectoryTree.prototype.updateAndSelectNewDirectory = function( DirectoryTree.prototype.updateAndSelectNewDirectory = function(
parentDirectory, newDirectory) { parentDirectory, newDirectory) {
// Expand parent directory. // Expand parent directory.
var parentItem = DirectoryItemTreeBaseMethods.getItemByEntry.call( const parentItem =
this, parentDirectory); DirectoryItemTreeBaseMethods.getItemByEntry.call(this, parentDirectory);
parentItem.expanded = true; parentItem.expanded = true;
// If new directory is already added to the tree, just select it. // If new directory is already added to the tree, just select it.
for (var i = 0; i < parentItem.items.length; i++) { for (let i = 0; i < parentItem.items.length; i++) {
var item = parentItem.items[i]; const item = parentItem.items[i];
if (util.isSameEntry(item.entry, newDirectory)) { if (util.isSameEntry(item.entry, newDirectory)) {
this.selectedItem = item; this.selectedItem = item;
return; return;
...@@ -1698,10 +1699,10 @@ DirectoryTree.prototype.updateAndSelectNewDirectory = function( ...@@ -1698,10 +1699,10 @@ DirectoryTree.prototype.updateAndSelectNewDirectory = function(
} }
// Create new item, and add it. // Create new item, and add it.
var newDirectoryItem = new SubDirectoryItem( const newDirectoryItem =
newDirectory.name, newDirectory, parentItem, this); new SubDirectoryItem(newDirectory.name, newDirectory, parentItem, this);
var addAt = 0; let addAt = 0;
while (addAt < parentItem.items.length && while (addAt < parentItem.items.length &&
parentItem.items[addAt].entry.name < newDirectory.name) { parentItem.items[addAt].entry.name < newDirectory.name) {
addAt++; addAt++;
...@@ -1792,10 +1793,10 @@ DirectoryTree.prototype.updateSubElementsFromList = function(recursive) { ...@@ -1792,10 +1793,10 @@ DirectoryTree.prototype.updateSubElementsFromList = function(recursive) {
*/ */
DirectoryTree.prototype.searchAndSelectByEntry = function(entry) { DirectoryTree.prototype.searchAndSelectByEntry = function(entry) {
// If the |entry| is same as one of volumes or shortcuts, select it. // If the |entry| is same as one of volumes or shortcuts, select it.
for (var i = 0; i < this.items.length; i++) { for (let i = 0; i < this.items.length; i++) {
// Skips the Drive root volume. For Drive entries, one of children of Drive // Skips the Drive root volume. For Drive entries, one of children of Drive
// root or shortcuts should be selected. // root or shortcuts should be selected.
var item = this.items[i]; const item = this.items[i];
if (item instanceof DriveVolumeItem) if (item instanceof DriveVolumeItem)
continue; continue;
...@@ -1805,8 +1806,8 @@ DirectoryTree.prototype.searchAndSelectByEntry = function(entry) { ...@@ -1805,8 +1806,8 @@ DirectoryTree.prototype.searchAndSelectByEntry = function(entry) {
} }
} }
// Otherwise, search whole tree. // Otherwise, search whole tree.
var found = DirectoryItemTreeBaseMethods.searchAndSelectByEntry.call( const found =
this, entry); DirectoryItemTreeBaseMethods.searchAndSelectByEntry.call(this, entry);
return found; return found;
}; };
...@@ -1869,7 +1870,7 @@ DirectoryTree.prototype.decorateDirectoryTree = function( ...@@ -1869,7 +1870,7 @@ DirectoryTree.prototype.decorateDirectoryTree = function(
* @private * @private
*/ */
DirectoryTree.prototype.onEntriesChanged_ = function(event) { DirectoryTree.prototype.onEntriesChanged_ = function(event) {
var directories = event.entries.filter((entry) => entry.isDirectory); const directories = event.entries.filter((entry) => entry.isDirectory);
if (directories.length === 0) if (directories.length === 0)
return; return;
...@@ -1906,8 +1907,8 @@ DirectoryTree.prototype.selectByEntry = function(entry) { ...@@ -1906,8 +1907,8 @@ DirectoryTree.prototype.selectByEntry = function(entry) {
return; return;
this.updateSubDirectories(false /* recursive */); this.updateSubDirectories(false /* recursive */);
var currentSequence = ++this.sequence_; const currentSequence = ++this.sequence_;
var volumeInfo = this.volumeManager_.getVolumeInfo(entry); const volumeInfo = this.volumeManager_.getVolumeInfo(entry);
if (!volumeInfo) if (!volumeInfo)
return; return;
volumeInfo.resolveDisplayRoot(() => { volumeInfo.resolveDisplayRoot(() => {
...@@ -1990,7 +1991,7 @@ DirectoryTree.prototype.updateTreeByEntry_ = function(entry) { ...@@ -1990,7 +1991,7 @@ DirectoryTree.prototype.updateTreeByEntry_ = function(entry) {
() => { () => {
// If entry exists. // If entry exists.
// e.g. /a/b is deleted while watching /a. // e.g. /a/b is deleted while watching /a.
for (var i = 0; i < this.items.length; i++) { for (let i = 0; i < this.items.length; i++) {
if (this.items[i] instanceof VolumeItem || if (this.items[i] instanceof VolumeItem ||
this.items[i] instanceof EntryListItem) this.items[i] instanceof EntryListItem)
this.items[i].updateItemByEntry(entry); this.items[i].updateItemByEntry(entry);
...@@ -2010,11 +2011,11 @@ DirectoryTree.prototype.updateTreeByEntry_ = function(entry) { ...@@ -2010,11 +2011,11 @@ DirectoryTree.prototype.updateTreeByEntry_ = function(entry) {
// //
// TODO(yawano): Try to get parent path also in this case by // TODO(yawano): Try to get parent path also in this case by
// manipulating path string. // manipulating path string.
var volumeInfo = this.volumeManager.getVolumeInfo(entry); const volumeInfo = this.volumeManager.getVolumeInfo(entry);
if (!volumeInfo) if (!volumeInfo)
return; return;
for (var i = 0; i < this.items.length; i++) { for (let i = 0; i < this.items.length; i++) {
if (this.items[i] instanceof VolumeItem && if (this.items[i] instanceof VolumeItem &&
this.items[i].volumeInfo === volumeInfo) { this.items[i].volumeInfo === volumeInfo) {
this.items[i].updateSubDirectories(true /* recursive */); this.items[i].updateSubDirectories(true /* recursive */);
...@@ -2043,7 +2044,7 @@ DirectoryTree.prototype.onListContentChanged_ = function() { ...@@ -2043,7 +2044,7 @@ DirectoryTree.prototype.onListContentChanged_ = function() {
// current directory because the current directory might have been populated // current directory because the current directory might have been populated
// in this tree in previous updateSubDirectories(). // in this tree in previous updateSubDirectories().
if (!this.selectedItem) { if (!this.selectedItem) {
var currentDir = this.directoryModel_.getCurrentDirEntry(); const currentDir = this.directoryModel_.getCurrentDirEntry();
if (currentDir) if (currentDir)
this.selectByEntry(currentDir); this.selectByEntry(currentDir);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment