Skip to content

Commit a963e32

Browse files
committed
Support toggled state in arduino toolbar items
fix hover state on toolbar items Improved statemanagement for ToolbarItem and Menus Disable Upload buttons while a sketch upload is already in progress toggled state to have override disabled button opacity doublecheck internal status before verify/upload a sketch fixes after code review
1 parent 9cd9146 commit a963e32

File tree

5 files changed

+66
-7
lines changed

5 files changed

+66
-7
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

+9
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,15 @@ export class ArduinoFrontendContribution implements FrontendApplicationContribut
418418
},
419419
description: 'Background color of the toolbar items when hovering over them. Such as Upload, Verify, etc.'
420420
},
421+
{
422+
id: 'arduino.toolbar.toggleBackground',
423+
defaults: {
424+
dark: 'editor.selectionBackground',
425+
light: 'editor.selectionBackground',
426+
hc: 'activityBar.inactiveForeground'
427+
},
428+
description: 'Toggle color of the toolbar items when they are currently toggled (the command is in progress)'
429+
},
421430
{
422431
id: 'arduino.output.foreground',
423432
defaults: {

arduino-ide-extension/src/browser/contributions/upload-sketch.ts

+19-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ export class UploadSketch extends SketchContribution {
2222
@inject(BoardsServiceProvider)
2323
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
2424

25+
protected uploadInProgress = false;
26+
2527
registerCommands(registry: CommandRegistry): void {
2628
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH, {
27-
execute: () => this.uploadSketch()
29+
execute: () => this.uploadSketch(),
30+
isEnabled: () => !this.uploadInProgress,
2831
});
2932
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH_USING_PROGRAMMER, {
30-
execute: () => this.uploadSketch(true)
33+
execute: () => this.uploadSketch(true),
34+
isEnabled: () => !this.uploadInProgress,
3135
});
3236
registry.registerCommand(UploadSketch.Commands.UPLOAD_SKETCH_TOOLBAR, {
3337
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
38+
isEnabled: () => !this.uploadInProgress,
39+
isToggled: () => this.uploadInProgress,
3440
execute: () => registry.executeCommand(UploadSketch.Commands.UPLOAD_SKETCH.id)
3541
});
3642
}
@@ -69,6 +75,16 @@ export class UploadSketch extends SketchContribution {
6975
}
7076

7177
async uploadSketch(usingProgrammer: boolean = false): Promise<void> {
78+
79+
// even with buttons disabled, better to double check if an upload is already in progress
80+
if (this.uploadInProgress) {
81+
return;
82+
}
83+
84+
// toggle the toolbar button and menu item state.
85+
// uploadInProgress will be set to false whether the upload fails or not
86+
this.uploadInProgress = true;
87+
7288
const sketch = await this.sketchServiceClient.currentSketch();
7389
if (!sketch) {
7490
return;
@@ -131,6 +147,7 @@ export class UploadSketch extends SketchContribution {
131147
} catch (e) {
132148
this.messageService.error(e.toString());
133149
} finally {
150+
this.uploadInProgress = false;
134151
if (monitorConfig) {
135152
const { board, port } = monitorConfig;
136153
try {

arduino-ide-extension/src/browser/contributions/verify-sketch.ts

+20-2
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,21 @@ export class VerifySketch extends SketchContribution {
1818
@inject(BoardsServiceProvider)
1919
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
2020

21+
protected verifyInProgress = false;
22+
2123
registerCommands(registry: CommandRegistry): void {
2224
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH, {
23-
execute: () => this.verifySketch()
25+
execute: () => this.verifySketch(),
26+
isEnabled: () => !this.verifyInProgress,
2427
});
2528
registry.registerCommand(VerifySketch.Commands.EXPORT_BINARIES, {
26-
execute: () => this.verifySketch(true)
29+
execute: () => this.verifySketch(true),
30+
isEnabled: () => !this.verifyInProgress,
2731
});
2832
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, {
2933
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
34+
isEnabled: () => !this.verifyInProgress,
35+
isToggled: () => this.verifyInProgress,
3036
execute: () => registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id)
3137
});
3238
}
@@ -65,7 +71,17 @@ export class VerifySketch extends SketchContribution {
6571
}
6672

6773
async verifySketch(exportBinaries?: boolean): Promise<void> {
74+
75+
// even with buttons disabled, better to double check if a verify is already in progress
76+
if (this.verifyInProgress) {
77+
return;
78+
}
79+
80+
// toggle the toolbar button and menu item state.
81+
// verifyInProgress will be set to false whether the compilation fails or not
82+
this.verifyInProgress = true;
6883
const sketch = await this.sketchServiceClient.currentSketch();
84+
6985
if (!sketch) {
7086
return;
7187
}
@@ -90,6 +106,8 @@ export class VerifySketch extends SketchContribution {
90106
this.messageService.info('Done compiling.', { timeout: 1000 });
91107
} catch (e) {
92108
this.messageService.error(e.toString());
109+
} finally {
110+
this.verifyInProgress = false;
93111
}
94112
}
95113

arduino-ide-extension/src/browser/style/main.css

+11-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,24 @@
1515
background: var(--theia-arduino-toolbar-background);
1616
}
1717

18-
.p-TabBar-toolbar .item.arduino-tool-item > div:hover {
19-
background: (--theia-arduino-toolbar-hoverBackground);
18+
.p-TabBar-toolbar .item.arduino-tool-item:hover > div {
19+
background: var(--theia-arduino-toolbar-hoverBackground);
2020
}
2121

2222
.arduino-verify-sketch--toolbar,
2323
.arduino-upload-sketch--toolbar {
2424
border-radius: 12px;
2525
}
2626

27+
.item.arduino-tool-item.toggled {
28+
background-color: unset;
29+
opacity: 1;
30+
}
31+
32+
.item.arduino-tool-item.toggled .arduino-verify-sketch--toolbar {
33+
background-color: var(--theia-arduino-toolbar-toggleBackground) !important;
34+
}
35+
2736
.arduino-tool-icon {
2837
height: 24px;
2938
width: 24px;

arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export namespace ArduinoToolbarComponent {
1313
commands: CommandRegistry,
1414
labelParser: LabelParser,
1515
commandIsEnabled: (id: string) => boolean,
16+
commandIsToggled: (id: string) => boolean,
1617
executeCommand: (e: React.MouseEvent<HTMLElement>) => void
1718
}
1819
export interface State {
@@ -39,7 +40,7 @@ export class ArduinoToolbarComponent extends React.Component<ArduinoToolbarCompo
3940
}
4041
}
4142
const command = this.props.commands.getCommand(item.command);
42-
const cls = `${ARDUINO_TOOLBAR_ITEM_CLASS} ${TabBarToolbar.Styles.TAB_BAR_TOOLBAR_ITEM} ${command && this.props.commandIsEnabled(command.id) ? 'enabled' : ''}`
43+
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' : ''}`
4344
return <div key={item.id} className={cls} >
4445
<div className={item.id}>
4546
<div
@@ -112,6 +113,10 @@ export class ArduinoToolbar extends ReactWidget {
112113
protected commandIsEnabled(command: string): boolean {
113114
return this.commands.isEnabled(command, this);
114115
}
116+
protected readonly doCommandIsToggled = (id: string) => this.commandIsToggled(id);
117+
protected commandIsToggled(command: string): boolean {
118+
return this.commands.isToggled(command, this);
119+
}
115120

116121
protected render(): React.ReactNode {
117122
return <ArduinoToolbarComponent
@@ -121,6 +126,7 @@ export class ArduinoToolbar extends ReactWidget {
121126
items={[...this.items.values()]}
122127
commands={this.commands}
123128
commandIsEnabled={this.doCommandIsEnabled}
129+
commandIsToggled={this.doCommandIsToggled}
124130
executeCommand={this.executeCommand}
125131
/>
126132
}

0 commit comments

Comments
 (0)