- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathinterface-scale.ts
173 lines (158 loc) · 5.2 KB
/
interface-scale.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import{injectable}from'@theia/core/shared/inversify';
import{
Contribution,
Command,
MenuModelRegistry,
KeybindingRegistry,
}from'./contribution';
import{ArduinoMenus}from'../menu/arduino-menus';
import{CommandRegistry,MaybePromise,nls}from'@theia/core/lib/common';
import{Settings}from'../dialogs/settings/settings';
importdebouncefrom'lodash.debounce';
@injectable()
exportclassInterfaceScaleextendsContribution{
privatefontScalingEnabled: InterfaceScale.FontScalingEnabled={
increase: true,
decrease: true,
};
privatecurrentSettings: Settings;
privateupdateSettingsDebounced=debounce(
async()=>{
awaitthis.settingsService.update(this.currentSettings);
awaitthis.settingsService.save();
},
100,
{maxWait: 200}
);
overrideonStart(): MaybePromise<void>{
constupdateCurrent=(settings: Settings)=>{
this.currentSettings=settings;
this.updateFontScalingEnabled();
};
this.settingsService.onDidChange((settings)=>updateCurrent(settings));
this.settingsService.settings().then((settings)=>updateCurrent(settings));
}
overrideregisterCommands(registry: CommandRegistry): void{
registry.registerCommand(InterfaceScale.Commands.INCREASE_FONT_SIZE,{
execute: ()=>this.updateFontSize('increase'),
isEnabled: ()=>this.fontScalingEnabled.increase,
});
registry.registerCommand(InterfaceScale.Commands.DECREASE_FONT_SIZE,{
execute: ()=>this.updateFontSize('decrease'),
isEnabled: ()=>this.fontScalingEnabled.decrease,
});
}
overrideregisterMenus(registry: MenuModelRegistry): void{
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP,{
commandId: InterfaceScale.Commands.INCREASE_FONT_SIZE.id,
label: nls.localize(
'arduino/editor/increaseFontSize',
'Increase Font Size'
),
order: '0',
});
registry.registerMenuAction(ArduinoMenus.EDIT__FONT_CONTROL_GROUP,{
commandId: InterfaceScale.Commands.DECREASE_FONT_SIZE.id,
label: nls.localize(
'arduino/editor/decreaseFontSize',
'Decrease Font Size'
),
order: '1',
});
}
privateupdateFontScalingEnabled(): void{
letfontScalingEnabled={
increase: true,
decrease: true,
};
if(this.currentSettings.autoScaleInterface){
fontScalingEnabled={
increase:
this.currentSettings.interfaceScale+InterfaceScale.ZoomLevel.STEP<=
InterfaceScale.ZoomLevel.MAX,
decrease:
this.currentSettings.interfaceScale-InterfaceScale.ZoomLevel.STEP>=
InterfaceScale.ZoomLevel.MIN,
};
}else{
fontScalingEnabled={
increase:
this.currentSettings.editorFontSize+InterfaceScale.FontSize.STEP<=
InterfaceScale.FontSize.MAX,
decrease:
this.currentSettings.editorFontSize-InterfaceScale.FontSize.STEP>=
InterfaceScale.FontSize.MIN,
};
}
constisChanged=Object.keys(fontScalingEnabled).some(
(key: keyofInterfaceScale.FontScalingEnabled)=>
fontScalingEnabled[key]!==this.fontScalingEnabled[key]
);
if(isChanged){
this.fontScalingEnabled=fontScalingEnabled;
this.menuManager.update();
}
}
privateupdateFontSize(mode: 'increase'|'decrease'): void{
if(this.currentSettings.autoScaleInterface){
mode==='increase'
? (this.currentSettings.interfaceScale+=InterfaceScale.ZoomLevel.STEP)
: (this.currentSettings.interfaceScale-=
InterfaceScale.ZoomLevel.STEP);
}else{
mode==='increase'
? (this.currentSettings.editorFontSize+=InterfaceScale.FontSize.STEP)
: (this.currentSettings.editorFontSize-=InterfaceScale.FontSize.STEP);
}
this.updateFontScalingEnabled();
this.updateSettingsDebounced();
}
overrideregisterKeybindings(registry: KeybindingRegistry): void{
registry.registerKeybinding({
command: InterfaceScale.Commands.INCREASE_FONT_SIZE.id,
keybinding: 'CtrlCmd+=',
});
registry.registerKeybinding({
command: InterfaceScale.Commands.DECREASE_FONT_SIZE.id,
keybinding: 'CtrlCmd+-',
});
}
}
exportnamespaceInterfaceScale{
exportnamespaceCommands{
exportconstINCREASE_FONT_SIZE: Command={
id: 'arduino-increase-font-size',
};
exportconstDECREASE_FONT_SIZE: Command={
id: 'arduino-decrease-font-size',
};
}
exportnamespaceZoomLevel{
exportconstMIN=-8;
exportconstMAX=9;
exportconstSTEP=1;
exportfunctiontoPercentage(scale: number): number{
returnscale*20+100;
}
exportfunctionfromPercentage(percentage: number): number{
return(percentage-100)/20;
}
exportnamespaceStep{
exportfunctiontoPercentage(step: number): number{
returnstep*20;
}
exportfunctionfromPercentage(percentage: number): number{
returnpercentage/20;
}
}
}
exportnamespaceFontSize{
exportconstMIN=8;
exportconstMAX=72;
exportconstSTEP=2;
}
exportinterfaceFontScalingEnabled{
increase: boolean;
decrease: boolean;
}
}