Skip to content

Commit 46c394d

Browse files
author
Akos Kitta
committed
get rid of old editor mode. use a preference.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 0ae8de7 commit 46c394d

9 files changed

+71
-84
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

-16
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ import { BoardsToolBarItem } from './boards/boards-toolbar-item';
6464
import { OpenSketchFiles } from './contributions/open-sketch-files';
6565
import { SaveAsSketch } from './contributions/save-as-sketch';
6666
import { IDEUpdaterDialog } from './dialogs/ide-updater/ide-updater-dialog';
67-
import { EditorMode } from './editor-mode';
6867
import { ArduinoMenus } from './menu/arduino-menus';
6968
import { MonitorViewContribution } from './serial/monitor/monitor-view-contribution';
7069
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
@@ -108,9 +107,6 @@ export class ArduinoFrontendContribution
108107
@inject(StatusBar)
109108
private readonly statusBar: StatusBar;
110109

111-
@inject(EditorMode)
112-
private readonly editorMode: EditorMode;
113-
114110
@inject(ArduinoPreferences)
115111
private readonly arduinoPreferences: ArduinoPreferences;
116112

@@ -328,10 +324,6 @@ export class ArduinoFrontendContribution
328324
}
329325

330326
registerCommands(registry: CommandRegistry): void {
331-
registry.registerCommand(ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG, {
332-
execute: () => this.editorMode.toggleCompileForDebug(),
333-
isToggled: () => this.editorMode.compileForDebug,
334-
});
335327
registry.registerCommand(ArduinoCommands.OPEN_BOARDS_DIALOG, {
336328
execute: async (query?: string | undefined) => {
337329
const boardsConfig = await this.boardsConfigDialog.open(query);
@@ -373,14 +365,6 @@ export class ArduinoFrontendContribution
373365
ArduinoMenus.TOOLS,
374366
nls.localize('arduino/menu/tools', 'Tools')
375367
);
376-
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
377-
commandId: ArduinoCommands.TOGGLE_COMPILE_FOR_DEBUG.id,
378-
label: nls.localize(
379-
'arduino/debug/optimizeForDebugging',
380-
'Optimize for Debugging'
381-
),
382-
order: '5',
383-
});
384368
}
385369

386370
registerColors(colors: ColorRegistry): void {

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

-5
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,6 @@ import { ProblemManager as TheiaProblemManager } from '@theia/markers/lib/browse
8080
import { ProblemManager } from './theia/markers/problem-manager';
8181
import { BoardsAutoInstaller } from './boards/boards-auto-installer';
8282
import { ShellLayoutRestorer } from './theia/core/shell-layout-restorer';
83-
import { EditorMode } from './editor-mode';
8483
import { ListItemRenderer } from './widgets/component-list/list-item-renderer';
8584
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
8685
import { MonacoThemingService } from '@theia/monaco/lib/browser/monaco-theming-service';
@@ -488,10 +487,6 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
488487
WorkspaceVariableContribution
489488
);
490489

