@@ -15,43 +15,36 @@ import { IModeService } from 'vs/editor/common/services/modeService';
1515import { IQuickOpenService , IPickOpenEntry } from 'vs/platform/quickOpen/common/quickOpen' ;
1616import { IWindowsService } from 'vs/platform/windows/common/windows' ;
1717import { join } from 'path' ;
18- import { SyncActionDescriptor } from 'vs/platform/actions/common/actions' ;
19- import * as actions from 'vs/base/ common/actions ' ;
18+ import { MenuRegistry , MenuId } from 'vs/platform/actions/common/actions' ;
19+ import { CommandsRegistry } from 'vs/platform/commands/ common/commands ' ;
2020import * as errors from 'vs/base/common/errors' ;
2121import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry' ;
2222import * as nls from 'vs/nls' ;
2323import * as platform from 'vs/platform/registry/common/platform' ;
2424import * as snippetsTracker from './snippetsTracker' ;
2525import * as tmSnippets from './TMSnippets' ;
2626import * as winjs from 'vs/base/common/winjs.base' ;
27- import * as workbenchActionRegistry from 'vs/workbench/common/actionRegistry' ;
2827import * as workbenchContributions from 'vs/workbench/common/contributions' ;
2928
30- class OpenSnippetsAction extends actions . Action {
29+ namespace OpenSnippetsAction {
3130
32- public static ID = 'workbench.action.openSnippets' ;
33- public static LABEL = nls . localize ( 'openSnippet.label' , "Open User Snippets" ) ;
31+ const id = 'workbench.action.openSnippets' ;
3432
35- constructor (
36- id : string ,
37- label : string ,
38- @IEnvironmentService private environmentService : IEnvironmentService ,
39- @IQuickOpenService private quickOpenService : IQuickOpenService ,
40- @IModeService private modeService : IModeService ,
41- @IWindowsService private windowsService : IWindowsService
42- ) {
43- super ( id , label ) ;
44- }
33+ CommandsRegistry . registerCommand ( id , accessor => {
4534
46- private openFile ( filePath : string ) : winjs . TPromise < void > {
47- return this . windowsService . openWindow ( [ filePath ] , { forceReuseWindow : true } ) ;
48- }
35+ const modeService = accessor . get ( IModeService ) ;
36+ const quickOpenService = accessor . get ( IQuickOpenService ) ;
37+ const environmentService = accessor . get ( IEnvironmentService ) ;
38+ const windowsService = accessor . get ( IWindowsService ) ;
4939
50- public run ( ) : winjs . Promise {
51- var modeIds = this . modeService . getRegisteredModes ( ) ;
40+ function openFile ( filePath : string ) : winjs . TPromise < void > {
41+ return windowsService . openWindow ( [ filePath ] , { forceReuseWindow : true } ) ;
42+ }
43+
44+ var modeIds = modeService . getRegisteredModes ( ) ;
5245 var picks : IPickOpenEntry [ ] = [ ] ;
5346 modeIds . forEach ( ( modeId ) => {
54- var name = this . modeService . getLanguageName ( modeId ) ;
47+ var name = modeService . getLanguageName ( modeId ) ;
5548 if ( name ) {
5649 picks . push ( { label : name , id : modeId } ) ;
5750 }
@@ -60,12 +53,12 @@ class OpenSnippetsAction extends actions.Action {
6053 e1 . label . localeCompare ( e2 . label )
6154 ) ;
6255
63- return this . quickOpenService . pick ( picks , { placeHolder : nls . localize ( 'openSnippet.pickLanguage' , "Select Language for Snippet" ) } ) . then ( ( language ) => {
56+ return quickOpenService . pick ( picks , { placeHolder : nls . localize ( 'openSnippet.pickLanguage' , "Select Language for Snippet" ) } ) . then ( ( language ) => {
6457 if ( language ) {
65- var snippetPath = join ( this . environmentService . appSettingsHome , 'snippets' , language . id + '.json' ) ;
58+ var snippetPath = join ( environmentService . appSettingsHome , 'snippets' , language . id + '.json' ) ;
6659 return fileExists ( snippetPath ) . then ( ( success ) => {
6760 if ( success ) {
68- return this . openFile ( snippetPath ) ;
61+ return openFile ( snippetPath ) ;
6962 }
7063 var defaultContent = [
7164 '{' ,
@@ -87,21 +80,24 @@ class OpenSnippetsAction extends actions.Action {
8780 '}'
8881 ] . join ( '\n' ) ;
8982 return writeFile ( snippetPath , defaultContent ) . then ( ( ) => {
90- return this . openFile ( snippetPath ) ;
83+ return openFile ( snippetPath ) ;
9184 } , ( err ) => {
9285 errors . onUnexpectedError ( nls . localize ( 'openSnippet.errorOnCreate' , 'Unable to create {0}' , snippetPath ) ) ;
9386 } ) ;
9487 } ) ;
9588 }
9689 return winjs . TPromise . as ( null ) ;
9790 } ) ;
98- }
99- }
100-
101- var preferencesCategory = nls . localize ( 'preferences' , "Preferences" ) ;
102- var workbenchActionsRegistry = < workbenchActionRegistry . IWorkbenchActionRegistry > platform . Registry . as ( workbenchActionRegistry . Extensions . WorkbenchActions ) ;
91+ } ) ;
10392
104- workbenchActionsRegistry . registerWorkbenchAction ( new SyncActionDescriptor ( OpenSnippetsAction , OpenSnippetsAction . ID , OpenSnippetsAction . LABEL ) , 'Preferences: Open User Snippets' , preferencesCategory ) ;
93+ MenuRegistry . appendMenuItem ( MenuId . CommandPalette , {
94+ command : {
95+ id,
96+ title : { value : nls . localize ( 'openSnippet.label' , "Open User Snippets" ) , original : 'Preferences: Open User Snippets' } ,
97+ category : nls . localize ( 'preferences' , "Preferences" )
98+ }
99+ } ) ;
100+ }
105101
106102( < workbenchContributions . IWorkbenchContributionsRegistry > platform . Registry . as ( workbenchContributions . Extensions . Workbench ) ) . registerWorkbenchContribution (
107103 snippetsTracker . SnippetsTracker
0 commit comments