Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ATL-1107][ATL-1045] Verify/Upload Buttons Hover & "running" style #197

Merged
merged 1 commit into from
Mar 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,20 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
id: 'arduino.toolbar.hoverBackground',
defaults: {
dark: 'button.hoverBackground',
light: 'button.hoverBackground',
hc: 'activityBar.inactiveForeground'
light: 'button.foreground',
hc: 'textLink.foreground'
},
description: 'Background color of the toolbar items when hovering over them. Such as Upload, Verify, etc.'
},
{
id: 'arduino.toolbar.toggleBackground',
defaults: {
dark: 'editor.selectionBackground',
light: 'editor.selectionBackground',
hc: 'textPreformat.foreground'
},
description: 'Toggle color of the toolbar items when they are currently toggled (the command is in progress)'
},
{
id: 'arduino.output.foreground',
defaults: {
Expand Down
30 changes: 27 additions & 3 deletions arduino-ide-extension/src/browser/contributions/upload-sketch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { inject, injectable } from 'inversify';
import { Emitter } from '@theia/core/lib/common/event';
import { CoreService } from '../../common/protocol';
import { ArduinoMenus } from '../menu/arduino-menus';
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
Expand All @@ -22,15 +23,24 @@ export class UploadSketch extends SketchContribution {
@inject(BoardsServiceProvider)
protected readonly boardsServiceClientImpl: BoardsServiceProvider;

protected readonly onDidChangeEmitter = new Emitter<Readonly<void>>();
readonly onDidChange = this.onDidChangeEmitter.event;

protected uploadInProgress = false;

registerCommands(registry: CommandRegistry): void {
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH, {
execute: () => this.uploadSketch()
execute: () => this.uploadSketch(),
isEnabled: () => !this.uploadInProgress,
});
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER, {
execute: () => this.uploadSketch(true)
execute: () => this.uploadSketch(true),
isEnabled: () => !this.uploadInProgress,
});
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH_TOOLBAR, {
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
isEnabled: () => !this.uploadInProgress,
isToggled: () => this.uploadInProgress,
execute: () => registry.executeCommand(UploadSketch.Commands.UPLOAD_SKETCH.id)
});
}
Expand Down Expand Up @@ -64,11 +74,22 @@ export class UploadSketch extends SketchContribution {
id: UploadSketch.Commands.UPLOAD_SKETCH_TOOLBAR.id,
command: UploadSketch.Commands.UPLOAD_SKETCH_TOOLBAR.id,
tooltip: 'Upload',
priority: 1
priority: 1,
onDidChange: this.onDidChange
});
}

