@@ -9,11 +9,14 @@ import {
9
9
KeybindingRegistry ,
10
10
CommandRegistry ,
11
11
} from './contribution' ;
12
- import { ArduinoMenus } from '../menu/arduino-menus' ;
13
- import { nls } from '@theia/core/lib/common' ;
12
+ import { ArduinoMenus , PlaceholderMenuNode } from '../menu/arduino-menus' ;
13
+ import { DisposableCollection , nls } from '@theia/core/lib/common' ;
14
14
import type { ICodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/browser/editorBrowser' ;
15
15
import type { StandaloneCodeEditor } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneCodeEditor' ;
16
16
17
+ import { Settings } from '../dialogs/settings/settings' ;
18
+ import { MainMenuManager } from '../../common/main-menu-manager' ;
19
+
17
20
// TODO: [macOS]: to remove `Start Dictation...` and `Emoji & Symbol` see this thread: https://github.com/electron/electron/issues/8283#issuecomment-269522072
18
21
// Depends on https://github.com/eclipse-theia/theia/pull/7964
19
22
@injectable ( )
@@ -24,6 +27,39 @@ export class EditContributions extends Contribution {
24
27
@inject ( ClipboardService )
25
28
private readonly clipboardService : ClipboardService ;
26
29
30
+ @inject ( MenuModelRegistry )
31
+ private readonly menuRegistry : MenuModelRegistry ;
32
+
33
+ @inject ( MainMenuManager )
34
+ protected readonly mainMenuManager : MainMenuManager ;
35
+
36
+ private readonly menuActionsDisposables = new DisposableCollection ( ) ;
37
+ private fontScalingEnabled : EditContributions . FontScalingEnabled = {
38
+ increase : true ,
39
+ decrease : true ,
40
+ } ;
41
+
42
+ private checkInterfaceScaleMenuActions ( settings : Settings ) : void {
43
+ let newFontScalingEnabled : EditContributions . FontScalingEnabled = {
44
+ increase : true ,
45
+ decrease : true ,
46
+ } ;
47
+ if ( settings . autoScaleInterface ) {
48
+ newFontScalingEnabled = {
49
+ increase : settings . interfaceScale < EditContributions . ZoomLevel . MAX ,
50
+ decrease : settings . interfaceScale > EditContributions . ZoomLevel . MIN ,
51
+ } ;
52
+ }
53
+ const isChanged = Object . keys ( newFontScalingEnabled ) . some (
54
+ ( key : keyof EditContributions . FontScalingEnabled ) =>
55
+ newFontScalingEnabled [ key ] !== this . fontScalingEnabled [ key ]
56
+ ) ;
57
+ if ( isChanged ) {
58
+ this . registerInterfaceScaleMenuActions ( newFontScalingEnabled ) ;
59
+ }
60
+ this . fontScalingEnabled = newFontScalingEnabled ;
61
+ }
62
+
27
63
override registerCommands ( registry : CommandRegistry ) : void {
28
64
registry . registerCommand ( EditContributions . Commands . GO_TO_LINE , {
29
65
execute : ( ) => this . run ( 'editor.action.gotoLine' ) ,
@@ -59,7 +95,9 @@ export class EditContributions extends Contribution {
59
95
}
60
96
await this . settingsService . update ( settings ) ;
61
97
await this . settingsService . save ( ) ;
98
+ this . checkInterfaceScaleMenuActions ( settings ) ;
62
99
} ,
100
+ isEnabled : ( ) => this . fontScalingEnabled . increase ,
63
101
} ) ;
64
102
registry . registerCommand ( EditContributions . Commands . DECREASE_FONT_SIZE , {
65
103
execute : async ( ) => {
@@ -71,7 +109,9 @@ export class EditContributions extends Contribution {
71
109
}
72
110
await this . settingsService . update ( settings ) ;
73
111
await this . settingsService . save ( ) ;
112
+ this . checkInterfaceScaleMenuActions ( settings ) ;
74
113
} ,
114
+ isEnabled : ( ) => this . fontScalingEnabled . decrease ,
75
115
} ) ;
76
116
/* Tools */ registry . registerCommand (
77
117
EditContributions . Commands . AUTO_FORMAT ,
@@ -147,23 +187,6 @@ ${value}
147
187
order : '3' ,
148
188
} ) ;
149
189
150
- registry . registerMenuAction ( ArduinoMenus . EDIT__FONT_CONTROL_GROUP , {
151
- commandId : EditContributions . Commands . INCREASE_FONT_SIZE . id ,
152
- label : nls . localize (
153
- 'arduino/editor/increaseFontSize' ,
154
- 'Increase Font Size'
155
- ) ,
156
- order : '0' ,
157
- } ) ;
158
- registry . registerMenuAction ( ArduinoMenus . EDIT__FONT_CONTROL_GROUP , {
159
- commandId : EditContributions . Commands . DECREASE_FONT_SIZE . id ,
160
- label : nls . localize (
161
- 'arduino/editor/decreaseFontSize' ,
162
- 'Decrease Font Size'
163
- ) ,
164
- order : '1' ,
165
- } ) ;
166
-
167
190
registry . registerMenuAction ( ArduinoMenus . EDIT__FIND_GROUP , {
168
191
commandId : EditContributions . Commands . FIND . id ,
169
192
label : nls . localize ( 'vscode/findController/startFindAction' , 'Find' ) ,
@@ -200,6 +223,70 @@ ${value}
200
223
label : nls . localize ( 'arduino/editor/autoFormat' , 'Auto Format' ) , // XXX: The Java IDE uses `Use Selection For Find`.
201
224
order : '0' ,
202
225
} ) ;
226
+
227
+ this . registerInterfaceScaleMenuActions ( ) ;
228
+ }
229
+
230
+ private registerInterfaceScaleMenuActions (
231
+ newFontScalingEnabled = this . fontScalingEnabled
232
+ ) : void {
233
+ this . menuActionsDisposables . dispose ( ) ;
234
+ const increaseFontSizeMenuAction = {
235
+ commandId : EditContributions . Commands . INCREASE_FONT_SIZE . id ,
236
+ label : nls . localize (
237
+ 'arduino/editor/increaseFontSize' ,
238
+ 'Increase Font Size'
239
+ ) ,
240
+ order : '0' ,
241
+ } ;
242
+ const decreaseFontSizeMenuAction = {
243
+ commandId : EditContributions . Commands . DECREASE_FONT_SIZE . id ,
244
+ label : nls . localize (
245
+ 'arduino/editor/decreaseFontSize' ,
246
+ 'Decrease Font Size'
247
+ ) ,
248
+ order : '1' ,
249
+ } ;
250
+
251
+ if ( newFontScalingEnabled . increase ) {
252
+ this . menuActionsDisposables . push (
253
+ this . menuRegistry . registerMenuAction (
254
+ ArduinoMenus . EDIT__FONT_CONTROL_GROUP ,
255
+ increaseFontSizeMenuAction
256
+ )
257
+ ) ;
258
+ } else {
259
+ this . menuActionsDisposables . push (
260
+ this . menuRegistry . registerMenuNode (
261
+ ArduinoMenus . EDIT__FONT_CONTROL_GROUP ,
262
+ new PlaceholderMenuNode (
263
+ ArduinoMenus . EDIT__FONT_CONTROL_GROUP ,
264
+ increaseFontSizeMenuAction . label ,
265
+ { order : increaseFontSizeMenuAction . order }
266
+ )
267
+ )
268
+ ) ;
269
+ }
270
+ if ( newFontScalingEnabled . decrease ) {
271
+ this . menuActionsDisposables . push (
272
+ this . menuRegistry . registerMenuAction (
273
+ ArduinoMenus . EDIT__FONT_CONTROL_GROUP ,
274
+ decreaseFontSizeMenuAction
275
+ )
276
+ ) ;
277
+ } else {
278
+ this . menuActionsDisposables . push (
279
+ this . menuRegistry . registerMenuNode (
280
+ ArduinoMenus . EDIT__FONT_CONTROL_GROUP ,
281
+ new PlaceholderMenuNode (
282
+ ArduinoMenus . EDIT__FONT_CONTROL_GROUP ,
283
+ decreaseFontSizeMenuAction . label ,
284
+ { order : decreaseFontSizeMenuAction . order }
285
+ )
286
+ )
287
+ ) ;
288
+ }
289
+ this . mainMenuManager . update ( ) ;
203
290
}
204
291
205
292
override registerKeybindings ( registry : KeybindingRegistry ) : void {
@@ -325,4 +412,14 @@ export namespace EditContributions {
325
412
id : 'arduino-auto-format' , // `Auto Format` should belong to `Tool`.
326
413
} ;
327
414
}
415
+
416
+ export namespace ZoomLevel {
417
+ export const MIN = - 8 ;
418
+ export const MAX = 9 ;
419
+ }
420
+
421
+ export interface FontScalingEnabled {
422
+ increase : boolean ;
423
+ decrease : boolean ;
424
+ }
328
425
}
0 commit comments