mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-09 20:36:32 +00:00
Minor code improvements
Signed-off-by: jbicker <jan.bicker@typefox.io>
This commit is contained in:
parent
9b255ac072
commit
f76f4543e9
@ -42,15 +42,4 @@ export namespace ArduinoCommands {
|
|||||||
export const TOGGLE_PRO_MODE: Command = {
|
export const TOGGLE_PRO_MODE: Command = {
|
||||||
id: "arduino-toggle-pro-mode"
|
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'
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import { EditorWidget } from '@theia/editor/lib/browser/editor-widget';
|
|||||||
import { MessageService } from '@theia/core/lib/common/message-service';
|
import { MessageService } from '@theia/core/lib/common/message-service';
|
||||||
import { CommandContribution, CommandRegistry, Command } from '@theia/core/lib/common/command';
|
import { CommandContribution, CommandRegistry, Command } from '@theia/core/lib/common/command';
|
||||||
import { TabBarToolbarContribution, TabBarToolbarRegistry } from '@theia/core/lib/browser/shell/tab-bar-toolbar';
|
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 { ArduinoCommands } from './arduino-commands';
|
||||||
import { CoreService } from '../common/protocol/core-service';
|
import { CoreService } from '../common/protocol/core-service';
|
||||||
import { WorkspaceServiceExt } from './workspace-service-ext';
|
import { WorkspaceServiceExt } from './workspace-service-ext';
|
||||||
@ -26,8 +26,6 @@ import {
|
|||||||
StatusBar,
|
StatusBar,
|
||||||
ShellLayoutRestorer,
|
ShellLayoutRestorer,
|
||||||
StatusBarAlignment,
|
StatusBarAlignment,
|
||||||
QuickOpenItem,
|
|
||||||
QuickOpenMode,
|
|
||||||
QuickOpenService,
|
QuickOpenService,
|
||||||
LabelProvider
|
LabelProvider
|
||||||
} from '@theia/core/lib/browser';
|
} from '@theia/core/lib/browser';
|
||||||
@ -74,9 +72,6 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
@inject(MonitorService)
|
@inject(MonitorService)
|
||||||
protected readonly monitorService: MonitorService;
|
protected readonly monitorService: MonitorService;
|
||||||
|
|
||||||
// TODO: make this better!
|
|
||||||
protected connectionId: string | undefined;
|
|
||||||
|
|
||||||
@inject(WorkspaceServiceExt)
|
@inject(WorkspaceServiceExt)
|
||||||
protected readonly workspaceServiceExt: WorkspaceServiceExt;
|
protected readonly workspaceServiceExt: WorkspaceServiceExt;
|
||||||
|
|
||||||
@ -341,65 +336,6 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
|||||||
},
|
},
|
||||||
isToggled: () => ARDUINO_PRO_MODE
|
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) {
|
registerMenus(registry: MenuModelRegistry) {
|
||||||
|
@ -8,34 +8,26 @@ export class MonitorConnection {
|
|||||||
@inject(MonitorService)
|
@inject(MonitorService)
|
||||||
protected readonly monitorService: MonitorService;
|
protected readonly monitorService: MonitorService;
|
||||||
|
|
||||||
protected _connectionId: string | undefined;
|
connectionId: string | undefined;
|
||||||
|
|
||||||
protected _connectionConfig: ConnectionConfig;
|
protected _connectionConfig: ConnectionConfig | undefined;
|
||||||
|
|
||||||
protected readonly onConnectionChangedEmitter = new Emitter<string | undefined>();
|
protected readonly onConnectionChangedEmitter = new Emitter<string | undefined>();
|
||||||
readonly onConnectionChanged: Event<string | undefined> = this.onConnectionChangedEmitter.event;
|
readonly onConnectionChanged: Event<string | undefined> = this.onConnectionChangedEmitter.event;
|
||||||
|
|
||||||
get connectionId(): string | undefined {
|
get connectionConfig(): ConnectionConfig | undefined {
|
||||||
return this._connectionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
set connectionId(cid: string | undefined) {
|
|
||||||
this._connectionId = cid;
|
|
||||||
}
|
|
||||||
|
|
||||||
get connectionConfig(): ConnectionConfig {
|
|
||||||
return this._connectionConfig;
|
return this._connectionConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
async connect(config: ConnectionConfig): Promise<string | undefined> {
|
async connect(config: ConnectionConfig): Promise<string | undefined> {
|
||||||
if (this._connectionId) {
|
if (this.connectionId) {
|
||||||
await this.disconnect();
|
await this.disconnect();
|
||||||
}
|
}
|
||||||
const { connectionId } = await this.monitorService.connect(config);
|
const { connectionId } = await this.monitorService.connect(config);
|
||||||
this._connectionId = connectionId;
|
this.connectionId = connectionId;
|
||||||
this._connectionConfig = config;
|
this._connectionConfig = config;
|
||||||
|
|
||||||
this.onConnectionChangedEmitter.fire(this._connectionId);
|
this.onConnectionChangedEmitter.fire(this.connectionId);
|
||||||
|
|
||||||
return connectionId;
|
return connectionId;
|
||||||
}
|
}
|
||||||
@ -43,17 +35,18 @@ export class MonitorConnection {
|
|||||||
async disconnect(): Promise<boolean> {
|
async disconnect(): Promise<boolean> {
|
||||||
let result = true;
|
let result = true;
|
||||||
const connections = await this.monitorService.getConnectionIds();
|
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...');
|
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) {
|
if (!result) {
|
||||||
// TODO: better!!!
|
// 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 {
|
} else {
|
||||||
console.log(`<<< Disposed ${this._connectionId} connection.`);
|
console.log(`<<< Disposed ${this.connectionId} connection.`);
|
||||||
this._connectionId = undefined;
|
this.connectionId = undefined;
|
||||||
|
this._connectionConfig = undefined;
|
||||||
|
this.onConnectionChangedEmitter.fire(this.connectionId);
|
||||||
}
|
}
|
||||||
this.onConnectionChangedEmitter.fire(this._connectionId);
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -71,12 +71,9 @@ export class SerialMonitorOutput extends React.Component<SerialMonitorOutput.Pro
|
|||||||
fontFamily: 'monospace',
|
fontFamily: 'monospace',
|
||||||
};
|
};
|
||||||
|
|
||||||
for (let text of this.props.lines) {
|
for (const text of this.props.lines) {
|
||||||
result += text;
|
result += text;
|
||||||
}
|
}
|
||||||
if (result.length === 0) {
|
|
||||||
result = '';
|
|
||||||
}
|
|
||||||
return <React.Fragment>
|
return <React.Fragment>
|
||||||
<div style={style}>{result}</div>
|
<div style={style}>{result}</div>
|
||||||
<div style={{ float: "left", clear: "both" }}
|
<div style={{ float: "left", clear: "both" }}
|
||||||
@ -116,7 +113,7 @@ export class MonitorWidget extends ReactWidget {
|
|||||||
|
|
||||||
protected lines: string[];
|
protected lines: string[];
|
||||||
protected tempData: string;
|
protected tempData: string;
|
||||||
protected _baudRate: number;
|
protected baudRate: number;
|
||||||
protected _lineEnding: string;
|
protected _lineEnding: string;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@ -168,10 +165,6 @@ export class MonitorWidget extends ReactWidget {
|
|||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
get baudRate(): number | undefined {
|
|
||||||
return this._baudRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected onAfterAttach(msg: Message) {
|
protected onAfterAttach(msg: Message) {
|
||||||
super.onAfterAttach(msg);
|
super.onAfterAttach(msg);
|
||||||
this.clear();
|
this.clear();
|
||||||
@ -296,7 +289,7 @@ export class MonitorWidget extends ReactWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected readonly onChangeBaudRate = (br: SelectOption) => {
|
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<SelectOption>, defaultVal: SelectOption, onChange: (v: SelectOption) => void): React.ReactNode {
|
protected renderSelectField(id: string, options: OptionsType<SelectOption>, defaultVal: SelectOption, onChange: (v: SelectOption) => void): React.ReactNode {
|
||||||
|
@ -6,14 +6,19 @@ import { CommandRegistry } from "@theia/core";
|
|||||||
import { LabelParser } from "@theia/core/lib/browser/label-parser";
|
import { LabelParser } from "@theia/core/lib/browser/label-parser";
|
||||||
|
|
||||||
export class ArduinoToolbarContainer extends Widget {
|
export class ArduinoToolbarContainer extends Widget {
|
||||||
constructor(protected left: ArduinoToolbar, protected right: ArduinoToolbar) {
|
|
||||||
|
protected toolbars: ArduinoToolbar[];
|
||||||
|
|
||||||
|
constructor(...toolbars: ArduinoToolbar[]) {
|
||||||
super();
|
super();
|
||||||
this.id = 'arduino-toolbar-container';
|
this.id = 'arduino-toolbar-container';
|
||||||
|
this.toolbars = toolbars;
|
||||||
}
|
}
|
||||||
|
|
||||||
onAfterAttach(msg: Message) {
|
onAfterAttach(msg: Message) {
|
||||||
Widget.attach(this.left, this.node);
|
for (const toolbar of this.toolbars) {
|
||||||
Widget.attach(this.right, this.node);
|
Widget.attach(toolbar, this.node);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,17 +45,18 @@ export class ArduinoToolbarComponent extends React.Component<ArduinoToolbarCompo
|
|||||||
}
|
}
|
||||||
|
|
||||||
render(): React.ReactNode {
|
render(): React.ReactNode {
|
||||||
|
const tooltip = <div key='arduino-toolbar-tooltip' className={'arduino-toolbar-tooltip'}>{this.state.tooltip}</div>;
|
||||||
|
const items = [
|
||||||
|
<React.Fragment>
|
||||||
|
{[...this.props.items].map(item => TabBarToolbarItem.is(item) ? this.renderItem(item) : item.render())}
|
||||||
|
</React.Fragment>
|
||||||
|
]
|
||||||
if (this.props.side === 'left') {
|
if (this.props.side === 'left') {
|
||||||
return <React.Fragment>
|
items.unshift(tooltip);
|
||||||
<div key='arduino-toolbar-tooltip' className={'arduino-toolbar-tooltip'}>{this.state.tooltip}</div>
|
|
||||||
{[...this.props.items].map(item => TabBarToolbarItem.is(item) ? this.renderItem(item) : item.render())}
|
|
||||||
</React.Fragment>;
|
|
||||||
} else {
|
} else {
|
||||||
return <React.Fragment>
|
items.push(tooltip)
|
||||||
{[...this.props.items].map(item => TabBarToolbarItem.is(item) ? this.renderItem(item) : item.render())}
|
|
||||||
<div key='arduino-toolbar-tooltip' className={'arduino-toolbar-tooltip'}>{this.state.tooltip}</div>
|
|
||||||
</React.Fragment>;
|
|
||||||
}
|
}
|
||||||
|
return items;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -91,8 +92,7 @@ export class ArduinoToolbar extends ReactWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected init(): void {
|
protected init(): void {
|
||||||
this.node.classList.add('theia-arduino-toolbar');
|
this.node.classList.add('theia-arduino-toolbar', this.side);
|
||||||
this.node.classList.add(this.side);
|
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user