@@ -23,33 +23,96 @@ export const Command = ConfigBasicCommand;
2323export const EditorCommand = ConfigEditorCommand ;
2424export type ICommandOptions = ICommandOptions ;
2525
26- // --- Keybinding extensions to make it more concise to express keybindings conditions
2726export interface IEditorCommandMenuOptions {
2827 group ?: string ;
2928 order ?: number ;
3029}
30+ export interface IActionOptions extends ICommandOptions {
31+ label : string ;
32+ alias : string ;
33+ menuOpts ?: IEditorCommandMenuOptions ;
34+ }
35+ export abstract class EditorAction extends ConfigEditorCommand {
36+
37+ public label : string ;
38+ public alias : string ;
39+ private menuOpts : IEditorCommandMenuOptions ;
40+
41+ constructor ( opts :IActionOptions ) {
42+ super ( opts ) ;
43+ this . label = opts . label ;
44+ this . alias = opts . alias ;
45+ this . menuOpts = opts . menuOpts ;
46+ }
47+
48+ public toMenuItem ( ) : IMenuItem {
49+ if ( ! this . menuOpts ) {
50+ return null ;
51+ }
52+
53+ return {
54+ command : {
55+ id : this . id ,
56+ title : this . label
57+ } ,
58+ when : this . precondition ,
59+ group : this . menuOpts . group ,
60+ order : this . menuOpts . order
61+ } ;
62+ }
63+
64+ public runEditorCommand ( accessor :ServicesAccessor , editor : editorCommon . ICommonCodeEditor , args : any ) : void | TPromise < void > {
65+ accessor . get ( ITelemetryService ) . publicLog ( 'editorActionInvoked' , { name : this . label , id : this . id } ) ;
66+ return this . run ( accessor , editor ) ;
67+ }
68+
69+ public abstract run ( accessor :ServicesAccessor , editor :editorCommon . ICommonCodeEditor ) : void | TPromise < void > ;
70+ }
71+
72+ export interface IHandlerActionOptions extends IActionOptions {
73+ handlerId : string ;
74+ }
75+ export abstract class HandlerEditorAction extends EditorAction {
76+ private _handlerId : string ;
77+
78+ constructor ( opts : IHandlerActionOptions ) {
79+ super ( opts ) ;
80+ this . _handlerId = opts . handlerId ;
81+ }
82+
83+ public run ( accessor :ServicesAccessor , editor :editorCommon . ICommonCodeEditor ) : void {
84+ editor . trigger ( this . id , this . _handlerId , null ) ;
85+ }
86+ }
3187
3288// --- Editor Actions
3389
90+ export function editorAction ( constructor :{ new ( ) : EditorAction ; } ) : void {
91+ CommonEditorRegistry . registerEditorAction ( new constructor ( ) ) ;
92+ }
93+
3494export module CommonEditorRegistry {
3595
96+ // --- Editor Actions
97+
3698 export function registerEditorAction ( desc :EditorAction ) {
37- ( < EditorContributionRegistry > Registry . as ( Extensions . EditorCommonContributions ) ) . registerEditorAction ( desc ) ;
99+ EditorContributionRegistry . INSTANCE . registerEditorAction ( desc ) ;
38100 }
39-
40101 export function getEditorActions ( ) : EditorAction [ ] {
41- return ( < EditorContributionRegistry > Registry . as ( Extensions . EditorCommonContributions ) ) . getEditorActions ( ) ;
102+ return EditorContributionRegistry . INSTANCE . getEditorActions ( ) ;
42103 }
43104
44105 // --- Editor Contributions
106+
45107 export function registerEditorContribution ( ctor :editorCommon . ICommonEditorContributionCtor ) : void {
46- ( < EditorContributionRegistry > Registry . as ( Extensions . EditorCommonContributions ) ) . registerEditorContribution ( ctor ) ;
108+ EditorContributionRegistry . INSTANCE . registerEditorContribution ( ctor ) ;
47109 }
48110 export function getEditorContributions ( ) : editorCommon . ICommonEditorContributionDescriptor [ ] {
49- return ( < EditorContributionRegistry > Registry . as ( Extensions . EditorCommonContributions ) ) . getEditorContributions ( ) ;
111+ return EditorContributionRegistry . INSTANCE . getEditorContributions ( ) ;
50112 }
51113
52114 // --- Editor Commands
115+
53116 export function commandWeight ( importance : number = 0 ) : number {
54117 return KeybindingsRegistry . WEIGHT . editorContrib ( importance ) ;
55118 }
@@ -101,6 +164,8 @@ var Extensions = {
101164
102165class EditorContributionRegistry {
103166
167+ public static INSTANCE = new EditorContributionRegistry ( ) ;
168+
104169 private editorContributions : editorCommon . ICommonEditorContributionDescriptor [ ] ;
105170 private editorActions : EditorAction [ ] ;
106171
@@ -133,64 +198,4 @@ class EditorContributionRegistry {
133198 return this . editorActions . slice ( 0 ) ;
134199 }
135200}
136- Registry . add ( Extensions . EditorCommonContributions , new EditorContributionRegistry ( ) ) ;
137-
138- export interface IActionOptions extends ICommandOptions {
139- label : string ;
140- alias : string ;
141- menuOpts ?: IEditorCommandMenuOptions ;
142- }
143-
144- export abstract class EditorAction extends ConfigEditorCommand {
145-
146- public label : string ;
147- public alias : string ;
148- private menuOpts : IEditorCommandMenuOptions ;
149-
150- constructor ( opts :IActionOptions ) {
151- super ( opts ) ;
152- this . label = opts . label ;
153- this . alias = opts . alias ;
154- this . menuOpts = opts . menuOpts ;
155- }
156-
157- public toMenuItem ( ) : IMenuItem {
158- if ( ! this . menuOpts ) {
159- return null ;
160- }
161-
162- return {
163- command : {
164- id : this . id ,
165- title : this . label
166- } ,
167- when : this . precondition ,
168- group : this . menuOpts . group ,
169- order : this . menuOpts . order
170- } ;
171- }
172-
173- public runEditorCommand ( accessor :ServicesAccessor , editor : editorCommon . ICommonCodeEditor , args : any ) : void | TPromise < void > {
174- accessor . get ( ITelemetryService ) . publicLog ( 'editorActionInvoked' , { name : this . label , id : this . id } ) ;
175- return this . run ( accessor , editor ) ;
176- }
177-
178- public abstract run ( accessor :ServicesAccessor , editor :editorCommon . ICommonCodeEditor ) : void | TPromise < void > ;
179- }
180-
181- export interface IHandlerActionOptions extends IActionOptions {
182- handlerId : string ;
183- }
184-
185- export abstract class HandlerEditorAction extends EditorAction {
186- private _handlerId : string ;
187-
188- constructor ( opts : IHandlerActionOptions ) {
189- super ( opts ) ;
190- this . _handlerId = opts . handlerId ;
191- }
192-
193- public run ( accessor :ServicesAccessor , editor :editorCommon . ICommonCodeEditor ) : void {
194- editor . trigger ( this . id , this . _handlerId , null ) ;
195- }
196- }
201+ Registry . add ( Extensions . EditorCommonContributions , EditorContributionRegistry . INSTANCE ) ;
0 commit comments