]> Git Repo - pico-vscode.git/blob - src/ui.mts
Fix linting errors
[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   picoSDKQuickPick = "raspberry-pi-pico.sdk-quick-pick",
8 }
9
10 const STATUS_BAR_ITEMS: {
11   [key: string]: { text: string; command: string; tooltip: string };
12 } = {
13   [StatusBarItemKey.compile]: {
14     // alt. "$(gear) Compile"
15     text: "$(file-binary) Build UF2",
16     command: "raspberry-pi-pico.compileProject",
17     tooltip: "Compile project",
18   },
19   [StatusBarItemKey.picoSDKQuickPick]: {
20     text: "Pico SDK: <version>",
21     command: "raspberry-pi-pico.switchSDK",
22     tooltip: "Select Pico SDK",
23   },
24 };
25
26 export default class UI {
27   private _logger: Logger;
28   private _items: { [key: string]: StatusBarItem } = {};
29
30   constructor(private readonly _activityBarProvider: PicoProjectActivityBar) {
31     this._logger = new Logger("UI");
32   }
33
34   public init(): void {
35     this._logger.info("Initializing UI");
36
37     Object.entries(STATUS_BAR_ITEMS).forEach(([key, value]) => {
38       this._items[key] = this.createStatusBarItem(
39         key,
40         value.text,
41         value.command,
42         value.tooltip
43       );
44     });
45   }
46
47   public showStatusBarItems(): void {
48     Object.values(this._items).forEach(item => item.show());
49   }
50
51   public updateSDKVersion(version: string): void {
52     this._items[StatusBarItemKey.picoSDKQuickPick].text = STATUS_BAR_ITEMS[
53       StatusBarItemKey.picoSDKQuickPick
54     ].text.replace("<version>", version);
55     this._activityBarProvider.refresh(version);
56   }
57
58   /*
59   /**
60    * Returns the selected Pico SDK version from the status bar.
61    *
62    * @returns
63   public getUIPicoSDKVersion(): string {
64     /* unsafe, Needs to be updated if the status bar item format ever changes
65     
66     return this._items[StatusBarItemKey.picoSDKQuickPick].text
67       .split(":")[1]
68       .trim();
69     return this._sdkVersion;
70   }*/
71
72   private createStatusBarItem(
73     key: string,
74     text: string,
75     command: string,
76     tooltip: string
77   ): StatusBarItem {
78     const item = window.createStatusBarItem(key, StatusBarAlignment.Right);
79     item.text = text;
80     item.command = command;
81     item.tooltip = tooltip;
82
83     return item;
84   }
85 }
This page took 0.030772 seconds and 4 git commands to generate.