|
7 | 7 | CommandRegistry,
|
8 | 8 | MenuModelRegistry,
|
9 | 9 | URI,
|
| 10 | + Sketch, |
10 | 11 | } from './contribution';
|
11 | 12 | import { FileDialogService } from '@theia/filesystem/lib/browser';
|
12 | 13 | import { nls } from '@theia/core/lib/common';
|
@@ -46,9 +47,7 @@ export class AddFile extends SketchContribution {
|
46 | 47 | if (!toAddUri) {
|
47 | 48 | return;
|
48 | 49 | }
|
49 |
| - const sketchUri = new URI(sketch.uri); |
50 |
| - const filename = toAddUri.path.base; |
51 |
| - const targetUri = sketchUri.resolve('data').resolve(filename); |
| 50 | + const { uri: targetUri, filename } = this.resolveTarget(sketch, toAddUri); |
52 | 51 | const exists = await this.fileService.exists(targetUri);
|
53 | 52 | if (exists) {
|
54 | 53 | const { response } = await remote.dialog.showMessageBox({
|
@@ -80,6 +79,22 @@ export class AddFile extends SketchContribution {
|
80 | 79 | }
|
81 | 80 | );
|
82 | 81 | }
|
| 82 | + |
| 83 | + // https://github.com/arduino/arduino-ide/issues/284#issuecomment-1364533662 |
| 84 | + // File the file to add has one of the following extension, it goes to the sketch folder root: .ino, .h, .cpp, .c, .S |
| 85 | + // Otherwise, the files goes to the `data` folder inside the sketch folder root. |
| 86 | + private resolveTarget( |
| 87 | + sketch: Sketch, |
| 88 | + toAddUri: URI |
| 89 | + ): { uri: URI; filename: string } { |
| 90 | + const path = toAddUri.path; |
| 91 | + const filename = path.base; |
| 92 | + let root = new URI(sketch.uri); |
| 93 | + if (!Sketch.Extensions.CODE_FILES.includes(path.ext)) { |
| 94 | + root = root.resolve('data'); |
| 95 | + } |
| 96 | + return { uri: root.resolve(filename), filename: filename }; |
| 97 | + } |
83 | 98 | }
|
84 | 99 |
|
85 | 100 | export namespace AddFile {
|
|
0 commit comments