Files
react-native-devtools-frontend/front_end/resources/ApplicationPanelTreeElement.ts
T
Sigurd Schneider c57ccf2b7b Refactor ExpandableApplicationPanelTreeElement
Some classes in ApplicationPanelSidebar inherit from a class called
StorageCategoryTreeElement. That class name is from a time when the
Application panel was only about storage and is nowadays misleading.
This CL renames the class to ExpandableApplicationPanelTreeElement
and moves it to ApplicationPanelTreeElement.ts. This enables
moving other classes to separate files later on.

R=wolfi@chromium.org

Bug: chromium:1157484
Change-Id: I3121827da92830ceb1b5132489fd5b0ecedeaf63
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2587015
Reviewed-by: Wolfgang Beyer <wolfi@chromium.org>
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
2020-12-11 15:26:57 +00:00

88 lines
2.4 KiB
TypeScript

// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import * as Common from '../common/common.js';
import * as UI from '../ui/ui.js';
import {ResourcesPanel} from './ResourcesPanel.js';
export class ApplicationPanelTreeElement extends UI.TreeOutline.TreeElement {
protected readonly resourcesPanel: ResourcesPanel;
constructor(resourcesPanel: ResourcesPanel, title: string, expandable: boolean) {
super(title, expandable);
this.resourcesPanel = resourcesPanel;
UI.ARIAUtils.setAccessibleName(this.listItemElement, title);
}
get itemURL(): string {
throw new Error('Unimplemented Method');
}
onselect(selectedByUser: boolean|undefined): boolean {
if (!selectedByUser) {
return false;
}
const path: string[] = [];
for (let el: UI.TreeOutline.TreeElement|null = this; el; el = el.parent) {
const url = el instanceof ApplicationPanelTreeElement && el.itemURL;
if (!url) {
break;
}
path.push(url);
}
this.resourcesPanel.setLastSelectedItemPath(path);
return false;
}
showView(view: UI.Widget.Widget|null) {
this.resourcesPanel.showView(view);
}
}
export class ExpandableApplicationPanelTreeElement extends ApplicationPanelTreeElement {
protected readonly expandedSetting: Common.Settings.Setting<boolean>;
protected readonly categoryName: string;
protected categoryLink: string|null;
constructor(resourcesPanel: ResourcesPanel, categoryName: string, settingsKey: string, settingsDefault = false) {
super(resourcesPanel, categoryName, false);
this.expandedSetting =
Common.Settings.Settings.instance().createSetting('resources' + settingsKey + 'Expanded', settingsDefault);
this.categoryName = categoryName;
this.categoryLink = null;
}
get itemURL() {
return 'category://' + this.categoryName;
}
setLink(link: string) {
this.categoryLink = link;
}
onselect(selectedByUser: boolean|undefined): boolean {
super.onselect(selectedByUser);
this.resourcesPanel.showCategoryView(this.categoryName, this.categoryLink);
return false;
}
onattach() {
super.onattach();
if (this.expandedSetting.get()) {
this.expand();
}
}
onexpand() {
this.expandedSetting.set(true);
}
oncollapse() {
this.expandedSetting.set(false);
}
}