491-
// Customizing default Theia layout based on the editor mode: `pro-mode` or `classic`.
492-
bind(EditorMode).toSelf().inSingletonScope();
493-
bind(FrontendApplicationContribution).toService(EditorMode);
494-
495490
bind(SurveyNotificationService)
496491
.toDynamicValue((context) => {
497492
return ElectronIpcConnectionProvider.createProxy(

arduino-ide-extension/src/browser/arduino-preferences.ts

+9
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ export const ArduinoConfigSchema: PreferenceSchema = {
8484
),
8585
default: 'None',
8686
},
87+
'arduino.compile.optimizeForDebug': {
88+
type: 'boolean',
89+
description: nls.localize(
90+
'arduino/preferences/compile.optimizeForDebug',
91+
"Optimize compile output for debug, not for release. It's 'false' by default."
92+
),
93+
default: false,
94+
},
8795
'arduino.upload.verbose': {
8896
type: 'boolean',
8997
description: nls.localize(
@@ -242,6 +250,7 @@ export interface ArduinoConfiguration {
242250
'arduino.compile.experimental': boolean;
243251
'arduino.compile.revealRange': ErrorRevealStrategy;
244252
'arduino.compile.warnings': CompilerWarnings;
253+
'arduino.compile.optimizeForDebug': boolean;
245254
'arduino.upload.verbose': boolean;
246255
'arduino.upload.verify': boolean;
247256
'arduino.window.autoScale': boolean;

arduino-ide-extension/src/browser/contributions/contribution.ts

-4
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import {
3737
CommandContribution,
3838
CommandService,
3939
} from '@theia/core/lib/common/command';
40-
import { EditorMode } from '../editor-mode';
4140
import { SettingsService } from '../dialogs/settings/settings';
4241
import {
4342
CurrentSketch,
@@ -90,9 +89,6 @@ export abstract class Contribution
9089
@inject(WorkspaceService)
9190
protected readonly workspaceService: WorkspaceService;
9291

93-
@inject(EditorMode)
94-
protected readonly editorMode: EditorMode;
95-
9692
@inject(LabelProvider)
9793
protected readonly labelProvider: LabelProvider;
9894

arduino-ide-extension/src/browser/contributions/debug.ts

+53-14
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,54 @@ import {
1212
SketchContribution,
1313
TabBarToolbarRegistry,
1414
} from './contribution';
15-
import { MaybePromise, nls } from '@theia/core/lib/common';
15+
import { MaybePromise, MenuModelRegistry, nls } from '@theia/core/lib/common';
1616
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
17+
import { ArduinoMenus } from '../menu/arduino-menus';
18+
import {
19+
PreferenceScope,
20+
PreferenceService,
21+
} from '@theia/core/lib/browser/preferences/preference-service';
1722

1823
@injectable()
1924
export class Debug extends SketchContribution {
2025
@inject(HostedPluginSupport)
21-
protected hostedPluginSupport: HostedPluginSupport;
26+
private readonly hostedPluginSupport: HostedPluginSupport;
2227

2328
@inject(NotificationCenter)
24-
protected readonly notificationCenter: NotificationCenter;
29+
private readonly notificationCenter: NotificationCenter;
2530

2631
@inject(ExecutableService)
27-
protected readonly executableService: ExecutableService;
32+
private readonly executableService: ExecutableService;
2833

2934
@inject(BoardsService)
30-
protected readonly boardService: BoardsService;
35+
private readonly boardService: BoardsService;
3136

3237
@inject(BoardsServiceProvider)
33-
protected readonly boardsServiceProvider: BoardsServiceProvider;
38+
private readonly boardsServiceProvider: BoardsServiceProvider;
39+
40+
@inject(PreferenceService)
41+
private readonly preferenceService: PreferenceService;
3442

3543
/**
3644
* If `undefined`, debugging is enabled. Otherwise, the reason why it's disabled.
3745
*/
38-
protected _disabledMessages?: string = nls.localize(
46+
private _disabledMessages?: string = nls.localize(
3947
'arduino/common/noBoardSelected',
4048
'No board selected'
4149
); // Initial pessimism.
42-
protected disabledMessageDidChangeEmitter = new Emitter<string | undefined>();
43-
protected onDisabledMessageDidChange =
50+
private disabledMessageDidChangeEmitter = new Emitter<string | undefined>();
51+
private onDisabledMessageDidChange =
4452
this.disabledMessageDidChangeEmitter.event;
4553

46-
protected get disabledMessage(): string | undefined {
54+
private get disabledMessage(): string | undefined {
4755
return this._disabledMessages;
4856
}
49-
protected set disabledMessage(message: string | undefined) {
57+
private set disabledMessage(message: string | undefined) {
5058
this._disabledMessages = message;
5159
this.disabledMessageDidChangeEmitter.fire(this._disabledMessages);
5260
}
5361

54-
protected readonly debugToolbarItem = {
62+
private readonly debugToolbarItem = {
5563
id: Debug.Commands.START_DEBUGGING.id,
5664
command: Debug.Commands.START_DEBUGGING.id,
5765
tooltip: `${
@@ -98,12 +106,24 @@ export class Debug extends SketchContribution {
98106
ArduinoToolbar.is(widget) && widget.side === 'left',
99107
isEnabled: () => !this.disabledMessage,
100108
});
109+
registry.registerCommand(Debug.Commands.OPTIMIZE_FOR_DEBUG, {
110+
execute: () => this.toggleOptimizeForDebug(),
111+
isToggled: () => this.isOptimizeForDebug(),
112+
});
101113
}
102114

103115
override registerToolbarItems(registry: TabBarToolbarRegistry): void {
104116
registry.registerItem(this.debugToolbarItem);
105117
}
106118

119+
override registerMenus(registry: MenuModelRegistry): void {
120+
registry.registerMenuAction(ArduinoMenus.SKETCH__MAIN_GROUP, {
121+
commandId: Debug.Commands.OPTIMIZE_FOR_DEBUG.id,
122+
label: Debug.Commands.OPTIMIZE_FOR_DEBUG.label,
123+
order: '5',
124+
});
125+
}
126+
107127
private async refreshState(
108128
board: Board | undefined = this.boardsServiceProvider.boardsConfig
109129
.selectedBoard
@@ -145,7 +165,7 @@ export class Debug extends SketchContribution {
145165
}
146166
}
147167

148-
protected async startDebug(
168+
private async startDebug(
149169
board: Board | undefined = this.boardsServiceProvider.boardsConfig
150170
.selectedBoard
151171
): Promise<void> {
@@ -183,8 +203,19 @@ export class Debug extends SketchContribution {
183203
};
184204
return this.commandService.executeCommand('arduino.debug.start', config);
185205
}
186-
}
187206

207+
private isOptimizeForDebug(): boolean {
208+
return this.preferences.get('arduino.compile.optimizeForDebug');
209+
}
210+
211+
private async toggleOptimizeForDebug(): Promise<void> {
212+
return this.preferenceService.set(
213+
'arduino.compile.optimizeForDebug',
214+
!this.isOptimizeForDebug(),
215+
PreferenceScope.User
216+
);
217+
}
218+
}
188219
export namespace Debug {
189220
export namespace Commands {
190221
export const START_DEBUGGING = Command.toLocalizedCommand(
@@ -195,5 +226,13 @@ export namespace Debug {
195226
},
196227
'vscode/debug.contribution/startDebuggingHelp'
197228
);
229+
export const OPTIMIZE_FOR_DEBUG = Command.toLocalizedCommand(
230+
{
231+
id: 'arduino-optimize-for-debug',
232+
label: 'Optimize for Debugging',
233+
category: 'Arduino',
234+
},
235+
'arduino/debug/optimizeForDebugging'
236+
);
198237
}
199238
}

arduino-ide-extension/src/browser/contributions/ino-language.ts

+2-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
import { HostedPluginEvents } from '../hosted-plugin-events';
99
import { SketchContribution, URI } from './contribution';
1010
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
11-
import { ArduinoPreferences } from '../arduino-preferences';
1211
import { BoardsConfig } from '../boards/boards-config';
1312
import { BoardsServiceProvider } from '../boards/boards-service-provider';
1413

@@ -29,9 +28,6 @@ export class InoLanguage extends SketchContribution {
2928
@inject(BoardsServiceProvider)
3029
private readonly boardsServiceProvider: BoardsServiceProvider;
3130

32-
@inject(ArduinoPreferences)
33-
private readonly arduinoPreferences: ArduinoPreferences;
34-
3531
private languageServerFqbn?: string;
3632
private languageServerStartMutex = new Mutex();
3733

@@ -51,7 +47,7 @@ export class InoLanguage extends SketchContribution {
5147
this.hostedPluginEvents.onPluginsWillUnload(
5248
() => (this.languageServerFqbn = undefined)
5349
);
54-
this.arduinoPreferences.onPreferenceChanged(
50+
this.preferences.onPreferenceChanged(
5551
({ preferenceName, oldValue, newValue }) => {
5652
if (
5753
preferenceName === 'arduino.language.log' &&
@@ -105,7 +101,7 @@ export class InoLanguage extends SketchContribution {
105101
return;
106102
}
107103
this.logger.info(`Starting language server: ${fqbn}`);
108-
const log = this.arduinoPreferences.get('arduino.language.log');
104+
const log = this.preferences.get('arduino.language.log');
109105
let currentSketchPath: string | undefined = undefined;
110106
if (log) {
111107
const currentSketch = await this.sketchServiceClient.currentSketch();

arduino-ide-extension/src/browser/contributions/upload-sketch.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,9 @@ export class UploadSketch extends CoreServiceContribution {
227227
fqbn,
228228
};
229229
let options: CoreService.Upload.Options | undefined = undefined;
230-
const optimizeForDebug = this.editorMode.compileForDebug;
230+
const optimizeForDebug = this.preferences.get(
231+
'arduino.compile.optimizeForDebug'
232+
);
231233
const { selectedPort } = boardsConfig;
232234
const port = selectedPort;
233235
const userFields =

arduino-ide-extension/src/browser/contributions/verify-sketch.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,14 @@ export class VerifySketch extends CoreServiceContribution {
114114
};
115115
const verbose = this.preferences.get('arduino.compile.verbose');
116116
const compilerWarnings = this.preferences.get('arduino.compile.warnings');
117+
const optimizeForDebug = this.preferences.get(
118+
'arduino.compile.optimizeForDebug'
119+
);
117120
this.outputChannelManager.getChannel('Arduino').clear();
118121
await this.coreService.compile({
119122
sketch,
120123
board,
121-
optimizeForDebug: this.editorMode.compileForDebug,
124+
optimizeForDebug,
122125
verbose,
123126
exportBinaries,
124127
sourceOverride,

arduino-ide-extension/src/browser/editor-mode.ts

-37
This file was deleted.

0 commit comments

Comments
 (0)