Skip to content

Commit d04dba2

Browse files
committed
Support toggled state in arduino toolbar items
1 parent ac50205 commit d04dba2

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export class VerifySketch extends SketchContribution {
1818
@inject(BoardsServiceProvider)
1919
protected readonly boardsServiceClientImpl: BoardsServiceProvider;
2020

21+
verifyInProgress = false;
22+
2123
registerCommands(registry: CommandRegistry): void {
2224
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH, {
2325
execute: () => this.verifySketch()
@@ -27,6 +29,7 @@ export class VerifySketch extends SketchContribution {
2729
});
2830
registry.registerCommand(VerifySketch.Commands.VERIFY_SKETCH_TOOLBAR, {
2931
isVisible: widget => ArduinoToolbar.is(widget) && widget.side === 'left',
32+
isToggled: () => this.verifyInProgress,
3033
execute: () => registry.executeCommand(VerifySketch.Commands.VERIFY_SKETCH.id)
3134
});
3235
}
@@ -65,7 +68,11 @@ export class VerifySketch extends SketchContribution {
6568
}
6669

6770
async verifySketch(exportBinaries?: boolean): Promise<void> {
71+
72+
this.verifyInProgress = true;
6873
const sketch = await this.sketchServiceClient.currentSketch();
74+
this.verifyInProgress = false;
75+
6976
if (!sketch) {
7077
return;
7178
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@
2424
border-radius: 12px;
2525
}
2626

27+
.item.arduino-tool-item.toggled {
28+
background-color: unset;
29+
}
30+
31+
.item.arduino-tool-item.toggled .arduino-verify-sketch--toolbar {
32+
background-color: rgb(255,204,0) !important;
33+
}
34+
2735
.arduino-tool-icon {
2836
height: 24px;
2937
width: 24px;

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

Lines changed: 7 additions & 1 deletion
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)