Skip to content

Commit c0bf94e

Browse files
committed
feat: can dock the monitor widget to the "right"
Added a new preference (`arduino.monitor.dockPanel`) to specify the location of the application shell where the _Serial Monitor_ widget resides. The possible values are `"bottom"` and `"right"`. The default\ value is the `"bottom"`. The dock panel is per application and not per workspace or window. However, advanced users can create the `./.vscode/settings.json` and configure per sketch preference. Signed-off-by: dankeboy36 <[email protected]>
1 parent d79bc0d commit c0bf94e

File tree

6 files changed

+80
-17
lines changed

6 files changed

+80
-17
lines changed

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

+20
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
} from '@theia/core/lib/browser/preferences';
99
import { nls } from '@theia/core/lib/common';
1010
import { CompilerWarningLiterals, CompilerWarnings } from '../common/protocol';
11+
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
12+
import { serialMonitorWidgetLabel } from '../common/nls';
1113

1214
export enum UpdateChannel {
1315
Stable = 'stable',
@@ -40,6 +42,12 @@ export namespace ErrorRevealStrategy {
4042
export const Default: ErrorRevealStrategy = 'centerIfOutsideViewport';
4143
}
4244

45+
export type MonitorWidgetDockPanel = Extract<ApplicationShell.Area, 'bottom' | 'right'>;
46+
export const defaultMonitorWidgetDockPanel: MonitorWidgetDockPanel = 'bottom';
47+
export function isMonitorWidgetDockPanel(arg: unknown): arg is MonitorWidgetDockPanel {
48+
return arg === 'bottom' || arg === 'right';
49+
}
50+
4351
export const ArduinoConfigSchema: PreferenceSchema = {
4452
type: 'object',
4553
properties: {
@@ -258,6 +266,17 @@ export const ArduinoConfigSchema: PreferenceSchema = {
258266
),
259267
default: undefined,
260268
},
269+
'arduino.monitor.dockArea': {
270+
type: 'string',
271+
enum: ['bottom', 'right'],
272+
markdownDescription: nls.localize(
273+
'arduino/preferences/monitor/dockPanel',
274+
'The area of the application shell where the _{0}_ widget will reside. It is either "bottom" or "right". It defaults to "{1}".',
275+
serialMonitorWidgetLabel,
276+
defaultMonitorWidgetDockPanel
277+
),
278+
default: defaultMonitorWidgetDockPanel,
279+
},
261280
},
262281
};
263282

@@ -288,6 +307,7 @@ export interface ArduinoConfiguration {
288307
'arduino.cli.daemon.debug': boolean;
289308
'arduino.sketch.inoBlueprint': string;
290309
'arduino.checkForUpdates': boolean;
310+
'arduino.monitor.dockPanel': MonitorWidgetDockPanel;
291311
}
292312

293313
export const ArduinoPreferences = Symbol('ArduinoPreferences');

arduino-ide-extension/src/browser/serial/monitor/monitor-view-contribution.tsx

