44 *--------------------------------------------------------------------------------------------*/
55
66import 'vs/css!./watermark' ;
7- import { Disposable } from 'vs/base/common/lifecycle' ;
7+ import { Disposable , DisposableStore } from 'vs/base/common/lifecycle' ;
88import { assign } from 'vs/base/common/objects' ;
99import { isMacintosh , OS } from 'vs/base/common/platform' ;
1010import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding' ;
@@ -37,51 +37,17 @@ interface WatermarkEntry {
3737 mac ?: boolean ;
3838}
3939
40- const showCommands : WatermarkEntry = {
41- text : nls . localize ( 'watermark.showCommands' , "Show All Commands" ) ,
42- id : ShowAllCommandsAction . ID
43- } ;
44- const quickOpen : WatermarkEntry = {
45- text : nls . localize ( 'watermark.quickOpen' , "Go to File" ) ,
46- id : QUICKOPEN_ACTION_ID
47- } ;
48- const openFileNonMacOnly : WatermarkEntry = {
49- text : nls . localize ( 'watermark.openFile' , "Open File" ) ,
50- id : OpenFileAction . ID ,
51- mac : false
52- } ;
53- const openFolderNonMacOnly : WatermarkEntry = {
54- text : nls . localize ( 'watermark.openFolder' , "Open Folder" ) ,
55- id : OpenFolderAction . ID ,
56- mac : false
57- } ;
58- const openFileOrFolderMacOnly : WatermarkEntry = {
59- text : nls . localize ( 'watermark.openFileFolder' , "Open File or Folder" ) ,
60- id : OpenFileFolderAction . ID ,
61- mac : true
62- } ;
63- const openRecent : WatermarkEntry = {
64- text : nls . localize ( 'watermark.openRecent' , "Open Recent" ) ,
65- id : 'workbench.action.openRecent'
66- } ;
67- const newUntitledFile : WatermarkEntry = {
68- text : nls . localize ( 'watermark.newUntitledFile' , "New Untitled File" ) ,
69- id : GlobalNewUntitledFileAction . ID
70- } ;
40+ const showCommands : WatermarkEntry = { text : nls . localize ( 'watermark.showCommands' , "Show All Commands" ) , id : ShowAllCommandsAction . ID } ;
41+ const quickOpen : WatermarkEntry = { text : nls . localize ( 'watermark.quickOpen' , "Go to File" ) , id : QUICKOPEN_ACTION_ID } ;
42+ const openFileNonMacOnly : WatermarkEntry = { text : nls . localize ( 'watermark.openFile' , "Open File" ) , id : OpenFileAction . ID , mac : false } ;
43+ const openFolderNonMacOnly : WatermarkEntry = { text : nls . localize ( 'watermark.openFolder' , "Open Folder" ) , id : OpenFolderAction . ID , mac : false } ;
44+ const openFileOrFolderMacOnly : WatermarkEntry = { text : nls . localize ( 'watermark.openFileFolder' , "Open File or Folder" ) , id : OpenFileFolderAction . ID , mac : true } ;
45+ const openRecent : WatermarkEntry = { text : nls . localize ( 'watermark.openRecent' , "Open Recent" ) , id : 'workbench.action.openRecent' } ;
46+ const newUntitledFile : WatermarkEntry = { text : nls . localize ( 'watermark.newUntitledFile' , "New Untitled File" ) , id : GlobalNewUntitledFileAction . ID } ;
7147const newUntitledFileMacOnly : WatermarkEntry = assign ( { mac : true } , newUntitledFile ) ;
72- const toggleTerminal : WatermarkEntry = {
73- text : nls . localize ( { key : 'watermark.toggleTerminal' , comment : [ 'toggle is a verb here' ] } , "Toggle Terminal" ) ,
74- id : TERMINAL_COMMAND_ID . TOGGLE
75- } ;
76-
77- const findInFiles : WatermarkEntry = {
78- text : nls . localize ( 'watermark.findInFiles' , "Find in Files" ) ,
79- id : FindInFilesActionId
80- } ;
81- const startDebugging : WatermarkEntry = {
82- text : nls . localize ( 'watermark.startDebugging' , "Start Debugging" ) ,
83- id : StartAction . ID
84- } ;
48+ const toggleTerminal : WatermarkEntry = { text : nls . localize ( { key : 'watermark.toggleTerminal' , comment : [ 'toggle is a verb here' ] } , "Toggle Terminal" ) , id : TERMINAL_COMMAND_ID . TOGGLE } ;
49+ const findInFiles : WatermarkEntry = { text : nls . localize ( 'watermark.findInFiles' , "Find in Files" ) , id : FindInFilesActionId } ;
50+ const startDebugging : WatermarkEntry = { text : nls . localize ( 'watermark.startDebugging' , "Start Debugging" ) , id : StartAction . ID } ;
8551
8652const noFolderEntries = [
8753 showCommands ,
@@ -103,27 +69,34 @@ const folderEntries = [
10369const WORKBENCH_TIPS_ENABLED_KEY = 'workbench.tips.enabled' ;
10470
10571export class WatermarkContribution extends Disposable implements IWorkbenchContribution {
106-
10772 private watermark : HTMLElement ;
73+ private watermarkDisposable = this . _register ( new DisposableStore ( ) ) ;
10874 private enabled : boolean ;
10975 private workbenchState : WorkbenchState ;
11076
11177 constructor (
112- @ILifecycleService lifecycleService : ILifecycleService ,
78+ @ILifecycleService private readonly lifecycleService : ILifecycleService ,
11379 @IWorkbenchLayoutService private readonly layoutService : IWorkbenchLayoutService ,
11480 @IKeybindingService private readonly keybindingService : IKeybindingService ,
11581 @IWorkspaceContextService private readonly contextService : IWorkspaceContextService ,
11682 @IConfigurationService private readonly configurationService : IConfigurationService ,
11783 @IEditorGroupsService private readonly editorGroupsService : IEditorGroupsService
11884 ) {
11985 super ( ) ;
120- this . workbenchState = contextService . getWorkbenchState ( ) ;
12186
122- lifecycleService . onShutdown ( this . dispose , this ) ;
87+ this . workbenchState = contextService . getWorkbenchState ( ) ;
12388 this . enabled = this . configurationService . getValue < boolean > ( WORKBENCH_TIPS_ENABLED_KEY ) ;
89+
90+ this . registerListeners ( ) ;
91+
12492 if ( this . enabled ) {
12593 this . create ( ) ;
12694 }
95+ }
96+
97+ private registerListeners ( ) : void {
98+ this . lifecycleService . onShutdown ( this . dispose , this ) ;
99+
127100 this . _register ( this . configurationService . onDidChangeConfiguration ( e => {
128101 if ( e . affectsConfiguration ( WORKBENCH_TIPS_ENABLED_KEY ) ) {
129102 const enabled = this . configurationService . getValue < boolean > ( WORKBENCH_TIPS_ENABLED_KEY ) ;
@@ -137,6 +110,7 @@ export class WatermarkContribution extends Disposable implements IWorkbenchContr
137110 }
138111 }
139112 } ) ) ;
113+
140114 this . _register ( this . contextService . onDidChangeWorkbenchState ( e => {
141115 const previousWorkbenchState = this . workbenchState ;
142116 this . workbenchState = this . contextService . getWorkbenchState ( ) ;
@@ -157,6 +131,7 @@ export class WatermarkContribution extends Disposable implements IWorkbenchContr
157131 const selected = folder ? folderEntries : noFolderEntries
158132 . filter ( entry => ! ( 'mac' in entry ) || entry . mac === isMacintosh )
159133 . filter ( entry => ! ! CommandsRegistry . getCommand ( entry . id ) ) ;
134+
160135 const update = ( ) => {
161136 dom . clearNode ( box ) ;
162137 selected . map ( entry => {
@@ -169,10 +144,14 @@ export class WatermarkContribution extends Disposable implements IWorkbenchContr
169144 dd . innerHTML = keybinding . element . outerHTML ;
170145 } ) ;
171146 } ;
147+
172148 update ( ) ;
149+
173150 dom . prepend ( container . firstElementChild as HTMLElement , this . watermark ) ;
174- this . _register ( this . keybindingService . onDidUpdateKeybindings ( update ) ) ;
175- this . _register ( this . editorGroupsService . onDidLayout ( dimension => this . handleEditorPartSize ( container , dimension ) ) ) ;
151+
152+ this . watermarkDisposable . add ( this . keybindingService . onDidUpdateKeybindings ( update ) ) ;
153+ this . watermarkDisposable . add ( this . editorGroupsService . onDidLayout ( dimension => this . handleEditorPartSize ( container , dimension ) ) ) ;
154+
176155 this . handleEditorPartSize ( container , this . editorGroupsService . contentDimension ) ;
177156 }
178157
@@ -187,9 +166,11 @@ export class WatermarkContribution extends Disposable implements IWorkbenchContr
187166 private destroy ( ) : void {
188167 if ( this . watermark ) {
189168 this . watermark . remove ( ) ;
169+
190170 const container = this . layoutService . getContainer ( Parts . EDITOR_PART ) ;
191171 container . classList . remove ( 'has-watermark' ) ;
192- this . dispose ( ) ;
172+
173+ this . watermarkDisposable . clear ( ) ;
193174 }
194175 }
195176
0 commit comments