mirror of
https://github.com/react/react-native-devtools-frontend.git
synced 2026-11-05 04:39:20 +08:00
Bug: none Change-Id: I02ef1182143b7fe091ce92d59f04ac2188903e0d Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2886925 Commit-Queue: Jack Franklin <jacktfranklin@chromium.org> Auto-Submit: Jack Franklin <jacktfranklin@chromium.org> Reviewed-by: Tim van der Lippe <tvanderlippe@chromium.org> Reviewed-by: Mathias Bynens <mathias@chromium.org>
88 lines
2.4 KiB
TypeScript
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 '../../core/common/common.js';
|
|
import * as UI from '../../ui/legacy/legacy.js';
|
|
|
|
import type {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): void {
|
|
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(): string {
|
|
return 'category://' + this.categoryName;
|
|
}
|
|
|
|
setLink(link: string): void {
|
|
this.categoryLink = link;
|
|
}
|
|
|
|
onselect(selectedByUser: boolean|undefined): boolean {
|
|
super.onselect(selectedByUser);
|
|
this.resourcesPanel.showCategoryView(this.categoryName, this.categoryLink);
|
|
return false;
|
|
}
|
|
|
|
onattach(): void {
|
|
super.onattach();
|
|
if (this.expandedSetting.get()) {
|
|
this.expand();
|
|
}
|
|
}
|
|
|
|
onexpand(): void {
|
|
this.expandedSetting.set(true);
|
|
}
|
|
|
|
oncollapse(): void {
|
|
this.expandedSetting.set(false);
|
|
}
|
|
}
|