Skip to content

Commit 7ca713a

Browse files
committed
Add PDE file setup and enhance command functionality
- Implement setupPDEFiles to open .pde and .java files in the workspace. - Update setupCommands to include autosave and new window options. - Modify setupSelectedVersion error message for Processing version requirement. - Clean up console logs in setupSidebar. - Update package.json to include new activation events and configuration options.
1 parent 27f06a8 commit 7ca713a

File tree

7 files changed

+64
-30
lines changed

7 files changed

+64
-30
lines changed

client/src/extension.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { setupCommands } from './setupCommands';
99
import { setupLanguageServer } from './setupLanguageServer';
1010
import { setupSidebar } from './setupSidebar';
1111
import { setupDecorators } from './setupDecorators';
12+
import { setupPDEFiles } from './setupPDEFiles';
1213

1314

1415
export interface ProcessingVersion {
@@ -30,6 +31,7 @@ export async function activate(context: ExtensionContext) {
3031
setupLanguageServer();
3132
setupSidebar();
3233
setupDecorators(context);
34+
setupPDEFiles();
3335
}
3436

3537

client/src/setupCommands.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,21 @@ import { ExtensionContext, commands, Uri, window, workspace } from 'vscode';
33
import { state } from './extension';
44

55
export function setupCommands(context: ExtensionContext) {
6+
const config = workspace.getConfiguration('processing');
7+
68
const runSketch = commands.registerCommand('processing.sketch.run', (resource: Uri) => {
9+
const autosave = config.get<boolean>('autosave');
10+
if (autosave === true) {
11+
// Save all files before running the sketch
12+
commands.executeCommand('workbench.action.files.saveAll');
13+
}
14+
if (resource == undefined) {
15+
const editor = window.activeTextEditor;
16+
if (editor) {
17+
resource = editor.document.uri;
18+
}
19+
}
20+
721
// TODO: If the command is run from a keyboard shortcut, find the current file
822
if (!resource) {
923
return;
@@ -53,29 +67,16 @@ export function setupCommands(context: ExtensionContext) {
5367
return;
5468
}
5569

56-
workspace.updateWorkspaceFolders(
57-
workspace.workspaceFolders ? workspace.workspaceFolders.length : 0,
58-
null,
59-
{ uri: Uri.file(folder) }
60-
);
61-
await commands.executeCommand('workbench.view.explorer');
62-
const folderName = folder.split('/').pop();
63-
const sketchFile = Uri.file(`${folder}/${folderName}.pde`);
64-
try {
65-
if (!workspace.fs.stat(sketchFile)) {
66-
return;
67-
}
6870

69-
const doc = await workspace.openTextDocument(sketchFile);
70-
if (!doc) {
71-
window.showErrorMessage(`Could not open sketch file: ${sketchFile.fsPath}`);
72-
return;
73-
}
74-
await window.showTextDocument(doc, { preview: false });
75-
window.activeTextEditor?.revealRange(doc.lineAt(0).range);
76-
} catch (error) {
77-
window.showErrorMessage(`Could not open sketch file: ${sketchFile.fsPath}`);
78-
console.error(error);
71+
const newWindow = config.get<boolean>('newWindow');
72+
if (newWindow === true) {
73+
await commands.executeCommand('vscode.openFolder', Uri.file(folder), true);
74+
} else {
75+
workspace.updateWorkspaceFolders(
76+
workspace.workspaceFolders ? workspace.workspaceFolders.length : 0,
77+
null,
78+
{ uri: Uri.file(folder) }
79+
);
7980
}
8081
});
8182

@@ -85,7 +86,9 @@ export function setupCommands(context: ExtensionContext) {
8586
canSelectFolders: true,
8687
canSelectMany: false,
8788
title: "Select a folder to create a new sketch in",
88-
defaultUri: workspace.workspaceFolders ? workspace.workspaceFolders[0].uri : undefined,
89+
defaultUri: workspace.workspaceFolders && workspace.workspaceFolders[0]
90+
? Uri.joinPath(workspace.workspaceFolders[0].uri, '..')
91+
: undefined,
8992
});
9093
if (!folder || folder.length === 0) {
9194
return;

client/src/setupPDEFiles.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { RelativePattern, window, workspace, WorkspaceFolder } from 'vscode';
2+
3+
export function setupPDEFiles() {
4+
workspace.onDidChangeWorkspaceFolders(event => {
5+
event.added.forEach(OpenSketchFiles);
6+
});
7+
8+
9+
workspace.workspaceFolders?.forEach(OpenSketchFiles);
10+
}
11+
12+
async function OpenSketchFiles(folder: WorkspaceFolder) {
13+
// find all the .pde files in the folder
14+
const files = await workspace.findFiles(new RelativePattern(folder, '*.{pde,java}'));
15+
16+
for (const file of files) {
17+
const doc = await workspace.openTextDocument(file);
18+
if (!doc) {
19+
window.showErrorMessage(`Could not open sketch file: ${file.fsPath}`);
20+
return;
21+
}
22+
await window.showTextDocument(doc, { preview: false });
23+
}
24+
}

client/src/setupSelectedVersion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export async function setupSelectedVersion(context: ExtensionContext) {
7777

7878
if (!versions || versions.length === 0) {
7979
await window.showErrorMessage(
80-
`Processing not found, please install Processing 4.4.5 or higher and open it at least once.`
80+
`Processing not found, please install Processing 4.4.6 or higher and open it at least once.`
8181
);
8282
return;
8383
}

client/src/setupSidebar.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ async function setupExamples() {
3333
console.error(`exec error: ${error}`);
3434
return;
3535
}
36-
console.log(`stdout: ${stdout}`);
3736
resolve(JSON.parse(stdout));
3837
});
3938
});
@@ -49,7 +48,6 @@ async function setupSketchbook() {
4948
console.error(`exec error: ${error}`);
5049
return;
5150
}
52-
console.log(`stdout: ${stdout}`);
5351
resolve(JSON.parse(stdout));
5452
});
5553
});
@@ -100,7 +98,7 @@ class ProcessingWindowDataProvider implements TreeDataProvider<FolderTreeItem |
10098
}
10199
getChildren(element?: FolderTreeItem): ProviderResult<(FolderTreeItem | SketchTreeItem)[]> {
102100
if (element === undefined) {
103-
return this.folders.flatMap((folder) => folder.children?.map(child => new FolderTreeItem(child)) ?? []);
101+
return this.folders.map((folder) => new FolderTreeItem(folder)) ?? [];
104102
} else {
105103
const sketches = element.folder.sketches?.map((sketch) => {
106104
return new SketchTreeItem(sketch);

client/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"root":["./src/compareversions.ts","./src/extension.ts","./src/setupcommands.ts","./src/setupdecorators.ts","./src/setuplanguageserver.ts","./src/setupselectedversion.ts","./src/setupsidebar.ts"],"version":"5.8.3"}
1+
{"root":["./src/compareversions.ts","./src/extension.ts","./src/setupcommands.ts","./src/setupdecorators.ts","./src/setuplanguageserver.ts","./src/setuppdefiles.ts","./src/setupselectedversion.ts","./src/setupsidebar.ts"],"version":"5.8.3"}

package.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
"vscode": "^1.75.0"
1919
},
2020
"activationEvents": [
21-
"onLanguage:plaintext"
21+
"onStartupFinished",
22+
"workspaceContains:**/*.pde"
2223
],
2324
"main": "./client/out/extension",
2425
"contributes": {
@@ -102,8 +103,14 @@
102103
"processing.autosave": {
103104
"scope": "window",
104105
"type": "boolean",
105-
"default": false,
106+
"default": true,
106107
"description": "Automatically save the sketch before running it."
108+
},
109+
"processing.newWindow": {
110+
"scope": "window",
111+
"type": "boolean",
112+
"default": true,
113+
"description": "Open sketches in a new window. If disabled, the current window will be reused."
107114
}
108115
}
109116
},

0 commit comments

Comments
 (0)