Skip to content
Open
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
22 changes: 21 additions & 1 deletion client/src/setupPDEFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,33 @@ export function setupPDEFiles() {
async function OpenSketchFiles(folder: WorkspaceFolder) {
// find all the .pde files in the folder
const files = await workspace.findFiles(new RelativePattern(folder, '*.{pde,java}'));
let mainFile = files.find(file => file.fsPath.endsWith(`${folder.name}.pde`));
// read the properties file if it exists
// and check if main has been declared
const [propertiesFile] = await workspace.findFiles(new RelativePattern(folder, 'sketch.properties'));
if (propertiesFile) {
const propertiesDoc = await workspace.openTextDocument(propertiesFile);
const propertiesText = propertiesDoc.getText();
const mainMatch = propertiesText.match(/main\s*=\s*(\S+)/);
if (mainMatch) {
const mainFileName = mainMatch[1];
mainFile = files.find(file => file.fsPath.endsWith(mainFileName));
}
}
if (mainFile) {
// move the declared main file to the front
files.splice(files.indexOf(mainFile), 1);
files.unshift(mainFile);
}

for (const file of files) {
const doc = await workspace.openTextDocument(file);
if (!doc) {
window.showErrorMessage(`Could not open sketch file: ${file.fsPath}`);
return;
}
await window.showTextDocument(doc, { preview: false });
await window.showTextDocument(doc, { preview: false, preserveFocus: true });
}
if (mainFile) { await window.showTextDocument(mainFile, { preview: false }); }

}