async uploadSketch(usingProgrammer: boolean = false): Promise<void> {

// even with buttons disabled, better to double check if an upload is already in progress
if (this.uploadInProgress) {
return;
}
Comment on lines +84 to +87
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kittaakos

I added this check in order to future-proof the verify-sketch implementation:

https://arduino.atlassian.net/browse/ATL-1045 reports an error (Error: Request upload failed with message: 2 UNKNOWN: exit status 1) when a verify/build is run while another is in progress.

At the moment we only have buttons/menu items, but the check whether or not continue with the action should be inside the action handler itself in my opinion..

Do you have concerns about this approach?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but the check whether or not continue with the action should be inside the action handler itself, in my opinion.

It is there; you added the isEnabled method: https://github.com/arduino/arduino-ide/pull/197/files#diff-5c246e36e23a59755c9cc7d5a116eac5be34d188c0eb681f8c449915cbfe9aacR30.

In theory, if the command handler is not enabled, the command should not run. I am fine with this approach. I just wanted to know if you did hit an error or why did you add it.


// toggle the toolbar button and menu item state.
// uploadInProgress will be set to false whether the upload fails or not
this.uploadInProgress = true;
this.onDidChangeEmitter.fire();
const sketch = await this.sketchServiceClient.currentSketch();
if (!sketch) {
return;
Expand Down Expand Up @@ -131,6 +152,9 @@ export class UploadSketch extends SketchContribution {
} catch (e) {
this.messageService.error(e.toString());
} finally {
this.uploadInProgress = false;
this.onDidChangeEmitter.fire();

if (monitorConfig) {
const { board, port } = monitorConfig;
try {
Expand Down
31 changes: 28 additions & 3 deletions arduino-ide-extension/src/browser/contributions/verify-sketch.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { inject, injectable } from 'inversify';
import { Emitter } from '@theia/core/lib/common/event';
import { CoreService } from '../../common/protocol';
import { ArduinoMenus } from '../menu/arduino-menus';
import { ArduinoToolbar } from '../toolbar/arduino-toolbar';
Expand All @@ -18,15 +19,24 @@ export class VerifySketch extends SketchContribution {
@inject(BoardsServiceProvider)
protected readonly boardsServiceClientImpl: BoardsServiceProvider;

protected readonly onDidChangeEmitter = new Emitter<Readonly<void>>();
readonly onDidChange = this.onDidChangeEmitter.event;

protected verifyInProgress = false;

registerCommands(registry: CommandRegistry): void {
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH, {
execute: () => this.verifySketch()
execute: () => this.verifySketch(),
isEnabled: () => !this.verifyInProgress,
});
registry.registerCommand(VerifySketch.Commands.EXPORT_BINARIES, {
execute: () => this.verifySketch(true)
execute: () => this.verifySketch(true),
isEnabled: () => !this.verifyInProgress,
});
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, {
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
isEnabled: () => !this.verifyInProgress,
isToggled: () => this.verifyInProgress,
execute: () => registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id)
});
}
Expand Down Expand Up @@ -60,12 +70,24 @@ export class VerifySketch extends SketchContribution {
id: VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR.id,
command: VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR.id,
tooltip: 'Verify',
priority: 0
priority: 0,
onDidChange: this.onDidChange
});
}

async verifySketch(exportBinaries?: boolean): Promise<void> {

// even with buttons disabled, better to double check if a verify is already in progress
if (this.verifyInProgress) {
return;
}

// toggle the toolbar button and menu item state.
// verifyInProgress will be set to false whether the compilation fails or not
this.verifyInProgress = true;
this.onDidChangeEmitter.fire();
const sketch = await this.sketchServiceClient.currentSketch();

if (!sketch) {
return;
}
Expand All @@ -90,6 +112,9 @@ export class VerifySketch extends SketchContribution {
this.messageService.info('Done compiling.', { timeout: 1000 });
} catch (e) {
this.messageService.error(e.toString());
} finally {
this.verifyInProgress = false;
this.onDidChangeEmitter.fire();
}
}

Expand Down
14 changes: 12 additions & 2 deletions arduino-ide-extension/src/browser/style/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,25 @@
background: var(--theia-arduino-toolbar-background);
}

.p-TabBar-toolbar .item.arduino-tool-item > div:hover {
background: (--theia-arduino-toolbar-hoverBackground);
.p-TabBar-toolbar .item.arduino-tool-item.enabled:hover > div {
background: var(--theia-arduino-toolbar-hoverBackground);
}

.arduino-verify-sketch--toolbar,
.arduino-upload-sketch--toolbar {
border-radius: 12px;
}

.item.arduino-tool-item.toggled {
background-color: unset;
opacity: 1;
border: none;
}

.item.arduino-tool-item.toggled .arduino-verify-sketch--toolbar {
background-color: var(--theia-arduino-toolbar-toggleBackground) !important;
}

.arduino-tool-icon {
height: 24px;
width: 24px;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export namespace ArduinoToolbarComponent {
commands: CommandRegistry,
labelParser: LabelParser,
commandIsEnabled: (id: string) => boolean,
commandIsToggled: (id: string) => boolean,
executeCommand: (e: React.MouseEvent<HTMLElement>) => void
}
export interface State {
Expand All @@ -39,7 +40,7 @@ export class ArduinoToolbarComponent extends React.Component<ArduinoToolbarCompo
}
}
const command = this.props.commands.getCommand(item.command);
const cls = `${ARDUINO_TOOLBAR_ITEM_CLASS} ${TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM} ${command && this.props.commandIsEnabled(command.id) ? 'enabled' : ''}`
const cls = `${ARDUINO_TOOLBAR_ITEM_CLASS} ${TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM} ${command && this.props.commandIsEnabled(command.id) ? 'enabled' : ''} ${command && this.props.commandIsToggled(command.id) ? 'toggled' : ''}`
return <div key={item.id} className={cls} >
<div className={item.id}>
<div
Expand Down Expand Up @@ -112,6 +113,10 @@ export class ArduinoToolbar extends ReactWidget {
protected commandIsEnabled(command: string): boolean {
return this.commands.isEnabled(command, this);
}
protected readonly doCommandIsToggled = (id: string) => this.commandIsToggled(id);
protected commandIsToggled(command: string): boolean {
return this.commands.isToggled(command, this);
}

protected render(): React.ReactNode {
return <ArduinoToolbarComponent
Expand All @@ -121,6 +126,7 @@ export class ArduinoToolbar extends ReactWidget {
items={[...this.items.values()]}
commands={this.commands}
commandIsEnabled={this.doCommandIsEnabled}
commandIsToggled={this.doCommandIsToggled}
executeCommand={this.executeCommand}
/>
}
Expand Down