diff --git a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts index 4f0109aa8..82fc23ebe 100644 --- a/arduino-ide-extension/src/browser/contributions/upload-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/upload-sketch.ts @@ -22,15 +22,21 @@ export class UploadSketch extends SketchContribution { @inject(BoardsServiceProvider) protected readonly boardsServiceClientImpl: BoardsServiceProvider; + 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) }); } @@ -69,6 +75,16 @@ export class UploadSketch extends SketchContribution { } async uploadSketch(usingProgrammer: boolean = false): Promise { + + // even with buttons disabled, better to double check if an upload is already in progress + if (this.uploadInProgress) { + return; + } + + // toggle the toolbar button and menu item state. + // uploadInProgress will be set to false whether the upload fails or not + this.uploadInProgress = true; + const sketch = await this.sketchServiceClient.currentSketch(); if (!sketch) { return; @@ -131,6 +147,7 @@ export class UploadSketch extends SketchContribution { } catch (e) { this.messageService.error(e.toString()); } finally { + this.uploadInProgress = false; if (monitorConfig) { const { board, port } = monitorConfig; try { diff --git a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts index fe9b3e074..4301d571d 100644 --- a/arduino-ide-extension/src/browser/contributions/verify-sketch.ts +++ b/arduino-ide-extension/src/browser/contributions/verify-sketch.ts @@ -18,15 +18,21 @@ export class VerifySketch extends SketchContribution { @inject(BoardsServiceProvider) protected readonly boardsServiceClientImpl: BoardsServiceProvider; + 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) }); } @@ -65,7 +71,17 @@ export class VerifySketch extends SketchContribution { } async verifySketch(exportBinaries?: boolean): Promise { + + // 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; const sketch = await this.sketchServiceClient.currentSketch(); + if (!sketch) { return; } @@ -90,6 +106,8 @@ export class VerifySketch extends SketchContribution { this.messageService.info('Done compiling.', { timeout: 1000 }); } catch (e) { this.messageService.error(e.toString()); + } finally { + this.verifyInProgress = false; } } diff --git a/arduino-ide-extension/src/browser/style/main.css b/arduino-ide-extension/src/browser/style/main.css index 8bb9d1253..e7341c006 100644 --- a/arduino-ide-extension/src/browser/style/main.css +++ b/arduino-ide-extension/src/browser/style/main.css @@ -15,8 +15,8 @@ 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:hover > div { + background: white; } .arduino-verify-sketch--toolbar, @@ -24,6 +24,15 @@ border-radius: 12px; } +.item.arduino-tool-item.toggled { + background-color: unset; + opacity: 1; +} + +.item.arduino-tool-item.toggled .arduino-verify-sketch--toolbar { + background-color: rgb(255,204,0) !important; +} + .arduino-tool-icon { height: 24px; width: 24px; diff --git a/arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx b/arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx index f9b6b5ab0..91ea3f131 100644 --- a/arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx +++ b/arduino-ide-extension/src/browser/toolbar/arduino-toolbar.tsx @@ -13,6 +13,7 @@ export namespace ArduinoToolbarComponent { commands: CommandRegistry, labelParser: LabelParser, commandIsEnabled: (id: string) => boolean, + commandIsToggled: (id: string) => boolean, executeCommand: (e: React.MouseEvent) => void } export interface State { @@ -39,7 +40,7 @@ export class ArduinoToolbarComponent extends React.Component
this.commandIsToggled(id); + protected commandIsToggled(command: string): boolean { + return this.commands.isToggled(command, this); + } protected render(): React.ReactNode { return }