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

fix #106487 implement 'enablement' clause for viewsWelcome contribution's buttons #107705

Merged
merged 4 commits into from
Nov 23, 2020
Merged
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions extensions/git/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2083,31 +2083,36 @@
{
"view": "scm",
"contents": "%view.workbench.scm.empty%",
"when": "config.git.enabled && git.state == initialized && workbenchState == empty",
"when": "config.git.enabled && workbenchState == empty",
"enablement": "git.state == initialized",
"group": "2_open@1"
},
{
"view": "scm",
"contents": "%view.workbench.scm.folder%",
"when": "config.git.enabled && git.state == initialized && workbenchState == folder",
"when": "config.git.enabled && workbenchState == folder",
"enablement": "git.state == initialized",
"group": "5_scm@1"
},
{
"view": "scm",
"contents": "%view.workbench.scm.workspace%",
"when": "config.git.enabled && git.state == initialized && workbenchState == workspace && workspaceFolderCount != 0",
"enablement": "git.state == initialized",
"group": "5_scm@1"
},
{
"view": "scm",
"contents": "%view.workbench.scm.emptyWorkspace%",
"when": "config.git.enabled && git.state == initialized && workbenchState == workspace && workspaceFolderCount == 0",
"when": "config.git.enabled && workbenchState == workspace && workspaceFolderCount == 0",
"enablement": "git.state == initialized",
"group": "2_open@1"
},
{
"view": "explorer",
"contents": "%view.workbench.cloneRepository%",
"when": "config.git.enabled && git.state == initialized",
"when": "config.git.enabled",
"enablement": "git.state == initialized",
"group": "5_scm@1"
}
]
Expand Down
2 changes: 1 addition & 1 deletion extensions/git/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,5 @@
"view.workbench.scm.folder": "The folder currently open doesn't have a git repository. You can initialize a repository which will enable source control features powered by git.\n[Initialize Repository](command:git.init?%5Btrue%5D)\nTo learn more about how to use git and source control in VS Code [read our docs](https://aka.ms/vscode-scm).",
"view.workbench.scm.workspace": "The workspace currently open doesn't have any folders containing git repositories. You can initialize a repository on a folder which will enable source control features powered by git.\n[Initialize Repository](command:git.init)\nTo learn more about how to use git and source control in VS Code [read our docs](https://aka.ms/vscode-scm).",
"view.workbench.scm.emptyWorkspace": "The workspace currently open doesn't have any folders containing git repositories.\n[Add Folder to Workspace](command:workbench.action.addRootFolder)\nTo learn more about how to use git and source control in VS Code [read our docs](https://aka.ms/vscode-scm).",
"view.workbench.cloneRepository": "You can also clone a repository from a URL. To learn more about how to use git and source control in VS Code [read our docs](https://aka.ms/vscode-scm).\n[Clone Repository](command:git.clone)"
"view.workbench.cloneRepository": "You can also clone a repository from a URL. To learn more about how to use git and source control in VS Code [read our docs](https://aka.ms/vscode-scm).\n[Clone Repository](command:git.clone 'Clone a repository once the git extension has activated')"
}
3 changes: 1 addition & 2 deletions src/vs/workbench/browser/parts/views/viewPaneContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,9 +554,8 @@ export abstract class ViewPane extends Pane implements IView {
this.bodyContainer.classList.add('welcome');
this.viewWelcomeContainer.innerText = '';

let buttonIndex = 0;

for (const { content, preconditions } of contents) {
let buttonIndex = 0;
const lines = content.split('\n');

for (let line of lines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ export class ViewsWelcomeContribution extends Disposable implements IWorkbenchCo
for (const welcome of contribution.value) {
const id = ViewIdentifierMap[welcome.view] ?? welcome.view;
const { group, order } = parseGroupAndOrder(welcome, contribution);
const enablement = ContextKeyExpr.deserialize(welcome.enablement);
const disposable = viewsRegistry.registerViewWelcomeContent(id, {
content: welcome.contents,
when: ContextKeyExpr.deserialize(welcome.when),
// supply the enablement clause for each line in case the line defines a button
preconditions: welcome.contents.split('\n').map((_) => enablement),
group,
order
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export enum ViewsWelcomeExtensionPointFields {
contents = 'contents',
when = 'when',
group = 'group',
enablement = 'enablement',
}

export interface ViewWelcome {
readonly [ViewsWelcomeExtensionPointFields.view]: string;
readonly [ViewsWelcomeExtensionPointFields.contents]: string;
readonly [ViewsWelcomeExtensionPointFields.when]: string;
readonly [ViewsWelcomeExtensionPointFields.group]: string;
readonly [ViewsWelcomeExtensionPointFields.enablement]: string;
}

export type ViewsWelcomeExtensionPoint = ViewWelcome[];
Expand Down Expand Up @@ -64,6 +66,10 @@ const viewsWelcomeExtensionPointSchema = Object.freeze<IConfigurationPropertySch
type: 'string',
description: nls.localize('contributes.viewsWelcome.view.group', "Group to which this welcome content belongs."),
},
[ViewsWelcomeExtensionPointFields.enablement]: {
type: 'string',
description: nls.localize('contributes.viewsWelcome.view.enablement', "Condition when the welcome content buttons should be enabled."),
},
}
}
});
Expand Down