Skip to content

Commit

Permalink
project status view working (needs more testing tho)
Browse files Browse the repository at this point in the history
  • Loading branch information
snehara99 committed Oct 25, 2023
1 parent 10efdbf commit 234beca
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
5 changes: 3 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export type CMakeCommunicationMode = 'legacy' | 'serverApi' | 'fileApi' | 'autom
export type StatusBarButtonVisibility = "default" | "compact" | "icon" | "hidden";
export type StatusBarStaticButtonVisibility = "default" | "icon" | "hidden";
export type StatusBarTextButtonVisibility = "default" | "compact" | "hidden";
export type StatusBarIconButtonVisibility = "default" | "hidden";
export type ProjectStatusButtonVisibility = "default" | "hidden";
export type TouchBarButtonVisibility = "default" | "hidden";
export type UseCMakePresets = 'always' | 'never' | 'auto';
Expand Down Expand Up @@ -91,11 +92,11 @@ export interface AdvancedStatusConfig {
};
debug?: {
projectStatusVisibility?: ProjectStatusButtonVisibility;
statusBarVisibility?: StatusBarStaticButtonVisibility;
statusBarVisibility?: StatusBarIconButtonVisibility;
};
launch?: {
projectStatusVisibility?: ProjectStatusButtonVisibility;
statusBarVisibility?: StatusBarStaticButtonVisibility;
statusBarVisibility?: StatusBarIconButtonVisibility;
};
ctest?: {
projectStatusVisibility?: ProjectStatusButtonVisibility;
Expand Down
6 changes: 3 additions & 3 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import * as nls from 'vscode-nls';
import * as api from 'vscode-cmake-tools';
import { CMakeCache } from '@cmt/cache';
import { CMakeProject, ConfigureType, ConfigureTrigger, DiagnosticsConfiguration, DiagnosticsSettings } from '@cmt/cmakeProject';
import { ConfigurationReader, getSettingsChangePromise, TouchBarConfig } from '@cmt/config';
import { ConfigurationReader, getSettingsChangePromise, StatusConfig, TouchBarConfig } from '@cmt/config';
import { CppConfigurationProvider, DiagnosticsCpptools } from '@cmt/cpptools';
import { ProjectController, FolderProjectType} from '@cmt/projectController';

Expand Down Expand Up @@ -228,7 +228,7 @@ export class ExtensionManager implements vscode.Disposable {
/**
* The project status view controller
*/
private readonly projectStatus = new ProjectStatus(this.workspaceConfig);
projectStatus = new ProjectStatus();

// NOTE: (from sidebar) The project controller manages all the projects in the workspace
public readonly projectController = new ProjectController(this.extensionContext, this.projectStatus);
Expand Down Expand Up @@ -581,7 +581,7 @@ export class ExtensionManager implements vscode.Disposable {

// Update the active project
private async updateActiveProject(workspaceFolder?: vscode.WorkspaceFolder, editor?: vscode.TextEditor): Promise<void> {
await this.projectController.updateActiveProject(workspaceFolder, editor);
await this.projectController.updateActiveProject(workspaceFolder, editor, this.workspaceConfig.status);
await this.postUpdateActiveProject();
}

Expand Down
22 changes: 11 additions & 11 deletions src/projectController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,19 @@ export class ProjectController implements vscode.Disposable {
}

private activeProject: CMakeProject | undefined;
async updateActiveProject(workspaceFolder?: vscode.WorkspaceFolder, openEditor?: vscode.TextEditor): Promise<void> {
async updateActiveProject(workspaceFolder?: vscode.WorkspaceFolder, openEditor?: vscode.TextEditor, status?: StatusConfig): Promise<void> {
const projects: CMakeProject[] | undefined = this.getProjectsForWorkspaceFolder(workspaceFolder);
if (projects && projects.length > 0) {
if (openEditor) {
for (const project of projects) {
if (util.isFileInsideFolder(openEditor.document.uri, project.folderPath)) {
await this.setActiveProject(project);
await this.setActiveProject(project, status);
break;
}
}
if (!this.activeProject) {
if (util.isFileInsideFolder(openEditor.document.uri, projects[0].workspaceFolder.uri.fsPath)) {
await this.setActiveProject(projects[0]);
await this.setActiveProject(projects[0], status);
}
}
// If active project is found, return.
Expand All @@ -113,17 +113,17 @@ export class ProjectController implements vscode.Disposable {
}
} else {
// Set a default active project.
await this.setActiveProject(projects[0]);
await this.setActiveProject(projects[0], status);
return;
}
}
await this.setActiveProject(undefined);
}

async setActiveProject(project?: CMakeProject): Promise<void> {
async setActiveProject(project?: CMakeProject, status?: StatusConfig): Promise<void> {
this.activeProject = project;
void this.updateUsePresetsState(this.activeProject);
await this.projectStatus.updateActiveProject(project);
await this.projectStatus.updateActiveProject(project, status);
await this.setupProjectSubscriptions(project);
}

Expand Down Expand Up @@ -334,7 +334,7 @@ export class ProjectController implements vscode.Disposable {
this.folderToProjectsMap.set(folder.uri.fsPath, projects);
const config: ConfigurationReader | undefined = workspaceContext.config;
if (config) {
this.sourceDirectorySub.set(folder, config.onChange('sourceDirectory', async (sourceDirectories: string | string[]) => this.doSourceDirectoryChange(folder, sourceDirectories)));
this.sourceDirectorySub.set(folder, config.onChange('sourceDirectory', async (sourceDirectories: string | string[]) => this.doSourceDirectoryChange(folder, sourceDirectories, config.status)));
this.buildDirectorySub.set(folder, config.onChange('buildDirectory', async () => this.refreshDriverSettings(config, folder)));
this.installPrefixSub.set(folder, config.onChange('installPrefix', async () => this.refreshDriverSettings(config, folder)));
this.useCMakePresetsSub.set(folder, config.onChange('useCMakePresets', async (useCMakePresets: string) => this.doUseCMakePresetsChange(folder, useCMakePresets)));
Expand Down Expand Up @@ -379,7 +379,7 @@ export class ProjectController implements vscode.Disposable {
this.useCMakePresetsSub.delete(folder);
}

private async doSourceDirectoryChange(folder: vscode.WorkspaceFolder, value: string | string[]) {
private async doSourceDirectoryChange(folder: vscode.WorkspaceFolder, value: string | string[], status: StatusConfig) {
let sourceDirectories: string[] = [];
if (typeof (value) === 'string') {
sourceDirectories = [value];
Expand Down Expand Up @@ -416,7 +416,7 @@ export class ProjectController implements vscode.Disposable {
for (let i = 0; i < sourceDirectories.length; i++) {
const cmakeProject: CMakeProject = await CMakeProject.create(workspaceContext, sourceDirectories[i], this, sourceDirectories.length > 1);
if (activeProjectPath === cmakeProject.sourceDir) {
await this.setActiveProject(cmakeProject);
await this.setActiveProject(cmakeProject, status);

activeProjectPath = undefined;
}
Expand All @@ -426,7 +426,7 @@ export class ProjectController implements vscode.Disposable {

if (activeProjectPath !== undefined) {
// Active project is no longer available. Pick a different one.
await this.setActiveProject(projects.length > 0 ? projects[0] : undefined);
await this.setActiveProject(projects.length > 0 ? projects[0] : undefined, status);

}

Expand Down Expand Up @@ -470,7 +470,7 @@ export class ProjectController implements vscode.Disposable {
project.doStatusChange(status);
}
}
await this.projectStatus.doStatusChange();
await this.projectStatus.doStatusChange(status);
await util.setContextValue(ext.hideBuildCommandKey, (status.advanced?.build?.statusBarVisibility === "hidden" && status?.advanced?.build?.projectStatusVisibility === "hidden") ? true : false);
await util.setContextValue(ext.hideDebugCommandKey, (status.advanced?.debug?.statusBarVisibility === "hidden" && status?.advanced?.debug?.projectStatusVisibility === "hidden") ? true : false);
await util.setContextValue(ext.hideLaunchCommandKey, (status.advanced?.launch?.statusBarVisibility === "hidden" && status?.advanced?.launch?.projectStatusVisibility === "hidden") ? true : false);
Expand Down
12 changes: 6 additions & 6 deletions src/projectStatus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ export class ProjectStatus {

protected disposables: vscode.Disposable[] = [];

constructor(protected readonly config: ConfigurationReader) {
constructor() {
treeDataProvider = new TreeDataProvider();
this.config.onChange('status', () => this.doStatusChange());
this.disposables.push(...[
// Commands for projectStatus items
vscode.commands.registerCommand('cmake.projectStatus.stop', async (_node: Node) => {
Expand Down Expand Up @@ -86,9 +85,9 @@ export class ProjectStatus {
]);
}

async updateActiveProject(cmakeProject?: CMakeProject): Promise<void> {
async updateActiveProject(cmakeProject?: CMakeProject, status?: StatusConfig): Promise<void> {
// Update Active Project
await treeDataProvider.updateActiveProject(cmakeProject, this.config.status);
await treeDataProvider.updateActiveProject(cmakeProject, status);
}

refresh(node?: Node): Promise<any> {
Expand Down Expand Up @@ -120,8 +119,8 @@ export class ProjectStatus {
await treeDataProvider.setIsBusy(isBusy);
}

async doStatusChange() {
await treeDataProvider.doStatusChange(this.config.status);
async doStatusChange(status: StatusConfig) {
await treeDataProvider.doStatusChange(status);
}

}
Expand Down Expand Up @@ -247,6 +246,7 @@ class TreeDataProvider implements vscode.TreeDataProvider<Node>, vscode.Disposab
}
}

// TODO: get rid of undefined?
public async doStatusChange(status: StatusConfig | undefined) {
let didChange: boolean = false;
if (this.activeCMakeProject) {
Expand Down
4 changes: 2 additions & 2 deletions src/status.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ConfigurationReader, StatusBarButtonVisibility, StatusBarTextButtonVisibility, StatusBarStaticButtonVisibility } from '@cmt/config';
import { ConfigurationReader, StatusBarButtonVisibility, StatusBarTextButtonVisibility, StatusBarStaticButtonVisibility, StatusBarIconButtonVisibility } from '@cmt/config';
import { SpecialKits } from '@cmt/kit';
import * as vscode from 'vscode';
import * as nls from 'vscode-nls';
Expand Down Expand Up @@ -131,7 +131,7 @@ abstract class Button {
private _isVisible(): boolean {
return this.isVisible() && this._getVisibilitySetting() !== 'hidden';
}
private _getVisibilitySetting(): StatusBarButtonVisibility | StatusBarTextButtonVisibility | StatusBarStaticButtonVisibility | null {
private _getVisibilitySetting(): StatusBarButtonVisibility | StatusBarTextButtonVisibility | StatusBarStaticButtonVisibility | StatusBarIconButtonVisibility | null {
if (this.settingsName) {
let setting = Object(this.config.status.advanced)[this.settingsName]?.statusBarVisibility;
if (setting === undefined) {
Expand Down

0 comments on commit 234beca

Please sign in to comment.