5
5
6
6
import { LifecyclePhase } from 'vs/workbench/services/lifecycle/common/lifecycle' ;
7
7
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' ;
10
10
import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService' ;
11
- import { IWelcomeDialogService as IWelcomeDialogService } from 'vs/workbench/contrib/welcomeDialog/browser/welcomeDialogService' ;
12
11
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' ;
13
19
14
20
const configurationKey = 'welcome.experimental.dialog' ;
15
21
16
- class WelcomeDialogContribution {
22
+ class WelcomeDialogContribution extends Disposable implements IWorkbenchContribution {
17
23
18
- private static readonly WELCOME_DIALOG_DISMISSED_KEY = 'workbench.dialog.welcome.dismissed' ;
24
+ private contextKeysToWatch = new Set < string > ( ) ;
19
25
20
26
constructor (
21
- @IWelcomeDialogService welcomeDialogService : IWelcomeDialogService ,
22
27
@IStorageService storageService : IStorageService ,
23
28
@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
25
35
) {
36
+ super ( ) ;
37
+
38
+ if ( ! storageService . isNew ( StorageScope . PROFILE ) ) {
39
+ return ; // do not show if this is not the first session
40
+ }
41
+
26
42
const setting = configurationService . inspect < boolean > ( configurationKey ) ;
27
43
if ( ! setting . value ) {
28
44
return ;
@@ -33,19 +49,23 @@ class WelcomeDialogContribution {
33
49
return ;
34
50
}
35
51
36
- if ( storageService . getBoolean ( WelcomeDialogContribution . WELCOME_DIALOG_DISMISSED_KEY + '#' + welcomeDialog . id , StorageScope . PROFILE , false ) ) {
37
- return ;
38
- }
52
+ this . contextKeysToWatch . add ( welcomeDialog . when ) ;
39
53
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
+ }
47
67
}
48
- } ) ;
68
+ } ) ) ;
49
69
}
50
70
}
51
71
0 commit comments