33 * Licensed under the MIT License. See License.txt in the project root for license information.
44 *--------------------------------------------------------------------------------------------*/
55
6- import { KeyCode , KeyCodeUtils , Keybinding , ResolvedKeybinding , ResolvedKeybindingPart , SimpleKeybinding } from 'vs/base/common/keyCodes' ;
7- import { AriaLabelProvider , ElectronAcceleratorLabelProvider , UILabelProvider , UserSettingsLabelProvider } from 'vs/base/common/keybindingLabels' ;
6+ import { KeyCode , KeyCodeUtils , Keybinding , SimpleKeybinding , BaseResolvedKeybinding } from 'vs/base/common/keyCodes' ;
87import { OperatingSystem } from 'vs/base/common/platform' ;
98
109/**
1110 * Do not instantiate. Use KeybindingService to get a ResolvedKeybinding seeded with information about the current kb layout.
1211 */
13- export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
14-
15- private readonly _os : OperatingSystem ;
16- private readonly _parts : SimpleKeybinding [ ] ;
17-
18- constructor ( actual : Keybinding , OS : OperatingSystem ) {
19- super ( ) ;
20- this . _os = OS ;
21- if ( ! actual ) {
22- throw new Error ( `Invalid USLayoutResolvedKeybinding` ) ;
23- } else {
24- this . _parts = actual . parts ;
25- }
12+ export class USLayoutResolvedKeybinding extends BaseResolvedKeybinding < SimpleKeybinding > {
13+
14+ constructor ( actual : Keybinding , os : OperatingSystem ) {
15+ super ( os , actual . parts ) ;
2616 }
2717
2818 private _keyCodeToUILabel ( keyCode : KeyCode ) : string {
@@ -41,34 +31,20 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
4131 return KeyCodeUtils . toString ( keyCode ) ;
4232 }
4333
44- private _getUILabelForKeybinding ( keybinding : SimpleKeybinding | null ) : string | null {
45- if ( ! keybinding ) {
46- return null ;
47- }
34+ protected _getLabel ( keybinding : SimpleKeybinding ) : string | null {
4835 if ( keybinding . isDuplicateModifierCase ( ) ) {
4936 return '' ;
5037 }
5138 return this . _keyCodeToUILabel ( keybinding . keyCode ) ;
5239 }
5340
54- public getLabel ( ) : string | null {
55- return UILabelProvider . toLabel ( this . _os , this . _parts , ( keybinding ) => this . _getUILabelForKeybinding ( keybinding ) ) ;
56- }
57-
58- private _getAriaLabelForKeybinding ( keybinding : SimpleKeybinding | null ) : string | null {
59- if ( ! keybinding ) {
60- return null ;
61- }
41+ protected _getAriaLabel ( keybinding : SimpleKeybinding ) : string | null {
6242 if ( keybinding . isDuplicateModifierCase ( ) ) {
6343 return '' ;
6444 }
6545 return KeyCodeUtils . toString ( keybinding . keyCode ) ;
6646 }
6747
68- public getAriaLabel ( ) : string | null {
69- return AriaLabelProvider . toLabel ( this . _os , this . _parts , ( keybinding ) => this . _getAriaLabelForKeybinding ( keybinding ) ) ;
70- }
71-
7248 private _keyCodeToElectronAccelerator ( keyCode : KeyCode ) : string | null {
7349 if ( keyCode >= KeyCode . NUMPAD_0 && keyCode <= KeyCode . NUMPAD_DIVIDE ) {
7450 // Electron cannot handle numpad keys
@@ -89,65 +65,27 @@ export class USLayoutResolvedKeybinding extends ResolvedKeybinding {
8965 return KeyCodeUtils . toString ( keyCode ) ;
9066 }
9167
92- private _getElectronAcceleratorLabelForKeybinding ( keybinding : SimpleKeybinding | null ) : string | null {
93- if ( ! keybinding ) {
94- return null ;
95- }
68+ protected _getElectronAccelerator ( keybinding : SimpleKeybinding ) : string | null {
9669 if ( keybinding . isDuplicateModifierCase ( ) ) {
9770 return null ;
9871 }
9972 return this . _keyCodeToElectronAccelerator ( keybinding . keyCode ) ;
10073 }
10174
102- public getElectronAccelerator ( ) : string | null {
103- if ( this . _parts . length > 1 ) {
104- // Electron cannot handle chords
105- return null ;
106- }
107-
108- return ElectronAcceleratorLabelProvider . toLabel ( this . _os , this . _parts , ( keybinding ) => this . _getElectronAcceleratorLabelForKeybinding ( keybinding ) ) ;
109- }
110-
111- private _getUserSettingsLabelForKeybinding ( keybinding : SimpleKeybinding | null ) : string | null {
112- if ( ! keybinding ) {
113- return null ;
114- }
75+ protected _getUserSettingsLabel ( keybinding : SimpleKeybinding ) : string | null {
11576 if ( keybinding . isDuplicateModifierCase ( ) ) {
11677 return '' ;
11778 }
118- return KeyCodeUtils . toUserSettingsUS ( keybinding . keyCode ) ;
119- }
120-
121- public getUserSettingsLabel ( ) : string | null {
122- const result = UserSettingsLabelProvider . toLabel ( this . _os , this . _parts , ( keybinding ) => this . _getUserSettingsLabelForKeybinding ( keybinding ) ) ;
79+ const result = KeyCodeUtils . toUserSettingsUS ( keybinding . keyCode ) ;
12380 return ( result ? result . toLowerCase ( ) : result ) ;
12481 }
12582
126- public isWYSIWYG ( ) : boolean {
83+ protected _isWYSIWYG ( ) : boolean {
12784 return true ;
12885 }
12986
130- public isChord ( ) : boolean {
131- return ( this . _parts . length > 1 ) ;
132- }
133-
134- public getParts ( ) : ResolvedKeybindingPart [ ] {
135- return this . _parts . map ( ( keybinding ) => this . _toResolvedKeybindingPart ( keybinding ) ) ;
136- }
137-
138- private _toResolvedKeybindingPart ( keybinding : SimpleKeybinding ) : ResolvedKeybindingPart {
139- return new ResolvedKeybindingPart (
140- keybinding . ctrlKey ,
141- keybinding . shiftKey ,
142- keybinding . altKey ,
143- keybinding . metaKey ,
144- this . _getUILabelForKeybinding ( keybinding ) ,
145- this . _getAriaLabelForKeybinding ( keybinding )
146- ) ;
147- }
148-
149- public getDispatchParts ( ) : ( string | null ) [ ] {
150- return this . _parts . map ( ( keybinding ) => USLayoutResolvedKeybinding . getDispatchStr ( keybinding ) ) ;
87+ protected _getDispatchPart ( keybinding : SimpleKeybinding ) : string | null {
88+ return USLayoutResolvedKeybinding . getDispatchStr ( keybinding ) ;
15189 }
15290
15391 public static getDispatchStr ( keybinding : SimpleKeybinding ) : string | null {
0 commit comments