1
1
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' ;
4
8
import { MonitorWidget } from './monitor-widget' ;
5
9
import { MenuModelRegistry , Command , CommandRegistry } from '@theia/core' ;
6
10
import {
@@ -13,6 +17,12 @@ import { nls } from '@theia/core/lib/common';
13
17
import { Event } from '@theia/core/lib/common/event' ;
14
18
import { MonitorModel } from '../../monitor-model' ;
15
19
import { MonitorManagerProxyClient } from '../../../common/protocol' ;
20
+ import {
21
+ ArduinoPreferences ,
22
+ defaultMonitorWidgetDockArea ,
23
+ isMonitorWidgetDockArea
24
+ } from '../../arduino-preferences' ;
25
+ import { serialMonitorWidgetLabel } from '../../../common/nls' ;
16
26
17
27
export namespace SerialMonitor {
18
28
export namespace Commands {
@@ -50,31 +60,59 @@ export class MonitorViewContribution
50
60
static readonly TOGGLE_SERIAL_MONITOR_TOOLBAR =
51
61
MonitorWidget . ID + ':toggle-toolbar' ;
52
62
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 ;
53
70
54
- constructor (
55
- @inject ( MonitorModel )
56
- protected readonly model : MonitorModel ,
71
+ private _area : ApplicationShell . Area ;
57
72
58
- @inject ( MonitorManagerProxyClient )
59
- protected readonly monitorManagerProxy : MonitorManagerProxyClient
60
- ) {
73
+ constructor ( ) {
61
74
super ( {
62
75
widgetId : MonitorWidget . ID ,
63
- widgetName : MonitorWidget . LABEL ,
76
+ widgetName : serialMonitorWidgetLabel ,
64
77
defaultWidgetOptions : {
65
- area : 'bottom' ,
78
+ area : defaultMonitorWidgetDockArea ,
66
79
} ,
67
80
toggleCommandId : MonitorViewContribution . TOGGLE_SERIAL_MONITOR ,
68
81
toggleKeybinding : 'CtrlCmd+Shift+M' ,
69
82
} ) ;
83
+ this . _area = defaultMonitorWidgetDockArea ;
84
+ }
85
+
86
+ @postConstruct ( )
87
+ protected init ( ) : void {
88
+ this . _area = this . arduinoPreferences [ 'arduino.monitor.dockArea' ] ?? defaultMonitorWidgetDockArea ;
70
89
this . monitorManagerProxy . onMonitorShouldReset ( ( ) => this . reset ( ) ) ;
90
+ this . arduinoPreferences . onPreferenceChanged ( ( event ) => {
91
+ if ( event . preferenceName === 'arduino.monitor.dockArea' && isMonitorWidgetDockArea ( event . newValue ) && event . newValue !== this . _area ) {
92
+ this . _area = 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 . _area
108
+ } ;
71
109
}
72
110
73
111
override registerMenus ( menus : MenuModelRegistry ) : void {
74
112
if ( this . toggleCommand ) {
75
113
menus . registerMenuAction ( ArduinoMenus . TOOLS__MAIN_GROUP , {
76
114
commandId : this . toggleCommand . id ,
77
- label : MonitorWidget . LABEL ,
115
+ label : serialMonitorWidgetLabel ,
78
116
order : '5' ,
79
117
} ) ;
80
118
}
0 commit comments