diff --git a/src/debugger.ts b/src/debugger.ts index ce36d0f..fd08dea 100644 --- a/src/debugger.ts +++ b/src/debugger.ts @@ -5,6 +5,7 @@ import { CXXRTLConnection, CXXRTLDebugItem, CXXRTLDebugItemType, CXXRTLNodeDesig import { TimePoint } from './model/time'; import { Scope } from './model/scope'; import { Variable } from './model/variable'; +import { StatusItemController } from './ui/status'; export enum CXXRTLSessionStatus { Absent = "absent", @@ -13,7 +14,7 @@ export enum CXXRTLSessionStatus { } export class CXXRTLDebugger { - private statusItem: vscode.StatusBarItem; + private statusItemController: StatusItemController; private terminal: vscode.Terminal | null = null; private connection: CXXRTLConnection | null = null; @@ -44,37 +45,7 @@ export class CXXRTLDebugger { readonly onDidChangeLatestTime: vscode.Event = this._onDidChangeLatestTime.event; constructor() { - this.statusItem = vscode.window.createStatusBarItem('rtlDebugger', vscode.StatusBarAlignment.Left, 10); - this.statusItem.tooltip = 'RTL Debugger Status'; - this.statusItem.command = 'rtlDebugger.runPauseSimulation'; - this.onDidChangeSessionStatus((_state) => this.updateStatusItem()); - this.onDidChangeCurrentTime((_time) => this.updateStatusItem()); - this.onDidChangeSimulationStatus((_state) => this.updateStatusItem()); - this.onDidChangeLatestTime((_time) => this.updateStatusItem()); - } - - private updateStatusItem() { - if (this.sessionStatus === CXXRTLSessionStatus.Absent) { - this.statusItem.hide(); - } else { - this.statusItem.show(); - if (this.sessionStatus === CXXRTLSessionStatus.Starting) { - this.statusItem.text = `$(gear~spin) Starting...`; - this.statusItem.tooltip = `RTL Debugger: Starting`; - } else { // this.sessionState === CXXRTLSessionState.Running - if (this.simulationStatus === CXXRTLSimulationStatus.Running) { - this.statusItem.text = '$(debug-pause) '; - this.statusItem.tooltip = `RTL Debugger: Running`; - } else if (this.simulationStatus === CXXRTLSimulationStatus.Paused) { - this.statusItem.text = '$(debug-continue) '; - this.statusItem.tooltip = `RTL Debugger: Paused`; - } else if (this.simulationStatus === CXXRTLSimulationStatus.Finished) { - this.statusItem.text = ''; - this.statusItem.tooltip = `RTL Debugger: Finished`; - } - this.statusItem.text += `${this.currentTime} / ${this.latestTime}`; - } - } + this.statusItemController = new StatusItemController(this); } public dispose() { diff --git a/src/ui/sidebar.ts b/src/ui/sidebar.ts index 26dba2b..e69c5cb 100644 --- a/src/ui/sidebar.ts +++ b/src/ui/sidebar.ts @@ -192,17 +192,17 @@ export class TreeDataProvider implements vscode.TreeDataProvider { constructor( readonly rtlDebugger: CXXRTLDebugger ) { + vscode.workspace.onDidChangeConfiguration((event) => { + if (event.affectsConfiguration('rtlDebugger.displayStyle')) { + this._onDidChangeTreeData.fire(null); + } + }); rtlDebugger.onDidChangeSessionStatus((_state) => { this._onDidChangeTreeData.fire(null); }); rtlDebugger.onDidChangeCurrentTime((_time) => { this._onDidChangeTreeData.fire(null); }); - vscode.workspace.onDidChangeConfiguration((event) => { - if (event.affectsConfiguration('rtlDebugger.displayStyle')) { - this._onDidChangeTreeData.fire(null); - } - }); } getTreeItem(element: TreeItem): vscode.TreeItem | Thenable { diff --git a/src/ui/status.ts b/src/ui/status.ts new file mode 100644 index 0000000..998ed28 --- /dev/null +++ b/src/ui/status.ts @@ -0,0 +1,49 @@ +import * as vscode from 'vscode'; +import { CXXRTLDebugger, CXXRTLSessionStatus } from '../debugger'; +import { CXXRTLSimulationStatus } from '../connection'; + +export class StatusItemController { + private statusItem: vscode.StatusBarItem; + private subscriptions: vscode.Disposable[] = []; + + constructor( + private rtlDebugger: CXXRTLDebugger + ) { + this.statusItem = vscode.window.createStatusBarItem('rtlDebugger', vscode.StatusBarAlignment.Left, 10); + this.statusItem.tooltip = 'RTL Debugger Status'; + this.statusItem.command = 'rtlDebugger.runPauseSimulation'; + rtlDebugger.onDidChangeSessionStatus((_state) => this.update(), this.subscriptions); + rtlDebugger.onDidChangeCurrentTime((_time) => this.update(), this.subscriptions); + rtlDebugger.onDidChangeSimulationStatus((_state) => this.update(), this.subscriptions); + rtlDebugger.onDidChangeLatestTime((_time) => this.update(), this.subscriptions); + } + + dispose() { + this.subscriptions.splice(0, this.subscriptions.length).forEach(sub => sub.dispose()); + this.statusItem.dispose(); + } + + private update() { + if (this.rtlDebugger.sessionStatus === CXXRTLSessionStatus.Absent) { + this.statusItem.hide(); + } else { + this.statusItem.show(); + if (this.rtlDebugger.sessionStatus === CXXRTLSessionStatus.Starting) { + this.statusItem.text = `$(gear~spin) Starting...`; + this.statusItem.tooltip = `RTL Debugger: Starting`; + } else { // this.sessionState === CXXRTLSessionState.Running + if (this.rtlDebugger.simulationStatus === CXXRTLSimulationStatus.Running) { + this.statusItem.text = '$(debug-pause) '; + this.statusItem.tooltip = `RTL Debugger: Running`; + } else if (this.rtlDebugger.simulationStatus === CXXRTLSimulationStatus.Paused) { + this.statusItem.text = '$(debug-continue) '; + this.statusItem.tooltip = `RTL Debugger: Paused`; + } else if (this.rtlDebugger.simulationStatus === CXXRTLSimulationStatus.Finished) { + this.statusItem.text = ''; + this.statusItem.tooltip = `RTL Debugger: Finished`; + } + this.statusItem.text += `${this.rtlDebugger.currentTime} / ${this.rtlDebugger.latestTime}`; + } + } + } +};