diff --git a/arduino-ide-extension/src/browser/arduino-commands.ts b/arduino-ide-extension/src/browser/arduino-commands.ts index 0629e024..9c8e1dd7 100644 --- a/arduino-ide-extension/src/browser/arduino-commands.ts +++ b/arduino-ide-extension/src/browser/arduino-commands.ts @@ -42,15 +42,4 @@ export namespace ArduinoCommands { export const TOGGLE_PRO_MODE: Command = { id: "arduino-toggle-pro-mode" } - - export const CONNECT_TODO: Command = { - id: 'connect-to-attached-board', - label: 'Connect to Attached Board' - } - - export const SEND: Command = { - id: 'send', - label: 'Send a Message to the Connected Board' - } - } diff --git a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx index 870b2766..5dabaac0 100644 --- a/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx +++ b/arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx @@ -5,7 +5,7 @@ import { EditorWidget } from '@theia/editor/lib/browser/editor-widget'; import { MessageService } from '@theia/core/lib/common/message-service'; import { CommandContribution, CommandRegistry, Command } from '@theia/core/lib/common/command'; import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar'; -import { BoardsService, AttachedSerialBoard } from '../common/protocol/boards-service'; +import { BoardsService } from '../common/protocol/boards-service'; import { ArduinoCommands } from './arduino-commands'; import { CoreService } from '../common/protocol/core-service'; import { WorkspaceServiceExt } from './workspace-service-ext'; @@ -26,8 +26,6 @@ import { StatusBar, ShellLayoutRestorer, StatusBarAlignment, - QuickOpenItem, - QuickOpenMode, QuickOpenService, LabelProvider } from '@theia/core/lib/browser'; @@ -74,9 +72,6 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C @inject(MonitorService) protected readonly monitorService: MonitorService; - // TODO: make this better! - protected connectionId: string | undefined; - @inject(WorkspaceServiceExt) protected readonly workspaceServiceExt: WorkspaceServiceExt; @@ -341,65 +336,6 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C }, isToggled: () => ARDUINO_PRO_MODE }); - registry.registerCommand(ArduinoCommands.CONNECT_TODO, { - execute: async () => { - const { boardsConfig } = this.boardsServiceClient; - const { selectedBoard, selectedPort } = boardsConfig; - if (!selectedBoard) { - this.messageService.warn('No boards selected.'); - return; - } - const { name } = selectedBoard; - if (!selectedPort) { - this.messageService.warn(`No ports selected for board: '${name}'.`); - return; - } - const attachedBoards = await this.boardsService.getAttachedBoards(); - const connectedBoard = attachedBoards.boards.filter(AttachedSerialBoard.is).find(board => BoardsConfig.Config.sameAs(boardsConfig, board)); - if (!connectedBoard) { - this.messageService.warn(`The selected '${name}' board is not connected on ${selectedPort}.`); - return; - } - if (this.connectionId) { - console.log('>>> Disposing existing monitor connection before establishing a new one...'); - const result = await this.monitorService.disconnect(this.connectionId); - if (!result) { - // TODO: better!!! - console.error(`Could not close connection: ${this.connectionId}. Check the backend logs.`); - } else { - console.log(`<<< Disposed ${this.connectionId} connection.`) - } - } - const { connectionId } = await this.monitorService.connect({ board: selectedBoard, port: selectedPort }); - this.connectionId = connectionId; - } - }); - registry.registerCommand(ArduinoCommands.SEND, { - isEnabled: () => !!this.connectionId, - execute: async () => { - const { monitorService, connectionId } = this; - const model = { - onType(lookFor: string, acceptor: (items: QuickOpenItem[]) => void): void { - acceptor([ - new QuickOpenItem({ - label: "Type your message and press 'Enter' to send it to the board. Escape to cancel.", - run: (mode: QuickOpenMode): boolean => { - if (mode !== QuickOpenMode.OPEN) { - return false; - } - monitorService.send(connectionId!, lookFor + '\n'); - return true; - } - }) - ]); - } - }; - const options = { - placeholder: "Your message. The message will be suffixed with a LF ['\\n'].", - }; - this.quickOpenService.open(model, options); - } - }) } registerMenus(registry: MenuModelRegistry) { diff --git a/arduino-ide-extension/src/browser/monitor/monitor-connection.ts b/arduino-ide-extension/src/browser/monitor/monitor-connection.ts index ba0ec3eb..ce08ee33 100644 --- a/arduino-ide-extension/src/browser/monitor/monitor-connection.ts +++ b/arduino-ide-extension/src/browser/monitor/monitor-connection.ts @@ -8,34 +8,26 @@ export class MonitorConnection { @inject(MonitorService) protected readonly monitorService: MonitorService; - protected _connectionId: string | undefined; + connectionId: string | undefined; - protected _connectionConfig: ConnectionConfig; + protected _connectionConfig: ConnectionConfig | undefined; protected readonly onConnectionChangedEmitter = new Emitter(); readonly onConnectionChanged: Event = this.onConnectionChangedEmitter.event; - get connectionId(): string | undefined { - return this._connectionId; - } - - set connectionId(cid: string | undefined) { - this._connectionId = cid; - } - - get connectionConfig(): ConnectionConfig { + get connectionConfig(): ConnectionConfig | undefined { return this._connectionConfig; } async connect(config: ConnectionConfig): Promise { - if (this._connectionId) { + if (this.connectionId) { await this.disconnect(); } const { connectionId } = await this.monitorService.connect(config); - this._connectionId = connectionId; + this.connectionId = connectionId; this._connectionConfig = config; - this.onConnectionChangedEmitter.fire(this._connectionId); + this.onConnectionChangedEmitter.fire(this.connectionId); return connectionId; } @@ -43,17 +35,18 @@ export class MonitorConnection { async disconnect(): Promise { let result = true; const connections = await this.monitorService.getConnectionIds(); - if (this._connectionId && connections.findIndex(id => id === this._connectionId) >= 0) { + if (this.connectionId && connections.findIndex(id => id === this.connectionId) >= 0) { console.log('>>> Disposing existing monitor connection before establishing a new one...'); - result = await this.monitorService.disconnect(this._connectionId); + result = await this.monitorService.disconnect(this.connectionId); if (!result) { // TODO: better!!! - console.error(`Could not close connection: ${this._connectionId}. Check the backend logs.`); + console.error(`Could not close connection: ${this.connectionId}. Check the backend logs.`); } else { - console.log(`<<< Disposed ${this._connectionId} connection.`); - this._connectionId = undefined; + console.log(`<<< Disposed ${this.connectionId} connection.`); + this.connectionId = undefined; + this._connectionConfig = undefined; + this.onConnectionChangedEmitter.fire(this.connectionId); } - this.onConnectionChangedEmitter.fire(this._connectionId); } return result; } diff --git a/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx b/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx index 501c7ee8..01a20657 100644 --- a/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx +++ b/arduino-ide-extension/src/browser/monitor/monitor-widget.tsx @@ -71,12 +71,9 @@ export class SerialMonitorOutput extends React.Component
{result}
{ - const currentConnectionConfig = this.connection.connectionConfig; + const currentConnectionConfig = this.connection.connectionConfig; const connectedBoard = states.newState.boards .filter(AttachedSerialBoard.is) .find(board => { @@ -296,7 +289,7 @@ export class MonitorWidget extends ReactWidget { } protected readonly onChangeBaudRate = (br: SelectOption) => { - this._baudRate = typeof br.value === 'number' ? br.value : 9600; + this.baudRate = typeof br.value === 'number' ? br.value : 9600; } protected renderSelectField(id: string, options: OptionsType, defaultVal: SelectOption, onChange: (v: SelectOption) => void): React.ReactNode { diff --git a/arduino-ide-extension/src/browser/toolbar/arduino-toolbar-contribution.ts b/arduino-ide-extension/src/browser/toolbar/arduino-toolbar-contribution.ts index 17c13353..5931f1ec 100644 --- a/arduino-ide-extension/src/browser/toolbar/arduino-toolbar-contribution.ts +++ b/arduino-ide-extension/src/browser/toolbar/arduino-toolbar-contribution.ts @@ -6,14 +6,19 @@ import { CommandRegistry } from "@theia/core"; import { LabelParser } from "@theia/core/lib/browser/label-parser"; export class ArduinoToolbarContainer extends Widget { - constructor(protected left: ArduinoToolbar, protected right: ArduinoToolbar) { + + protected toolbars: ArduinoToolbar[]; + + constructor(...toolbars: ArduinoToolbar[]) { super(); this.id = 'arduino-toolbar-container'; + this.toolbars = toolbars; } onAfterAttach(msg: Message) { - Widget.attach(this.left, this.node); - Widget.attach(this.right, this.node); + for (const toolbar of this.toolbars) { + Widget.attach(toolbar, this.node); + } } } diff --git a/arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx b/arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx index c16af2f0..31b7f113 100644 --- a/arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx +++ b/arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx @@ -45,17 +45,18 @@ export class ArduinoToolbarComponent extends React.Component{this.state.tooltip}
; + const items = [ + + {[...this.props.items].map(item => TabBarToolbarItem.is(item) ? this.renderItem(item) : item.render())} + + ] if (this.props.side === 'left') { - return -
{this.state.tooltip}
- {[...this.props.items].map(item => TabBarToolbarItem.is(item) ? this.renderItem(item) : item.render())} -
; + items.unshift(tooltip); } else { - return - {[...this.props.items].map(item => TabBarToolbarItem.is(item) ? this.renderItem(item) : item.render())} -
{this.state.tooltip}
-
; + items.push(tooltip) } + return items; } } @@ -91,8 +92,7 @@ export class ArduinoToolbar extends ReactWidget { } protected init(): void { - this.node.classList.add('theia-arduino-toolbar'); - this.node.classList.add(this.side); + this.node.classList.add('theia-arduino-toolbar', this.side); this.update(); }