Skip to content

Commit

Permalink
Extract status item into its own class.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitequark committed Oct 7, 2024
1 parent 74b4e76 commit 39d7507
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 37 deletions.
35 changes: 3 additions & 32 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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;

Expand Down Expand Up @@ -44,37 +45,7 @@ export class CXXRTLDebugger {
readonly onDidChangeLatestTime: vscode.Event<TimePoint> = 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() {
Expand Down
10 changes: 5 additions & 5 deletions src/ui/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,17 @@ export class TreeDataProvider implements vscode.TreeDataProvider<TreeItem> {
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<vscode.TreeItem> {
Expand Down
49 changes: 49 additions & 0 deletions src/ui/status.ts
Original file line number Diff line number Diff line change
@@ -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}`;
}
}
}
};

0 comments on commit 39d7507

Please sign in to comment.