]> Git Repo - pico-vscode.git/blob - src/ui.mts
Update dependencies + auto-format
[pico-vscode.git] / src / ui.mts
1 import { window, type StatusBarItem, StatusBarAlignment } from "vscode";
2 import Logger from "./logger.mjs";
3 import type { PicoProjectActivityBar } from "./webview/activityBar.mjs";
4
5 enum StatusBarItemKey {
6   compile = "raspberry-pi-pico.compileProject",
7   run = "raspberry-pi-pico.runProject",
8   picoSDKQuickPick = "raspberry-pi-pico.sdk-quick-pick",
9   picoBoardQuickPick = "raspberry-pi-pico.board-quick-pick",
10 }
11
12 const STATUS_BAR_ITEMS: {
13   [key: string]: { text: string; command: string; tooltip: string };
14 } = {
15   [StatusBarItemKey.compile]: {
16     // alt. "$(gear) Compile"
17     text: "$(file-binary) Compile",
18     command: "raspberry-pi-pico.compileProject",
19     tooltip: "Compile Project",
20   },
21   [StatusBarItemKey.run]: {
22     // alt. "$(gear) Compile"
23     text: "$(run) Run",
24     command: "raspberry-pi-pico.runProject",
25     tooltip: "Run Project",
26   },
27   [StatusBarItemKey.picoSDKQuickPick]: {
28     text: "Pico SDK: <version>",
29     command: "raspberry-pi-pico.switchSDK",
30     tooltip: "Select Pico SDK",
31   },
32   [StatusBarItemKey.picoBoardQuickPick]: {
33     text: "Board: <board>",
34     command: "raspberry-pi-pico.switchBoard",
35     tooltip: "Select Board",
36   },
37 };
38
39 export default class UI {
40   private _logger: Logger;
41   private _items: { [key: string]: StatusBarItem } = {};
42
43   constructor(private readonly _activityBarProvider: PicoProjectActivityBar) {
44     this._logger = new Logger("UI");
45   }
46
47   public init(): void {
48     this._logger.info("Initializing UI");
49
50     Object.entries(STATUS_BAR_ITEMS).forEach(([key, value]) => {
51       this._items[key] = this.createStatusBarItem(
52         key,
53         value.text,
54         value.command,
55         value.tooltip
56       );
57     });
58   }
59
60   public showStatusBarItems(): void {
61     Object.values(this._items).forEach(item => item.show());
62   }
63
64   public updateSDKVersion(version: string): void {
65     this._items[StatusBarItemKey.picoSDKQuickPick].text = STATUS_BAR_ITEMS[
66       StatusBarItemKey.picoSDKQuickPick
67     ].text.replace("<version>", version);
68     this._activityBarProvider.refresh(version);
69   }
70
71   public updateBoard(board: string): void {
72     this._items[StatusBarItemKey.picoBoardQuickPick].text = STATUS_BAR_ITEMS[
73       StatusBarItemKey.picoBoardQuickPick
74     ].text.replace("<board>", board);
75   }
76
77   /*
78   /**
79    * Returns the selected Pico SDK version from the status bar.
80    *
81    * @returns
82   public getUIPicoSDKVersion(): string {
83     /* unsafe, Needs to be updated if the status bar item format ever changes
84     
85     return this._items[StatusBarItemKey.picoSDKQuickPick].text
86       .split(":")[1]
87       .trim();
88     return this._sdkVersion;
89   }*/
90
91   private createStatusBarItem(
92     key: string,
93     text: string,
94     command: string,
95     tooltip: string
96   ): StatusBarItem {
97     const item = window.createStatusBarItem(key, StatusBarAlignment.Right);
98     item.text = text;
99     item.command = command;
100     item.tooltip = tooltip;
101
102     return item;
103   }
104 }
This page took 0.029216 seconds and 4 git commands to generate.