Skip to content

Commit

Permalink
Change WPILib on status bar to open project information (wpilibsuite#577
Browse files Browse the repository at this point in the history
)
  • Loading branch information
wpineth committed Mar 29, 2024
1 parent 9e61327 commit b60ff79
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion vscode-wpilib/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export async function activate(context: vscode.ExtensionContext) {

try {
// Create the help window provider
help = await Help.Create(externalApi.getPreferencesAPI(), extensionResourceLocation);
help = await Help.Create(extensionResourceLocation);
context.subscriptions.push(help);
} catch (err) {
logger.error('error creating help window provider', err);
Expand Down
18 changes: 18 additions & 0 deletions vscode-wpilib/src/projectinfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,30 @@ export class ProjectInfoGatherer {
private wpilibUpdates: WPILibUpdates;
private externalApi: IExternalAPI;
private disposables: vscode.Disposable[] = [];
private statusBar: vscode.StatusBarItem;

public constructor(vendorLibraries: VendorLibraries, wpilibUpdates: WPILibUpdates, externalApi: IExternalAPI) {
this.vendorLibraries = vendorLibraries;
this.wpilibUpdates = wpilibUpdates;
this.externalApi = externalApi;

this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 0);
this.statusBar.text = 'WPILib';
this.statusBar.tooltip = 'Open WPILib Project Information';
this.statusBar.command = 'wpilibcore.getProjectInformation';
this.disposables.push(this.statusBar);

const workspaces = vscode.workspace.workspaceFolders;
if (workspaces !== undefined) {
for (const wp of workspaces) {
const prefs = this.externalApi.getPreferencesAPI().getPreferences(wp);
if (prefs.getIsWPILibProject()) {
this.statusBar.show();
break;
}
}
}

this.disposables.push(vscode.commands.registerCommand('wpilibcore.getProjectInformation', async () => {
await this.displayProjectInfo();
}));
Expand Down
27 changes: 3 additions & 24 deletions vscode-wpilib/src/webviews/help.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
'use strict';
import * as path from 'path';
import * as vscode from 'vscode';
import { IPreferencesAPI } from 'vscode-wpilibapi';
import { extensionContext } from '../utilities';
import { WebViewBase } from './webviewbase';

export class Help extends WebViewBase {
public static async Create(preferences: IPreferencesAPI, resourceRoot: string): Promise<Help> {
const help = new Help(preferences, resourceRoot);
public static async Create(resourceRoot: string): Promise<Help> {
const help = new Help(resourceRoot);
await help.asyncInitialize();
return help;
}

private statusBar: vscode.StatusBarItem;
private preferences: IPreferencesAPI;

private constructor(preferences: IPreferencesAPI, resourceRoot: string) {
private constructor(resourceRoot: string) {
super('wpilibhelp', 'WPILib Help', resourceRoot);
this.preferences = preferences;
this.statusBar = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 0);
this.statusBar.text = 'WPILib';
this.statusBar.tooltip = 'Open WPILib Help';
this.statusBar.command = 'wpilibcore.help';
this.disposables.push(this.statusBar);

this.disposables.push(vscode.commands.registerCommand('wpilibcore.help', () => {
this.displayHelp();
Expand All @@ -35,16 +25,5 @@ export class Help extends WebViewBase {

private async asyncInitialize() {
await this.loadWebpage(path.join(extensionContext.extensionPath, 'resources', 'webviews', 'help.html'));

const workspaces = vscode.workspace.workspaceFolders;
if (workspaces !== undefined) {
for (const wp of workspaces) {
const prefs = this.preferences.getPreferences(wp);
if (prefs.getIsWPILibProject()) {
this.statusBar.show();
break;
}
}
}
}
}

0 comments on commit b60ff79

Please sign in to comment.