Skip to content

fix: aligned Add File... behavior with IDE 1.x #1805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions arduino-ide-extension/src/browser/contributions/add-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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 {
Expand Down
15 changes: 3 additions & 12 deletions arduino-ide-extension/src/common/protocol/sketches-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down