+49-11
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as React from '@theia/core/shared/react';
2-
import { injectable, inject } from '@theia/core/shared/inversify';
3-
import { AbstractViewContribution, codicon } from '@theia/core/lib/browser';
2+
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
3+
import {
4+
AbstractViewContribution,
5+
ApplicationShell,
6+
codicon
7+
} from '@theia/core/lib/browser';
48
import { MonitorWidget } from './monitor-widget';
59
import { MenuModelRegistry, Command, CommandRegistry } from '@theia/core';
610
import {
@@ -13,6 +17,12 @@ import { nls } from '@theia/core/lib/common';
1317
import { Event } from '@theia/core/lib/common/event';
1418
import { MonitorModel } from '../../monitor-model';
1519
import { MonitorManagerProxyClient } from '../../../common/protocol';
20+
import {
21+
ArduinoPreferences,
22+
defaultMonitorWidgetDockPanel,
23+
isMonitorWidgetDockPanel
24+
} from '../../arduino-preferences';
25+
import { serialMonitorWidgetLabel } from '../../../common/nls';
1626

1727
export namespace SerialMonitor {
1828
export namespace Commands {
@@ -50,31 +60,59 @@ export class MonitorViewContribution
5060
static readonly TOGGLE_SERIAL_MONITOR_TOOLBAR =
5161
MonitorWidget.ID + ':toggle-toolbar';
5262
static readonly RESET_SERIAL_MONITOR = MonitorWidget.ID + ':reset';
63+
64+
@inject(MonitorModel)
65+
private readonly model: MonitorModel;
66+
@inject(MonitorManagerProxyClient)
67+
private readonly monitorManagerProxy: MonitorManagerProxyClient;
68+
@inject(ArduinoPreferences)
69+
private readonly arduinoPreferences: ArduinoPreferences;
5370

54-
constructor(
55-
@inject(MonitorModel)
56-
protected readonly model: MonitorModel,
71+
private _panel: ApplicationShell.Area;
5772

58-
@inject(MonitorManagerProxyClient)
59-
protected readonly monitorManagerProxy: MonitorManagerProxyClient
60-
) {
73+
constructor() {
6174
super({
6275
widgetId: MonitorWidget.ID,
63-
widgetName: MonitorWidget.LABEL,
76+
widgetName: serialMonitorWidgetLabel,
6477
defaultWidgetOptions: {
65-
area: 'bottom',
78+
area: defaultMonitorWidgetDockPanel,
6679
},
6780
toggleCommandId: MonitorViewContribution.TOGGLE_SERIAL_MONITOR,
6881
toggleKeybinding: 'CtrlCmd+Shift+M',
6982
});
83+
this._panel = defaultMonitorWidgetDockPanel;
84+
}
85+
86+
@postConstruct()
87+
protected init(): void {
88+
this._panel = this.arduinoPreferences['arduino.monitor.dockPanel'] ?? defaultMonitorWidgetDockPanel;
7089
this.monitorManagerProxy.onMonitorShouldReset(() => this.reset());
90+
this.arduinoPreferences.onPreferenceChanged((event) => {
91+
if (event.preferenceName === 'arduino.monitor.dockPanel' && isMonitorWidgetDockPanel(event.newValue) && event.newValue !== this._panel) {
92+
this._panel = event.newValue;
93+
const widget = this.tryGetWidget();
94+
// reopen at the new position if opened
95+
if (widget) {
96+
widget.close();
97+
this.openView({ activate: true, reveal: true });
98+
}
99+
}
100+
})
101+
}
102+
103+
override get defaultViewOptions(): ApplicationShell.WidgetOptions {
104+
const viewOptions = super.defaultViewOptions;
105+
return {
106+
...viewOptions,
107+
area: this._panel
108+
};
71109
}
72110

73111
override registerMenus(menus: MenuModelRegistry): void {
74112
if (this.toggleCommand) {
75113
menus.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP, {
76114
commandId: this.toggleCommand.id,
77-
label: MonitorWidget.LABEL,
115+
label: serialMonitorWidgetLabel,
78116
order: '5',
79117
});
80118
}

arduino-ide-extension/src/browser/serial/monitor/monitor-widget.tsx

+2-5
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ import {
2727
} from '../../../common/protocol';
2828
import { MonitorModel } from '../../monitor-model';
2929
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
30+
import { serialMonitorWidgetLabel } from '../../../common/nls';
3031

3132
@injectable()
3233
export class MonitorWidget extends ReactWidget {
33-
static readonly LABEL = nls.localize(
34-
'arduino/common/serialMonitor',
35-
'Serial Monitor'
36-
);
3734
static readonly ID = 'serial-monitor';
3835

3936
protected settings: MonitorSettings = {};
@@ -65,7 +62,7 @@ export class MonitorWidget extends ReactWidget {
6562
constructor() {
6663
super();
6764
this.id = MonitorWidget.ID;
68-
this.title.label = MonitorWidget.LABEL;
65+
this.title.label = serialMonitorWidgetLabel;
6966
this.title.iconClass = 'monitor-tab-icon';
7067
this.title.closable = true;
7168
this.scrollOptions = undefined;

arduino-ide-extension/src/browser/style/monitor.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
.serial-monitor .head {
2222
display: flex;
23-
padding: 0px 5px 5px 0px;
23+
padding: 0px 5px 5px 5px;
2424
height: 27px;
2525
background-color: var(--theia-activityBar-background);
2626
}

arduino-ide-extension/src/common/nls.ts

+5
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,8 @@ export const InstallManually = nls.localize(
1919
'arduino/common/installManually',
2020
'Install Manually'
2121
);
22+
23+
export const serialMonitorWidgetLabel = nls.localize(
24+
'arduino/common/serialMonitor',
25+
'Serial Monitor'
26+
);

i18n/en.json

+3
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@
381381
"language.log": "True if the Arduino Language Server should generate log files into the sketch folder. Otherwise, false. It's false by default.",
382382
"language.realTimeDiagnostics": "If true, the language server provides real-time diagnostics when typing in the editor. It's false by default.",
383383
"manualProxy": "Manual proxy configuration",
384+
"monitor": {
385+
"dockPanel": "The area of the application shell where the _{0}_ widget will reside. It is either \"bottom\" or \"right\". It defaults to \"{1}\"."
386+
},
384387
"network": "Network",
385388
"newSketchbookLocation": "Select new sketchbook location",
386389
"noCliConfig": "Could not load the CLI configuration",

0 commit comments

Comments
 (0)