Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

workspace: add workbenchState context key #10550

Merged
merged 2 commits into from
Jan 7, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export enum WorkspaceStates {
folder = 'folder',
};
export type WorkspaceState = keyof typeof WorkspaceStates;
export type WorkbenchState = keyof typeof WorkspaceStates;

@injectable()
export class WorkspaceFrontendContribution implements CommandContribution, KeybindingContribution, MenuContribution, FrontendApplicationContribution {
Expand Down Expand Up @@ -90,11 +91,16 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi
const updateWorkspaceStateKey = () => workspaceStateKey.set(this.updateWorkspaceStateKey());
updateWorkspaceStateKey();

const workbenchStateKey = this.contextKeyService.createKey<WorkbenchState>('workbenchState', 'empty');
const updateWorkbenchStateKey = () => workbenchStateKey.set(this.updateWorkbenchStateKey());
updateWorkbenchStateKey();

this.updateStyles();
this.workspaceService.onWorkspaceChanged(() => {
this.updateEncodingOverrides();
updateWorkspaceFolderCountKey();
updateWorkspaceStateKey();
updateWorkbenchStateKey();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you expect that workspaceState and workbenchState may want to have different values in the future? In this code, they're updated in tandem and with the same values, so they could be combined.

this.updateStyles();
});
}
Expand Down Expand Up @@ -495,8 +501,16 @@ export class WorkspaceFrontendContribution implements CommandContribution, Keybi
}

protected updateWorkspaceStateKey(): WorkspaceState {
return this.doUpdateState();
}

protected updateWorkbenchStateKey(): WorkbenchState {
return this.doUpdateState();
}

protected doUpdateState(): WorkspaceState | WorkbenchState {
if (this.workspaceService.opened) {
return this.workspaceService.isMultiRootWorkspaceOpened ? 'folder' : 'workspace';
return this.workspaceService.isMultiRootWorkspaceOpened ? 'workspace' : 'folder';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the original code might have had the logic reversed.

}
return 'empty';
}
Expand Down