- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy pathsave-sketch.ts
86 lines (79 loc) · 2.72 KB
/
save-sketch.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import{CommonCommands}from'@theia/core/lib/browser/common-frontend-contribution';
import{MessageService}from'@theia/core/lib/common/message-service';
import{nls}from'@theia/core/lib/common/nls';
import{injectable}from'@theia/core/shared/inversify';
import{ArduinoMenus}from'../menu/arduino-menus';
import{CurrentSketch}from'../sketches-service-client-impl';
import{ApplicationConnectionStatusContribution}from'../theia/core/connection-status-service';
import{
Command,
CommandRegistry,
KeybindingRegistry,
MenuModelRegistry,
SketchContribution,
}from'./contribution';
import{SaveAsSketch}from'./save-as-sketch';
@injectable()
exportclassSaveSketchextendsSketchContribution{
overrideregisterCommands(registry: CommandRegistry): void{
registry.registerCommand(SaveSketch.Commands.SAVE_SKETCH,{
execute: ()=>this.saveSketch(),
});
}
overrideregisterMenus(registry: MenuModelRegistry): void{
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP,{
commandId: SaveSketch.Commands.SAVE_SKETCH.id,
label: nls.localize('vscode/fileCommands/save','Save'),
order: '7',
});
}
overrideregisterKeybindings(registry: KeybindingRegistry): void{
registry.registerKeybinding({
command: SaveSketch.Commands.SAVE_SKETCH.id,
keybinding: 'CtrlCmd+S',
});
}
asyncsaveSketch(): Promise<void>{
assertConnectedToBackend({
connectionStatusService: this.connectionStatusService,
messageService: this.messageService,
});
constsketch=awaitthis.sketchServiceClient.currentSketch();
if(!CurrentSketch.isValid(sketch)){
return;
}
constisTemp=awaitthis.sketchesService.isTemp(sketch);
if(isTemp){
returnthis.commandService.executeCommand(
SaveAsSketch.Commands.SAVE_AS_SKETCH.id,
{
execOnlyIfTemp: false,
openAfterMove: true,
wipeOriginal: true,
}
);
}
returnthis.commandService.executeCommand(CommonCommands.SAVE_ALL.id);
}
}
exportnamespaceSaveSketch{
exportnamespaceCommands{
exportconstSAVE_SKETCH: Command={
id: 'arduino-save-sketch',
};
}
}
// https://github.com/arduino/arduino-ide/issues/2081
exportfunctionassertConnectedToBackend(param: {
connectionStatusService: ApplicationConnectionStatusContribution;
messageService: MessageService;
}): void{
if(param.connectionStatusService.offlineStatus==='backend'){
constmessage=nls.localize(
'theia/core/couldNotSave',
'Could not save the sketch. Please copy your unsaved work into your favorite text editor, and restart the IDE.'
);
param.messageService.error(message);
thrownewError(message);
}
}