Skip to content

Commit 757e8d1

Browse files
committed
Improved statemanagement for ToolbarItem and Menus
1 parent b331419 commit 757e8d1

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

+10-4
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ export class VerifySketch extends SketchContribution {
2222

2323
registerCommands(registry: CommandRegistry): void {
2424
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH, {
25-
execute: () => this.verifySketch()
25+
execute: () => this.verifySketch(),
26+
isEnabled: () => !this.verifyInProgress,
2627
});
2728
registry.registerCommand(VerifySketch.Commands.EXPORT_BINARIES, {
28-
execute: () => this.verifySketch(true)
29+
execute: () => this.verifySketch(true),
30+
isEnabled: () => !this.verifyInProgress,
2931
});
3032
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, {
3133
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
34+
isEnabled: () => !this.verifyInProgress,
3235
isToggled: () => this.verifyInProgress,
3336
execute: () => registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id)
3437
});
@@ -69,10 +72,11 @@ export class VerifySketch extends SketchContribution {
6972

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

75+
// toggle the toolbar button and menu item state.
76+
// verifyInProgress will be set to false whether the compilation fails or not
7277
this.verifyInProgress = true;
7378
const sketch = await this.sketchServiceClient.currentSketch();
74-
this.verifyInProgress = false;
75-
79+
7680
if (!sketch) {
7781
return;
7882
}
@@ -97,6 +101,8 @@ export class VerifySketch extends SketchContribution {
97101
this.messageService.info('Done compiling.', { timeout: 1000 });
98102
} catch (e) {
99103
this.messageService.error(e.toString());
104+
} finally {
105+
this.verifyInProgress = false;
100106
}
101107
}
102108

0 commit comments

Comments
 (0)