UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 3.79 kB
import*as Common from"../../core/common/common.js";import*as i18n from"../../core/i18n/i18n.js";import*as DataGrid from"../../ui/legacy/components/data_grid/data_grid.js";import*as UI from"../../ui/legacy/legacy.js";import*as TraceEngine from"../../models/trace/trace.js";import{Category,IsLong}from"./TimelineFilters.js";import{TimelineSelection}from"./TimelineSelection.js";import{TimelineTreeView}from"./TimelineTreeView.js";import{TimelineUIUtils}from"./TimelineUIUtils.js";const UIStrings={filterEventLog:"Filter event log",startTime:"Start Time",durationFilter:"Duration filter",Dms:"{PH1} ms",all:"All"},str_=i18n.i18n.registerUIStrings("panels/timeline/EventsTimelineTreeView.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class EventsTimelineTreeView extends TimelineTreeView{filtersControl;delegate;currentTree;constructor(e){super(),this.filtersControl=new Filters,this.filtersControl.addEventListener("FilterChanged",this.onFilterChanged,this),this.init(),this.delegate=e,this.dataGrid.markColumnAsSortedBy("startTime",DataGrid.DataGrid.Order.Ascending),this.splitWidget.showBoth()}filters(){return[...super.filters(),...this.filtersControl.filters()]}updateContents(e){super.updateContents(e),TimelineSelection.isTraceEventSelection(e.object)&&this.selectEvent(e.object,!0)}getToolbarInputAccessiblePlaceHolder(){return i18nString(UIStrings.filterEventLog)}buildTree(){return this.currentTree=this.buildTopDownTree(!0,null),this.currentTree}onFilterChanged(){const e=this.lastSelectedNode(),t=e&&e.event;this.refreshTree(),t&&this.selectEvent(t,!1)}findNodeWithEvent(e){if("RunTask"===e.name)return null;const t=[this.currentTree.children().values()];for(;t.length;){const{done:i,value:r}=t[t.length-1].next();if(i)t.pop();else{if(r.event===e)return r;t.push(r.children().values())}}return null}selectEvent(e,t){const i=this.findNodeWithEvent(e);if(i&&(this.selectProfileNode(i,!1),t)){const e=this.dataGridNodeForTreeNode(i);e&&e.expand()}}populateColumns(e){e.push({id:"startTime",title:i18nString(UIStrings.startTime),width:"80px",fixedWidth:!0,sortable:!0}),super.populateColumns(e),e.filter((e=>e.fixedWidth)).forEach((e=>{e.width="80px"}))}populateToolbar(e){super.populateToolbar(e),this.filtersControl.populateToolbar(e)}showDetailsForNode(e){const t=e.event;if(!t)return!1;const i=this.model();return!!i&&(TimelineUIUtils.buildTraceEventDetails(t,i.timelineModel(),this.linkifier,!1,this.traceParseData()).then((e=>this.detailsView.element.appendChild(e))),!0)}onHover(e){this.delegate.highlightEvent(e&&e.event)}}export class Filters extends Common.ObjectWrapper.ObjectWrapper{categoryFilter;durationFilter;filtersInternal;constructor(){super(),this.categoryFilter=new Category,this.durationFilter=new IsLong,this.filtersInternal=[this.categoryFilter,this.durationFilter]}filters(){return this.filtersInternal}populateToolbar(e){const t=new UI.Toolbar.ToolbarComboBox(function(){const e=t.selectedOption().value,i=parseInt(e,10);this.durationFilter.setMinimumRecordDuration(i),this.notifyFiltersChanged()}.bind(this),i18nString(UIStrings.durationFilter));for(const e of Filters.durationFilterPresetsMs)t.addOption(t.createOption(e?`≥ ${i18nString(UIStrings.Dms,{PH1:e})}`:i18nString(UIStrings.all),String(e)));e.appendToolbarItem(t);const i=new Map,r=TimelineUIUtils.categories();for(const t in r){const s=r[t];if(!s.visible)continue;const o=new UI.Toolbar.ToolbarCheckbox(s.title,void 0,n.bind(this,t));o.setChecked(!0),o.inputElement.style.backgroundColor=s.color,i.set(s.name,o),e.appendToolbarItem(o)}function n(e){const t=TimelineUIUtils.categories(),r=i.get(e);t[e].hidden=!r||!r.checked(),this.notifyFiltersChanged()}}notifyFiltersChanged(){this.dispatchEventToListeners("FilterChanged")}static durationFilterPresetsMs=[0,1,15]}