- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathsketchbook.ts
64 lines (58 loc) · 1.86 KB
/
sketchbook.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import{injectable}from'@theia/core/shared/inversify';
import{CommandHandler}from'@theia/core/lib/common/command';
import{MenuModelRegistry}from'./contribution';
import{ArduinoMenus}from'../menu/arduino-menus';
import{Examples}from'./examples';
import{SketchContainer,SketchesError}from'../../common/protocol';
import{OpenSketch}from'./open-sketch';
import{nls}from'@theia/core/lib/common/nls';
@injectable()
exportclassSketchbookextendsExamples{
overrideonStart(): void{
this.sketchServiceClient.onSketchbookDidChange(()=>this.update());
this.configService.onDidChangeSketchDirUri(()=>this.update());
}
overrideasynconReady(): Promise<void>{
this.update();
}
protectedoverrideupdate(): void{
this.sketchesService.getSketches({}).then((container)=>{
this.register(container);
this.menuManager.update();
});
}
overrideregisterMenus(registry: MenuModelRegistry): void{
registry.registerSubmenu(
ArduinoMenus.FILE__SKETCHBOOK_SUBMENU,
nls.localize('arduino/sketch/sketchbook','Sketchbook'),
{order: '3'}
);
}
privateregister(container: SketchContainer): void{
this.toDispose.dispose();
this.registerRecursively(
[...container.children, ...container.sketches],
ArduinoMenus.FILE__SKETCHBOOK_SUBMENU,
this.toDispose
);
}
protectedoverridecreateHandler(uri: string): CommandHandler{
return{
execute: async()=>{
try{
awaitthis.commandService.executeCommand(
OpenSketch.Commands.OPEN_SKETCH.id,
uri
);
}catch(err){
if(SketchesError.NotFound.is(err)){
// Force update the menu items to remove the absent sketch.
this.update();
}else{
throwerr;
}
}
},
};
}
}