Skip to content

Commit b0115ea

Browse files
author
Akos Kitta
committed
fix: aligned Add File... behavior with IDE 1.x
- code files will be copied to sketch folder root - other files go under the `data` folder in the sketch folder root Closes #284 Signed-off-by: Akos Kitta <[email protected]>
1 parent 76f9f63 commit b0115ea

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

Diff for: arduino-ide-extension/src/browser/contributions/add-file.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
CommandRegistry,
88
MenuModelRegistry,
99
URI,
10+
Sketch,
1011
} from './contribution';
1112
import { FileDialogService } from '@theia/filesystem/lib/browser';
1213
import { nls } from '@theia/core/lib/common';
@@ -46,9 +47,7 @@ export class AddFile extends SketchContribution {
4647
if (!toAddUri) {
4748
return;
4849
}
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);
5251
const exists = await this.fileService.exists(targetUri);
5352
if (exists) {
5453
const { response } = await remote.dialog.showMessageBox({
@@ -80,6 +79,22 @@ export class AddFile extends SketchContribution {
8079
}
8180
);
8281
}
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+
}
8398
}
8499

85100
export namespace AddFile {

Diff for: arduino-ide-extension/src/common/protocol/sketches-service.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -162,18 +162,9 @@ export namespace Sketch {
162162
}
163163
export namespace Extensions {
164164
export const MAIN = ['.ino', '.pde'];
165-
export const SOURCE = ['.c', '.cpp', '.s'];
166-
export const ADDITIONAL = [
167-
'.h',
168-
'.c',
169-
'.hpp',
170-
'.hh',
171-
'.cpp',
172-
'.S',
173-
'.json',
174-
'.md',
175-
'.adoc',
176-
];
165+
export const SOURCE = ['.c', '.cpp', '.S'];
166+
export const CODE_FILES = [...MAIN, ...SOURCE, '.h', '.hh', '.hpp'];
167+
export const ADDITIONAL = [...CODE_FILES, '.json', '.md', '.adoc'];
177168
export const ALL = Array.from(new Set([...MAIN, ...SOURCE, ...ADDITIONAL]));
178169
}
179170
export function isInSketch(uri: string | URI, sketch: Sketch): boolean {

0 commit comments

Comments
 (0)