Skip to content

Commit 049ee36

Browse files
authored
Initial welcome widget commit (microsoft#183446)
* Initial welcome widget commit * Update i18n.resource.json for welcomeDialog * Clean up code
1 parent 731d08f commit 049ee36

File tree

7 files changed

+256
-138
lines changed

7 files changed

+256
-138
lines changed

build/lib/i18n.resources.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@
290290
"name": "vs/workbench/contrib/welcomeWalkthrough",
291291
"project": "vscode-workbench"
292292
},
293+
{
294+
"name": "vs/workbench/contrib/welcomeDialog",
295+
"project": "vscode-workbench"
296+
},
293297
{
294298
"name": "vs/workbench/contrib/outline",
295299
"project": "vscode-workbench"

src/vs/workbench/browser/web.api.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ export interface IWorkbenchConstructionOptions {
343343
readonly initialColorTheme?: IInitialColorTheme;
344344

345345
/**
346-
* Welcome view dialog on first launch. Can be dismissed by the user.
346+
* Welcome dialog. Can be dismissed by the user.
347347
*/
348348
readonly welcomeDialog?: IWelcomeDialog;
349349

@@ -639,14 +639,24 @@ export interface IWelcomeDialog {
639639
buttonText: string;
640640

641641
/**
642-
* Message text and icon for the welcome dialog.
642+
* Button command to execute from the welcome dialog.
643643
*/
644-
messages: { message: string; icon: string }[];
644+
buttonCommand: string;
645645

646646
/**
647-
* Optional action to appear as links at the bottom of the welcome dialog.
647+
* Message text for the welcome dialog.
648648
*/
649-
action?: IWelcomeLinkAction;
649+
message: string;
650+
651+
/**
652+
* Context key expression to control the visibility of the welcome dialog.
653+
*/
654+
when: string;
655+
656+
/**
657+
* Media to include in the welcome dialog.
658+
*/
659+
media: { altText: string; path: string };
650660
}
651661

652662
export interface IDefaultView {

src/vs/workbench/contrib/welcomeDialog/browser/media/welcomeDialog.css

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
.monaco-dialog-box {
6+
border-radius: 6px;
7+
}
8+
9+
.welcome-widget {
10+
height: min-content;
11+
border-radius: 6px;
12+
}
13+
14+
.dialog-message-detail-title{
15+
height: 22px;
16+
padding-bottom: 4px;
17+
font-size: large;
18+
}
19+
20+
.monaco-dialog-box .monaco-action-bar .actions-container {
21+
justify-content: flex-end;
22+
}

src/vs/workbench/contrib/welcomeDialog/browser/welcomeDialog.contribution.ts

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,40 @@
55

66
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle';
77
import { Registry } from 'vs/platform/registry/common/platform';
8-
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common/contributions';
9-
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
8+
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution } from 'vs/workbench/common/contributions';
9+
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
1010
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService';
11-
import { IWelcomeDialogService as IWelcomeDialogService } from 'vs/workbench/contrib/welcomeDialog/browser/welcomeDialogService';
1211
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
12+
import { Disposable } from 'vs/base/common/lifecycle';
13+
import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
14+
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService';
15+
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
16+
import { ICommandService } from 'vs/platform/commands/common/commands';
17+
import { WelcomeWidget } from 'vs/workbench/contrib/welcomeDialog/browser/welcomeWidget';
18+
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
1319

1420
const configurationKey = 'welcome.experimental.dialog';
1521

16-
class WelcomeDialogContribution {
22+
class WelcomeDialogContribution extends Disposable implements IWorkbenchContribution {
1723

18-
private static readonly WELCOME_DIALOG_DISMISSED_KEY = 'workbench.dialog.welcome.dismissed';
24+
private contextKeysToWatch = new Set<string>();
1925

2026
constructor(
21-
@IWelcomeDialogService welcomeDialogService: IWelcomeDialogService,
2227
@IStorageService storageService: IStorageService,
2328
@IBrowserWorkbenchEnvironmentService environmentService: IBrowserWorkbenchEnvironmentService,
24-
@IConfigurationService configurationService: IConfigurationService
29+
@IConfigurationService configurationService: IConfigurationService,
30+
@IContextKeyService readonly contextService: IContextKeyService,
31+
@ICodeEditorService readonly codeEditorService: ICodeEditorService,
32+
@IInstantiationService readonly instantiationService: IInstantiationService,
33+
@ICommandService readonly commandService: ICommandService,
34+
@ITelemetryService readonly telemetryService: ITelemetryService
2535
) {
36+
super();
37+
38+
if (!storageService.isNew(StorageScope.PROFILE)) {
39+
return; // do not show if this is not the first session
40+
}
41+
2642
const setting = configurationService.inspect<boolean>(configurationKey);
2743
if (!setting.value) {
2844
return;
@@ -33,19 +49,23 @@ class WelcomeDialogContribution {
3349
return;
3450
}
3551

36-
if (storageService.getBoolean(WelcomeDialogContribution.WELCOME_DIALOG_DISMISSED_KEY + '#' + welcomeDialog.id, StorageScope.PROFILE, false)) {
37-
return;
38-
}
52+
this.contextKeysToWatch.add(welcomeDialog.when);
3953

40-
welcomeDialogService.show({
41-
title: welcomeDialog.title,
42-
buttonText: welcomeDialog.buttonText,
43-
messages: welcomeDialog.messages,
44-
action: welcomeDialog.action,
45-
onClose: () => {
46-
storageService.store(WelcomeDialogContribution.WELCOME_DIALOG_DISMISSED_KEY + '#' + welcomeDialog.id, true, StorageScope.PROFILE, StorageTarget.USER);
54+
this._register(this.contextService.onDidChangeContext(e => {
55+
if (e.affectsSome(this.contextKeysToWatch) &&
56+
Array.from(this.contextKeysToWatch).every(value => this.contextService.contextMatchesRules(ContextKeyExpr.deserialize(value)))) {
57+
const codeEditor = this.codeEditorService.getActiveCodeEditor();
58+
if (codeEditor?.hasModel()) {
59+
const welcomeWidget = new WelcomeWidget(codeEditor, instantiationService, commandService, telemetryService);
60+
welcomeWidget.render(welcomeDialog.title,
61+
welcomeDialog.message,
62+
welcomeDialog.buttonText,
63+
welcomeDialog.buttonCommand,
64+
welcomeDialog.media);
65+
this.contextKeysToWatch.delete(welcomeDialog.when);
66+
}
4767
}
48-
});
68+
}));
4969
}
5070
}
5171

src/vs/workbench/contrib/welcomeDialog/browser/welcomeDialogService.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.

0 commit comments

Comments
 (0)