Skip to content

Commit ece75b4

Browse files
create new project command
1 parent 41985d5 commit ece75b4

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

editor/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@
175175
{
176176
"command": "4d-analyzer.checkWorkspaceSyntax",
177177
"title": "4D Analyzer: Check workspace syntax"
178+
},
179+
{
180+
"command": "4d-analyzer.createNewProject",
181+
"title": "4D Analyzer: Create a new project"
178182
}
179183
]
180184
},
@@ -207,4 +211,4 @@
207211
"glob": "^11.0.0",
208212
"typescript": "^5.4.5"
209213
}
210-
}
214+
}

editor/src/commands.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as vscode from "vscode";
44
import { WorkspaceFullDocumentDiagnosticReport } from "vscode-languageclient";
55
import { LabeledVersion } from "./labeledVersion";
66
import { Logger } from "./logger";
7+
import * as fs from "fs";
8+
import path = require("path");
79

810
export type Cmd = (...args: any[]) => unknown;
911

@@ -143,3 +145,31 @@ export function checkWorkspaceSyntax(ctx: Ctx): Cmd {
143145
};
144146
}
145147

148+
export function createNewProject(ctx: Ctx): Cmd {
149+
150+
return async () => {
151+
const uri = await vscode.window.showSaveDialog({
152+
})
153+
if (uri) {
154+
const parsed_uri = path.parse(uri.path);
155+
const new_project_name = parsed_uri.name;
156+
157+
//main folder
158+
fs.mkdirSync(uri.path);
159+
const project_folder = path.join(uri.path, "Project");
160+
fs.mkdirSync(project_folder);
161+
162+
//create .4DProject
163+
const content = {
164+
"compatibilityVersion": ctx.get4DVersion().display(),
165+
"tokenizedText" : false,
166+
}
167+
fs.writeFileSync(path.join(project_folder, `${new_project_name}.4DProject`), JSON.stringify(content, null, 4));
168+
169+
const sources = path.join(project_folder, "Sources");
170+
fs.mkdirSync(sources);
171+
fs.mkdirSync(path.join(sources, "Methods"));
172+
fs.mkdirSync(path.join(sources, "Classes"));
173+
}
174+
};
175+
}

editor/src/ctx.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ export class Ctx {
268268
updateTool4D: { call: Commands.updateTool4D },
269269
display4DVersion: { call: Commands.display4DVersion },
270270
cleanUnusedToolVersions: { call: Commands.cleanUnusedToolVersions },
271-
checkWorkspaceSyntax: { call: Commands.checkWorkspaceSyntax }
271+
checkWorkspaceSyntax: { call: Commands.checkWorkspaceSyntax },
272+
createNewProject: { call: Commands.createNewProject },
272273
};
273274

274275
for (const [name, command] of Object.entries(this._commands)) {

editor/src/labeledVersion.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ export class LabeledVersion {
117117
return result;
118118
}
119119

120+
public display(): string {
121+
let result = String(this.version);
122+
if (this.isRRelease) {
123+
result += "R" + this.releaseVersion;
124+
}
125+
126+
127+
return result;
128+
}
129+
120130
private _getInfoplistPath(inExePath: string) {
121131
const serverPath = inExePath;
122132
const type = os.type();

0 commit comments

Comments
 (0)