Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 197cea2

Browse filesBrowse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
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>
1 parent b2bf368 commit 197cea2
Copy full SHA for 197cea2

File tree

Expand file treeCollapse file tree

2 files changed

+21
-15
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+21
-15
lines changed

‎arduino-ide-extension/src/browser/contributions/add-file.ts

Copy file name to clipboardExpand all lines: arduino-ide-extension/src/browser/contributions/add-file.ts
+18-3Lines changed: 18 additions & 3 deletions
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 {

‎arduino-ide-extension/src/common/protocol/sketches-service.ts

Copy file name to clipboardExpand all lines: arduino-ide-extension/src/common/protocol/sketches-service.ts
+3-12Lines changed: 3 additions & 12 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.