mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-27 13:16:43 +00:00
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 <a.kitta@arduino.cc>
This commit is contained in:
parent
b2bf368db9
commit
197cea2a60
@ -7,6 +7,7 @@ import {
|
||||
CommandRegistry,
|
||||
MenuModelRegistry,
|
||||
URI,
|
||||
Sketch,
|
||||
} from './contribution';
|
||||
import { FileDialogService } from '@theia/filesystem/lib/browser';
|
||||
import { nls } from '@theia/core/lib/common';
|
||||
@ -46,9 +47,7 @@ export class AddFile extends SketchContribution {
|
||||
if (!toAddUri) {
|
||||
return;
|
||||
}
|
||||
const sketchUri = new URI(sketch.uri);
|
||||
const filename = toAddUri.path.base;
|
||||
const targetUri = sketchUri.resolve('data').resolve(filename);
|
||||
const { uri: targetUri, filename } = this.resolveTarget(sketch, toAddUri);
|
||||
const exists = await this.fileService.exists(targetUri);
|
||||
if (exists) {
|
||||
const { response } = await remote.dialog.showMessageBox({
|
||||
@ -80,6 +79,22 @@ export class AddFile extends SketchContribution {
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// https://github.com/arduino/arduino-ide/issues/284#issuecomment-1364533662
|
||||
// File the file to add has one of the following extension, it goes to the sketch folder root: .ino, .h, .cpp, .c, .S
|
||||
// Otherwise, the files goes to the `data` folder inside the sketch folder root.
|
||||
private resolveTarget(
|
||||
sketch: Sketch,
|
||||
toAddUri: URI
|
||||
): { uri: URI; filename: string } {
|
||||
const path = toAddUri.path;
|
||||
const filename = path.base;
|
||||
let root = new URI(sketch.uri);
|
||||
if (!Sketch.Extensions.CODE_FILES.includes(path.ext)) {
|
||||
root = root.resolve('data');
|
||||
}
|
||||
return { uri: root.resolve(filename), filename: filename };
|
||||
}
|
||||
}
|
||||
|
||||
export namespace AddFile {
|
||||
|
@ -162,18 +162,9 @@ export namespace Sketch {
|
||||
}
|
||||
export namespace Extensions {
|
||||
export const MAIN = ['.ino', '.pde'];
|
||||
export const SOURCE = ['.c', '.cpp', '.s'];
|
||||
export const ADDITIONAL = [
|
||||
'.h',
|
||||
'.c',
|
||||
'.hpp',
|
||||
'.hh',
|
||||
'.cpp',
|
||||
'.S',
|
||||
'.json',
|
||||
'.md',
|
||||
'.adoc',
|
||||
];
|
||||
export const SOURCE = ['.c', '.cpp', '.S'];
|
||||
export const CODE_FILES = [...MAIN, ...SOURCE, '.h', '.hh', '.hpp'];
|
||||
export const ADDITIONAL = [...CODE_FILES, '.json', '.md', '.adoc'];
|
||||
export const ALL = Array.from(new Set([...MAIN, ...SOURCE, ...ADDITIONAL]));
|
||||
}
|
||||
export function isInSketch(uri: string | URI, sketch: Sketch): boolean {
|
||||
|
Loading…
x
Reference in New Issue
Block a user