mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-06-15 08:36:33 +00:00
Got rid of the send button, use keybinding instead
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
ed660ccd64
commit
71842abfa3
@ -331,8 +331,8 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectionConfig = this.monitorConnection.connectionConfig;
|
const monitorConfig = this.monitorConnection.monitorConfig;
|
||||||
if (connectionConfig) {
|
if (monitorConfig) {
|
||||||
await this.monitorConnection.disconnect();
|
await this.monitorConnection.disconnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,8 +349,8 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
await this.messageService.error(e.toString());
|
await this.messageService.error(e.toString());
|
||||||
} finally {
|
} finally {
|
||||||
if (connectionConfig) {
|
if (monitorConfig) {
|
||||||
await this.monitorConnection.connect(connectionConfig);
|
await this.monitorConnection.connect(monitorConfig);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ export class ArduinoSelect<T> extends Select<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render(): React.ReactNode {
|
render(): React.ReactNode {
|
||||||
const height = 27; // Seems to be the hard coded constant for `input` and `textArea` in Theia.
|
const controlHeight = 27; // from `monitor.css` -> `.serial-monitor-container .head` (`height: 27px;`)
|
||||||
const styles: Styles = {
|
const styles: Styles = {
|
||||||
control: styles => ({
|
control: styles => ({
|
||||||
...styles,
|
...styles,
|
||||||
@ -37,7 +37,7 @@ export class ArduinoSelect<T> extends Select<T> {
|
|||||||
...theme,
|
...theme,
|
||||||
borderRadius: 0,
|
borderRadius: 0,
|
||||||
spacing: {
|
spacing: {
|
||||||
controlHeight: height,
|
controlHeight,
|
||||||
baseUnit: 2,
|
baseUnit: 2,
|
||||||
menuGutter: 4
|
menuGutter: 4
|
||||||
}, colors: {
|
}, colors: {
|
||||||
|
@ -107,7 +107,7 @@ export class MonitorConnection {
|
|||||||
return !!this.state;
|
return !!this.state;
|
||||||
}
|
}
|
||||||
|
|
||||||
get connectionConfig(): MonitorConfig | undefined {
|
get monitorConfig(): MonitorConfig | undefined {
|
||||||
return this.state ? this.state.config : undefined;
|
return this.state ? this.state.config : undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,12 +2,15 @@ import * as React from 'react';
|
|||||||
import * as dateFormat from 'dateformat';
|
import * as dateFormat from 'dateformat';
|
||||||
import { postConstruct, injectable, inject } from 'inversify';
|
import { postConstruct, injectable, inject } from 'inversify';
|
||||||
import { OptionsType } from 'react-select/src/types';
|
import { OptionsType } from 'react-select/src/types';
|
||||||
import { ArduinoSelect } from '../components/arduino-select';
|
import { Key, KeyCode } from '@theia/core/lib/browser/keys';
|
||||||
import { ReactWidget, Message, Widget } from '@theia/core/lib/browser/widgets';
|
import { ReactWidget, Message, Widget } from '@theia/core/lib/browser/widgets';
|
||||||
import { MonitorConfig } from '../../common/protocol/monitor-service';
|
import { MonitorConfig } from '../../common/protocol/monitor-service';
|
||||||
|
import { ArduinoSelect } from '../components/arduino-select';
|
||||||
import { MonitorModel } from './monitor-model';
|
import { MonitorModel } from './monitor-model';
|
||||||
import { MonitorConnection } from './monitor-connection';
|
import { MonitorConnection } from './monitor-connection';
|
||||||
import { MonitorServiceClientImpl } from './monitor-service-client-impl';
|
import { MonitorServiceClientImpl } from './monitor-service-client-impl';
|
||||||
|
import { isOSX } from '@theia/core';
|
||||||
|
import { Board, Port } from '../../common/protocol/boards-service';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class MonitorWidget extends ReactWidget {
|
export class MonitorWidget extends ReactWidget {
|
||||||
@ -15,7 +18,7 @@ export class MonitorWidget extends ReactWidget {
|
|||||||
static readonly ID = 'serial-monitor';
|
static readonly ID = 'serial-monitor';
|
||||||
|
|
||||||
@inject(MonitorModel)
|
@inject(MonitorModel)
|
||||||
protected readonly model: MonitorModel;
|
protected readonly monitorModel: MonitorModel;
|
||||||
|
|
||||||
@inject(MonitorConnection)
|
@inject(MonitorConnection)
|
||||||
protected readonly monitorConnection: MonitorConnection;
|
protected readonly monitorConnection: MonitorConnection;
|
||||||
@ -53,15 +56,11 @@ export class MonitorWidget extends ReactWidget {
|
|||||||
if (eolIndex !== -1) {
|
if (eolIndex !== -1) {
|
||||||
const line = this.chunk.substring(0, eolIndex + 1);
|
const line = this.chunk.substring(0, eolIndex + 1);
|
||||||
this.chunk = this.chunk.slice(eolIndex + 1);
|
this.chunk = this.chunk.slice(eolIndex + 1);
|
||||||
this.lines.push(`${this.model.timestamp ? `${dateFormat(new Date(), 'H:M:ss.l')} -> ` : ''}${line}`);
|
this.lines.push(`${this.monitorModel.timestamp ? `${dateFormat(new Date(), 'H:M:ss.l')} -> ` : ''}${line}`);
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
this.monitorConnection.onConnectionChanged(state => {
|
this.monitorConnection.onConnectionChanged(() => this.clearConsole())
|
||||||
if (!state) {
|
|
||||||
this.clearConsole();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
]);
|
]);
|
||||||
this.update();
|
this.update();
|
||||||
}
|
}
|
||||||
@ -125,24 +124,23 @@ export class MonitorWidget extends ReactWidget {
|
|||||||
|
|
||||||
protected render(): React.ReactNode {
|
protected render(): React.ReactNode {
|
||||||
const { baudRates, lineEndings } = this;
|
const { baudRates, lineEndings } = this;
|
||||||
const lineEnding = lineEndings.find(item => item.value === this.model.lineEnding) || lineEndings[1]; // Defaults to `\n`.
|
const lineEnding = lineEndings.find(item => item.value === this.monitorModel.lineEnding) || lineEndings[1]; // Defaults to `\n`.
|
||||||
const baudRate = baudRates.find(item => item.value === this.model.baudRate) || baudRates[4]; // Defaults to `9600`.
|
const baudRate = baudRates.find(item => item.value === this.monitorModel.baudRate) || baudRates[4]; // Defaults to `9600`.
|
||||||
return <div className='serial-monitor-container'>
|
return <div className='serial-monitor-container'>
|
||||||
<div className='head'>
|
<div className='head'>
|
||||||
<div className='send'>
|
<div className='send'>
|
||||||
<SerialMonitorSendField
|
<SerialMonitorSendField
|
||||||
|
monitorConfig={this.monitorConnection.monitorConfig}
|
||||||
resolveFocus={this.onFocusResolved}
|
resolveFocus={this.onFocusResolved}
|
||||||
onSend={this.onSend} />
|
onSend={this.onSend} />
|
||||||
</div>
|
</div>
|
||||||
<div className='config'>
|
<div className='config'>
|
||||||
<ArduinoSelect
|
<ArduinoSelect
|
||||||
className='serial-monitor-select'
|
|
||||||
maxMenuHeight={this.widgetHeight - 40}
|
maxMenuHeight={this.widgetHeight - 40}
|
||||||
options={lineEndings}
|
options={lineEndings}
|
||||||
defaultValue={lineEnding}
|
defaultValue={lineEnding}
|
||||||
onChange={this.onChangeLineEnding} />,
|
onChange={this.onChangeLineEnding} />,
|
||||||
<ArduinoSelect
|
<ArduinoSelect
|
||||||
className='serial-monitor-select'
|
|
||||||
maxMenuHeight={this.widgetHeight - 40}
|
maxMenuHeight={this.widgetHeight - 40}
|
||||||
options={baudRates}
|
options={baudRates}
|
||||||
defaultValue={baudRate}
|
defaultValue={baudRate}
|
||||||
@ -150,7 +148,7 @@ export class MonitorWidget extends ReactWidget {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id='serial-monitor-output-container'>
|
<div id='serial-monitor-output-container'>
|
||||||
<SerialMonitorOutput model={this.model} lines={this.lines} />
|
<SerialMonitorOutput monitorModel={this.monitorModel} lines={this.lines} />
|
||||||
</div>
|
</div>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
@ -161,18 +159,19 @@ export class MonitorWidget extends ReactWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected readonly onChangeLineEnding = (option: SelectOption<MonitorModel.EOL>) => {
|
protected readonly onChangeLineEnding = (option: SelectOption<MonitorModel.EOL>) => {
|
||||||
this.model.lineEnding = option.value;
|
this.monitorModel.lineEnding = option.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected readonly onChangeBaudRate = async (option: SelectOption<MonitorConfig.BaudRate>) => {
|
protected readonly onChangeBaudRate = async (option: SelectOption<MonitorConfig.BaudRate>) => {
|
||||||
await this.monitorConnection.disconnect();
|
await this.monitorConnection.disconnect();
|
||||||
this.model.baudRate = option.value;
|
this.monitorModel.baudRate = option.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace SerialMonitorSendField {
|
export namespace SerialMonitorSendField {
|
||||||
export interface Props {
|
export interface Props {
|
||||||
|
readonly monitorConfig?: MonitorConfig;
|
||||||
readonly onSend: (text: string) => void;
|
readonly onSend: (text: string) => void;
|
||||||
readonly resolveFocus: (element: HTMLElement | undefined) => void;
|
readonly resolveFocus: (element: HTMLElement | undefined) => void;
|
||||||
}
|
}
|
||||||
@ -186,39 +185,56 @@ export class SerialMonitorSendField extends React.Component<SerialMonitorSendFie
|
|||||||
constructor(props: SerialMonitorSendField.Props) {
|
constructor(props: SerialMonitorSendField.Props) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = { value: '' };
|
this.state = { value: '' };
|
||||||
|
this.onChange = this.onChange.bind(this);
|
||||||
this.handleChange = this.handleChange.bind(this);
|
this.onSend = this.onSend.bind(this);
|
||||||
this.handleSubmit = this.handleSubmit.bind(this);
|
this.onKeyDown = this.onKeyDown.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return <React.Fragment>
|
return <React.Fragment>
|
||||||
<input
|
<input
|
||||||
tabIndex={-1}
|
|
||||||
ref={this.setRef}
|
ref={this.setRef}
|
||||||
id='serial-monitor-send'
|
|
||||||
type='text'
|
type='text'
|
||||||
autoComplete='off'
|
className={this.props.monitorConfig ? '' : 'not-connected'}
|
||||||
|
placeholder={this.placeholder}
|
||||||
value={this.state.value}
|
value={this.state.value}
|
||||||
onChange={this.handleChange} />
|
onChange={this.onChange}
|
||||||
<button className='button' onClick={this.handleSubmit}>Send</button>
|
onKeyDown={this.onKeyDown} />
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected get placeholder(): string {
|
||||||
|
const { monitorConfig } = this.props;
|
||||||
|
if (!monitorConfig) {
|
||||||
|
return 'Not connected. Select a board and a port to connect automatically.'
|
||||||
|
}
|
||||||
|
const { board, port } = monitorConfig;
|
||||||
|
return `Message (${isOSX ? '⌘' : 'Ctrl'}+Enter to send message to '${Board.toString(board, { useFqbn: false })}' on '${Port.toString(port)}')`;
|
||||||
|
}
|
||||||
|
|
||||||
protected setRef = (element: HTMLElement | null) => {
|
protected setRef = (element: HTMLElement | null) => {
|
||||||
if (this.props.resolveFocus) {
|
if (this.props.resolveFocus) {
|
||||||
this.props.resolveFocus(element || undefined);
|
this.props.resolveFocus(element || undefined);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected handleChange(event: React.ChangeEvent<HTMLInputElement>) {
|
protected onChange(event: React.ChangeEvent<HTMLInputElement>): void {
|
||||||
this.setState({ value: event.target.value });
|
this.setState({ value: event.target.value });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected handleSubmit(event: React.MouseEvent<HTMLButtonElement>) {
|
protected onSend(): void {
|
||||||
this.props.onSend(this.state.value);
|
this.props.onSend(this.state.value);
|
||||||
this.setState({ value: '' });
|
this.setState({ value: '' });
|
||||||
event.preventDefault();
|
}
|
||||||
|
|
||||||
|
protected onKeyDown(event: React.KeyboardEvent<HTMLInputElement>): void {
|
||||||
|
const keyCode = KeyCode.createKeyCode(event.nativeEvent);
|
||||||
|
if (keyCode) {
|
||||||
|
const { key, meta, ctrl } = keyCode;
|
||||||
|
if (key === Key.ENTER && ((isOSX && meta) || (!isOSX && ctrl))) {
|
||||||
|
this.onSend();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -226,7 +242,7 @@ export class SerialMonitorSendField extends React.Component<SerialMonitorSendFie
|
|||||||
export namespace SerialMonitorOutput {
|
export namespace SerialMonitorOutput {
|
||||||
export interface Props {
|
export interface Props {
|
||||||
readonly lines: string[];
|
readonly lines: string[];
|
||||||
readonly model: MonitorModel;
|
readonly monitorModel: MonitorModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,7 +271,7 @@ export class SerialMonitorOutput extends React.Component<SerialMonitorOutput.Pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected scrollToBottom() {
|
protected scrollToBottom() {
|
||||||
if (this.props.model.autoscroll && this.anchor) {
|
if (this.props.monitorModel.autoscroll && this.anchor) {
|
||||||
this.anchor.scrollIntoView();
|
this.anchor.scrollIntoView();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,25 +20,21 @@
|
|||||||
|
|
||||||
.serial-monitor-container .head .send {
|
.serial-monitor-container .head .send {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex:1;
|
|
||||||
}
|
|
||||||
|
|
||||||
.serial-monitor-container .head .send .btn {
|
|
||||||
display: flex;
|
|
||||||
padding: 0 5px;
|
|
||||||
align-items: center;
|
|
||||||
color: var(--theia-ui-font-color1);
|
|
||||||
opacity: 0.7;
|
|
||||||
}
|
|
||||||
.serial-monitor-container .head .send .btn:hover {
|
|
||||||
opacity: 1;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
.serial-monitor-container .head .send form {
|
|
||||||
flex: 1;
|
flex: 1;
|
||||||
display: flex;
|
margin-right: 4px;
|
||||||
background: var(--theia-layout-color2);
|
}
|
||||||
|
|
||||||
|
.serial-monitor-container .head .send > input {
|
||||||
|
line-height: var(--theia-content-line-height);
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.serial-monitor-container .head .send > input:focus {
|
||||||
|
border-color: var(--theia-accent-color3);
|
||||||
|
}
|
||||||
|
|
||||||
|
.serial-monitor-container .head .send > input.not-connected {
|
||||||
|
background-color: var(--theia-warn-color0);
|
||||||
}
|
}
|
||||||
|
|
||||||
.serial-monitor-container .head .send input#serial-monitor-send {
|
.serial-monitor-container .head .send input#serial-monitor-send {
|
||||||
@ -46,18 +42,10 @@
|
|||||||
flex: 1;
|
flex: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
.serial-monitor-container .head .send input:focus {
|
|
||||||
outline: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.serial-monitor-container .head .config {
|
.serial-monitor-container .head .config {
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
|
|
||||||
.serial-monitor-container .head .config .serial-monitor-select {
|
|
||||||
margin-left: 5px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#serial-monitor-output-container {
|
#serial-monitor-output-container {
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
flex: 1;
|
flex: 1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user