- Notifications
You must be signed in to change notification settings - Fork 440
/
Copy patharchive-sketch.ts
75 lines (71 loc) · 2.17 KB
/
archive-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
import{injectable}from'@theia/core/shared/inversify';
importdateFormatfrom'dateformat';
import{ArduinoMenus}from'../menu/arduino-menus';
import{
SketchContribution,
Command,
CommandRegistry,
MenuModelRegistry,
}from'./contribution';
import{nls}from'@theia/core/lib/common';
import{CurrentSketch}from'../sketches-service-client-impl';
@injectable()
exportclassArchiveSketchextendsSketchContribution{
overrideregisterCommands(registry: CommandRegistry): void{
registry.registerCommand(ArchiveSketch.Commands.ARCHIVE_SKETCH,{
execute: ()=>this.archiveSketch(),
});
}
overrideregisterMenus(registry: MenuModelRegistry): void{
registry.registerMenuAction(ArduinoMenus.TOOLS__MAIN_GROUP,{
commandId: ArchiveSketch.Commands.ARCHIVE_SKETCH.id,
label: nls.localize('arduino/sketch/archiveSketch','Archive Sketch'),
order: '1',
});
}
privateasyncarchiveSketch(): Promise<void>{
constsketch=awaitthis.sketchServiceClient.currentSketch();
if(!CurrentSketch.isValid(sketch)){
return;
}
constarchiveBasename=`${sketch.name}-${dateFormat(
newDate(),
'yymmdd'
)}a.zip`;
constdefaultContainerUri=awaitthis.defaultUri();
constdefaultUri=defaultContainerUri.resolve(archiveBasename);
constdefaultPath=awaitthis.fileService.fsPath(defaultUri);
const{ filePath, canceled }=awaitthis.dialogService.showSaveDialog({
title: nls.localize(
'arduino/sketch/saveSketchAs',
'Save sketch folder as...'
),
defaultPath,
});
if(!filePath||canceled){
return;
}
constdestinationUri=awaitthis.fileSystemExt.getUri(filePath);
if(!destinationUri){
return;
}
awaitthis.sketchesService.archive(sketch,destinationUri.toString());
this.messageService.info(
nls.localize(
'arduino/sketch/createdArchive',
"Created archive '{0}'.",
archiveBasename
),
{
timeout: 2000,
}
);
}
}
exportnamespaceArchiveSketch{
exportnamespaceCommands{
exportconstARCHIVE_SKETCH: Command={
id: 'arduino-archive-sketch',
};
}
}