Wire up preconditions for viewsWelcome buttons, and use it

This commit is contained in:
gjsjohnmurray
2020-09-30 13:01:46 +01:00
parent af4fb00687
commit ceeb974856
5 changed files with 18 additions and 20 deletions

View File

@@ -2075,11 +2075,6 @@
"contents": "%view.workbench.scm.disabled%",
"when": "!config.git.enabled"
},
{
"view": "scm",
"contents": "%view.workbench.scm.activating%",
"when": "config.git.enabled && git.state != initialized"
},
{
"view": "scm",
"contents": "%view.workbench.scm.missing%",
@@ -2088,37 +2083,36 @@
{
"view": "scm",
"contents": "%view.workbench.scm.empty%",
"when": "config.git.enabled && git.state == initialized && workbenchState == empty",
"when": "config.git.enabled && workbenchState == empty",
"preconditions": ["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",
"preconditions": ["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",
"preconditions": ["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",
"preconditions": ["git.state == initialized"],
"group": "2_open@1"
},
{
"view": "explorer",
"contents": "%view.workbench.activating%",
"when": "config.git.enabled && git.state != initialized",
"group": "5_scm@1"
},
{
"view": "explorer",
"contents": "%view.workbench.cloneRepository%",
"when": "config.git.enabled && git.state == initialized",
"when": "config.git.enabled",
"preconditions": ["git.state == initialized"],
"group": "5_scm@1"
}
]

View File

@@ -177,11 +177,9 @@
"colors.submodule": "Color for submodule resources.",
"view.workbench.scm.missing": "A valid git installation was not detected, more details can be found in the [git output](command:git.showOutput).\nPlease [install git](https://git-scm.com/), or learn more about how to use git and source control in VS Code in [our docs](https://aka.ms/vscode-scm).\nIf you're using a different version control system, you can [search the Marketplace](command:workbench.extensions.search?%22%40category%3A%5C%22scm%20providers%5C%22%22) for additional extensions.",
"view.workbench.scm.disabled": "If you would like to use git features, please enable git in your [settings](command:workbench.action.openSettings?%5B%22git.enabled%22%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.activating": "Git extension is activating...\n[Learn More](https://aka.ms/vscode-scm)",
"view.workbench.scm.empty": "In order to use git features, you can open a folder containing a git repository or clone from a URL.\n[Open Folder](command:vscode.openFolder)\n[Clone Repository](command:git.clone)\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.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.activating": "Git extension is activating...\n[Learn More](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')"
}

View File

@@ -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) {

View File

@@ -39,6 +39,7 @@ export class ViewsWelcomeContribution extends Disposable implements IWorkbenchCo
const disposable = viewsRegistry.registerViewWelcomeContent(id, {
content: welcome.contents,
when: ContextKeyExpr.deserialize(welcome.when),
preconditions: welcome.preconditions?.map((value) => ContextKeyExpr.deserialize(value)),
group,
order
});

View File

@@ -11,6 +11,7 @@ export enum ViewsWelcomeExtensionPointFields {
contents = 'contents',
when = 'when',
group = 'group',
preconditions = 'preconditions',
}
export interface ViewWelcome {
@@ -18,6 +19,7 @@ export interface ViewWelcome {
readonly [ViewsWelcomeExtensionPointFields.contents]: string;
readonly [ViewsWelcomeExtensionPointFields.when]: string;
readonly [ViewsWelcomeExtensionPointFields.group]: string;
readonly [ViewsWelcomeExtensionPointFields.preconditions]: string[];
}
export type ViewsWelcomeExtensionPoint = ViewWelcome[];
@@ -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.preconditions]: {
type: 'array',
description: nls.localize('contributes.viewsWelcome.view.preconditions', "Conditions when the each of the welcome content buttons should be enabled."),
},
}
}
});