Skip to content

Commit e7fafca

Browse files
committed
add status bar: project, target
1 parent 96ea5d3 commit e7fafca

3 files changed

Lines changed: 117 additions & 3 deletions

File tree

src/EIDEProjectExplorer.ts

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ import * as ArmCpuUtils from './ArmCpuUtils';
113113
import { ShellFlasherIndexItem } from './WebInterface/WebInterface';
114114
import { jsonc } from 'jsonc';
115115
import { SimpleUIConfig, SimpleUIConfigData_input, SimpleUIConfigData_options, SimpleUIConfigData_text, SimpleUIConfigData_table, SimpleUIConfigData_boolean } from "./SimpleUIDef";
116+
import { StatusBarManager } from './StatusBarManager';
116117

117118
enum TreeItemType {
118119
SOLUTION,
@@ -907,7 +908,32 @@ class ProjectDataProvider implements vscode.TreeDataProvider<ProjTreeItem>, vsco
907908
}
908909

909910
UpdateView(ele?: ProjTreeItem) {
911+
912+
// update treeview ui
910913
this.dataChangedEvent.fire(ele);
914+
915+
// whole treeview updated
916+
if (ele == undefined) {
917+
setTimeout(() => this.updateStatusBarForActiveProjects(), 500);
918+
}
919+
}
920+
921+
private updateStatusBarForActiveProjects() {
922+
923+
const statusbars = StatusBarManager.getInstance();
924+
925+
statusbars.foreach((bar, name) => {
926+
927+
const activeProj = this.getActiveProject();
928+
929+
if (name == 'current.project') {
930+
bar.text = `EIDE Project: ${activeProj?.getProjectName() || 'unspecified'}`;
931+
}
932+
933+
else if (name == 'current.target') {
934+
bar.text = `Target: ${activeProj?.getCurrentTarget() || 'unspecified'}`;
935+
}
936+
});
911937
}
912938

913939
clearTreeViewCache() {
@@ -3839,6 +3865,60 @@ export class ProjectExplorer implements CustomConfigurationProvider {
38393865
pickBox.show();
38403866
}
38413867

3868+
async showQuickPickAndSwitchActiveProject() {
3869+
3870+
const acvtiveProj = this.dataProvider.getActiveProject();
3871+
3872+
const selections: vscode.QuickPickItem[] = [];
3873+
3874+
this.dataProvider.foreachProject((proj) => {
3875+
if (acvtiveProj && proj.getUid() == acvtiveProj.getUid())
3876+
return;
3877+
selections.push(<any>{
3878+
uid: proj.getUid(),
3879+
label: proj.getProjectName(),
3880+
description: `uid: ${proj.getUid()}`,
3881+
detail: `loc: ${proj.getWorkspaceFile().path}`
3882+
});
3883+
});
3884+
3885+
if (selections.length > 0) {
3886+
3887+
const result: any = await vscode.window.showQuickPick(selections, {
3888+
title: `Switch Active Project`,
3889+
canPickMany: false,
3890+
});
3891+
3892+
if (result) {
3893+
const idx = this.dataProvider.getIndexByProjectUid(result.uid);
3894+
if (idx != -1) {
3895+
this.dataProvider.setActiveProject(idx);
3896+
}
3897+
}
3898+
}
3899+
}
3900+
3901+
async showQuickPickAndSwitchActiveTarget() {
3902+
3903+
const activeProj = this.getActiveProject();
3904+
3905+
if (activeProj) {
3906+
3907+
const selections = activeProj.getTargets().map<vscode.QuickPickItem>((name) => { return { label: name }; });
3908+
3909+
const result = await vscode.window.showQuickPick(selections, {
3910+
title: `Switch Active Target`,
3911+
canPickMany: false
3912+
});
3913+
3914+
if (result) {
3915+
if (result.label != activeProj.getCurrentTarget()) {
3916+
activeProj.switchTarget(result.label);
3917+
}
3918+
}
3919+
}
3920+
}
3921+
38423922
clearCppcheckDiagnostic(): void {
38433923
this.cppcheck_diag.clear();
38443924
}

src/StatusBarManager.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,16 @@ export class StatusBarManager {
5050
return bar;
5151
}
5252
}
53-
/*
53+
5454
get(name: string): vscode.StatusBarItem | undefined {
5555
return this.barMap.get(name);
56-
} */
56+
}
57+
58+
foreach(callbk: (bar: vscode.StatusBarItem, name: string) => void) {
59+
this.barMap.forEach((v, k) => {
60+
callbk(v, k);
61+
});
62+
}
5763

5864
show(name: string) {
5965
if (this.barMap.has(name)) {

src/extension.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ export async function activate(context: vscode.ExtensionContext) {
254254
operationExplorer.on('request_create_from_template', (option) => projectExplorer.emit('request_create_from_template', option));
255255
operationExplorer.on('request_import_project', (option) => projectExplorer.emit('request_import_project', option));
256256

257+
// status bar
258+
subscriptions.push(vscode.commands.registerCommand('_cl.eide.statusbar.switch-project', () => projectExplorer.showQuickPickAndSwitchActiveProject()));
259+
subscriptions.push(vscode.commands.registerCommand('_cl.eide.statusbar.switch-target', () => projectExplorer.showQuickPickAndSwitchActiveTarget()));
260+
257261
// others
258262
vscode.workspace.registerTextDocumentContentProvider(VirtualDocument.scheme, VirtualDocument.instance());
259263
vscode.workspace.registerTaskProvider(EideTaskProvider.TASK_TYPE_MSYS, new EideTaskProvider());
@@ -1024,7 +1028,16 @@ async function InitComponents(context: vscode.ExtensionContext): Promise<boolean
10241028
{
10251029
const statusBarManager = StatusBarManager.getInstance();
10261030

1027-
// TODO
1031+
const bar_cur_proj = statusBarManager.create('current.project');
1032+
const bar_cur_targ = statusBarManager.create('current.target');
1033+
1034+
bar_cur_proj.text = `EIDE Project: unspecified`;
1035+
bar_cur_proj.command = `_cl.eide.statusbar.switch-project`;
1036+
bar_cur_proj.tooltip = `select active project`;
1037+
1038+
bar_cur_targ.text = `Target: unspecified`;
1039+
bar_cur_targ.command = `_cl.eide.statusbar.switch-target`;
1040+
bar_cur_targ.tooltip = `select active target for eide project`;
10281041
}
10291042

10301043
// register msys bash profile for windows
@@ -1093,6 +1106,21 @@ function RegisterGlobalEvent() {
10931106
vscode.commands.executeCommand('setContext', 'cl.eide.projectActived', prj_count != 0);
10941107
vscode.commands.executeCommand('setContext', 'cl.eide.enable.active', prj_count > 1);
10951108
});
1109+
1110+
// for status bar
1111+
GlobalEvent.on('project.opened', () => {
1112+
if (prj_count == 1) {
1113+
StatusBarManager.getInstance().get('current.project')?.show();
1114+
StatusBarManager.getInstance().get('current.target')?.show();
1115+
}
1116+
});
1117+
1118+
GlobalEvent.on('project.closed', () => {
1119+
if (prj_count == 0) {
1120+
StatusBarManager.getInstance().get('current.project')?.hide();
1121+
StatusBarManager.getInstance().get('current.target')?.hide();
1122+
}
1123+
});
10961124
}
10971125

10981126
////////////////////////////////////////////

0 commit comments

Comments
 (0)