1
1
import { inject , injectable } from 'inversify' ;
2
+ import { Emitter } from '@theia/core/lib/common/event' ;
2
3
import { CoreService } from '../../common/protocol' ;
3
4
import { ArduinoMenus } from '../menu/arduino-menus' ;
4
5
import { ArduinoToolbar } from '../toolbar/arduino-toolbar' ;
@@ -18,15 +19,24 @@ export class VerifySketch extends SketchContribution {
18
19
@inject ( BoardsServiceProvider )
19
20
protected readonly boardsServiceClientImpl : BoardsServiceProvider ;
20
21
22
+ protected readonly onDidChangeEmitter = new Emitter < Readonly < void > > ( ) ;
23
+ readonly onDidChange = this . onDidChangeEmitter . event ;
24
+
25
+ protected verifyInProgress = false ;
26
+
21
27
registerCommands ( registry : CommandRegistry ) : void {
22
28
registry . registerCommand ( VerifySketch . Commands . VERIFY_SKETCH , {
23
- execute : ( ) => this . verifySketch ( )
29
+ execute : ( ) => this . verifySketch ( ) ,
30
+ isEnabled : ( ) => ! this . verifyInProgress ,
24
31
} ) ;
25
32
registry . registerCommand ( VerifySketch . Commands . EXPORT_BINARIES , {
26
- execute : ( ) => this . verifySketch ( true )
33
+ execute : ( ) => this . verifySketch ( true ) ,
34
+ isEnabled : ( ) => ! this . verifyInProgress ,
27
35
} ) ;
28
36
registry . registerCommand ( VerifySketch . Commands . VERIFY_SKETCH_TOOLBAR , {
29
37
isVisible : widget => ArduinoToolbar . is ( widget ) && widget . side === 'left' ,
38
+ isEnabled : ( ) => ! this . verifyInProgress ,
39
+ isToggled : ( ) => this . verifyInProgress ,
30
40
execute : ( ) => registry . executeCommand ( VerifySketch . Commands . VERIFY_SKETCH . id )
31
41
} ) ;
32
42
}
@@ -60,12 +70,24 @@ export class VerifySketch extends SketchContribution {
60
70
id : VerifySketch . Commands . VERIFY_SKETCH_TOOLBAR . id ,
61
71
command : VerifySketch . Commands . VERIFY_SKETCH_TOOLBAR . id ,
62
72
tooltip : 'Verify' ,
63
- priority : 0
73
+ priority : 0 ,
74
+ onDidChange : this . onDidChange
64
75
} ) ;
65
76
}
66
77
67
78
async verifySketch ( exportBinaries ?: boolean ) : Promise < void > {
79
+
80
+ // even with buttons disabled, better to double check if a verify is already in progress
81
+ if ( this . verifyInProgress ) {
82
+ return ;
83
+ }
84
+
85
+ // toggle the toolbar button and menu item state.
86
+ // verifyInProgress will be set to false whether the compilation fails or not
87
+ this . verifyInProgress = true ;
88
+ this . onDidChangeEmitter . fire ( ) ;
68
89
const sketch = await this . sketchServiceClient . currentSketch ( ) ;
90
+
69
91
if ( ! sketch ) {
70
92
return ;
71
93
}
@@ -90,6 +112,9 @@ export class VerifySketch extends SketchContribution {
90
112
this . messageService . info ( 'Done compiling.' , { timeout : 1000 } ) ;
91
113
} catch ( e ) {
92
114
this . messageService . error ( e . toString ( ) ) ;
115
+ } finally {
116
+ this . verifyInProgress = false ;
117
+ this . onDidChangeEmitter . fire ( ) ;
93
118
}
94
119
}
95
120
0 commit comments