]> Git Repo - pico-vscode.git/blob - src/ui.mts
Add global env vars and compile button
[pico-vscode.git] / src / ui.mts
1 import { window, type StatusBarItem, StatusBarAlignment } from "vscode";
2 import Logger from "./logger.mjs";
3
4 enum StatusBarItemKey {
5   compile = "raspberry-pi-pico.compileProject",
6   picoSDKQuickPick = "raspberry-pi-pico.sdk-quick-pick",
7 }
8
9 const STATUS_BAR_ITEMS: {
10   [key: string]: { text: string; command: string; tooltip: string };
11 } = {
12   [StatusBarItemKey.compile]: {
13     text: "$(gear) Compile",
14     command: "raspberry-pi-pico.compileProject",
15     tooltip: "Compile project",
16   },
17   [StatusBarItemKey.picoSDKQuickPick]: {
18     text: "Pico SDK: <version>",
19     command: "raspberry-pi-pico.switchSDK",
20     tooltip: "Select Pico SDK",
21   },
22 };
23
24 export default class UI {
25   private _logger: Logger;
26   private _items: { [key: string]: StatusBarItem } = {};
27
28   constructor() {
29     this._logger = new Logger("UI");
30   }
31
32   public init(): void {
33     this._logger.info("Initializing UI");
34
35     Object.entries(STATUS_BAR_ITEMS).forEach(([key, value]) => {
36       this._items[key] = this.createStatusBarItem(
37         key,
38         value.text,
39         value.command,
40         value.tooltip
41       );
42     });
43   }
44
45   public showStatusBarItems(): void {
46     Object.values(this._items).forEach(item => item.show());
47   }
48
49   public updateSDKVersion(version: string): void {
50     this._items[StatusBarItemKey.picoSDKQuickPick].text = STATUS_BAR_ITEMS[
51       StatusBarItemKey.picoSDKQuickPick
52     ].text.replace("<version>", version);
53   }
54
55   private createStatusBarItem(
56     key: string,
57     text: string,
58     command: string,
59     tooltip: string
60   ): StatusBarItem {
61     const item = window.createStatusBarItem(key, StatusBarAlignment.Right);
62     item.text = text;
63     item.command = command;
64     item.tooltip = tooltip;
65
66     return item;
67   }
68 }
This page took 0.028227 seconds and 4 git commands to generate.