Skip to content

Commit d8b1246

Browse files
Added a "New project" button
1 parent fcf16ea commit d8b1246

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@
253253
"title": "TKVSC: Add workspace folder to Projects",
254254
"icon": "$(repo-create)"
255255
},
256+
{
257+
"command": "totk-editor.createProject",
258+
"title": "TKVSC: Create New Project",
259+
"icon": "$(new-folder)"
260+
},
256261
{
257262
"command": "totk-editor.addProjectFolders",
258263
"title": "TKVSC: Add Projects via File Explorer",
@@ -502,6 +507,11 @@
502507
"when": "view == totk-editor.archives && !config.totk-editor.enableCanonicalSavePropagation",
503508
"group": "navigation"
504509
},
510+
{
511+
"command": "totk-editor.createProject",
512+
"when": "view == totk-editor.archives",
513+
"group": "navigation"
514+
},
505515
{
506516
"command": "totk-editor.addProjectFolders",
507517
"when": "view == totk-editor.archives",

src/archiveTree.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,58 @@ export function registerArchiveTree(context: vscode.ExtensionContext): ArchiveTr
496496
}
497497
};
498498

499+
const createProject = async (): Promise<void> => {
500+
const config = vscode.workspace.getConfiguration('TKVSC');
501+
const projectsPath = config.get<string>('projectsPath');
502+
if (!projectsPath) {
503+
void vscode.window.showErrorMessage('TKVSC: Please set a default projects path in settings (TKVSC.projectsPath) first.');
504+
return;
505+
}
506+
507+
const projectName = await vscode.window.showInputBox({
508+
prompt: 'Enter the name for the new project',
509+
placeHolder: 'My New Project'
510+
});
511+
512+
if (!projectName) {
513+
return;
514+
}
515+
516+
const projectFolderUri = vscode.Uri.file(path.join(projectsPath, projectName));
517+
518+
try {
519+
// Check if exists
520+
try {
521+
const stat = await vscode.workspace.fs.stat(projectFolderUri);
522+
if (stat) {
523+
void vscode.window.showErrorMessage(`TKVSC: Project folder '${projectName}' already exists at the specified path.`);
524+
return;
525+
}
526+
} catch {
527+
// Doesn't exist, which is good
528+
}
529+
530+
// Create folder
531+
await vscode.workspace.fs.createDirectory(projectFolderUri);
532+
533+
// Create romfs
534+
await vscode.workspace.fs.createDirectory(vscode.Uri.joinPath(projectFolderUri, 'romfs'));
535+
536+
// Create .tkproj
537+
await vscode.workspace.fs.writeFile(vscode.Uri.joinPath(projectFolderUri, '.tkproj'), new Uint8Array(0));
538+
539+
// Add to workspace/archive tree
540+
await provider.addRoot(projectFolderUri);
541+
void focusArchiveSidebar();
542+
543+
void vscode.window.showInformationMessage(`TKVSC: Created new project '${projectName}'.`);
544+
545+
} catch (error) {
546+
const message = error instanceof Error ? error.message : String(error);
547+
void vscode.window.showErrorMessage(`TKVSC: Failed to create project: ${message}`);
548+
}
549+
};
550+
499551
const importTKMMProjects = async (): Promise<void> => {
500552
const foundPath = await getTkmmRecentJsonPath();
501553

@@ -536,6 +588,7 @@ export function registerArchiveTree(context: vscode.ExtensionContext): ArchiveTr
536588
// Backwards-compat alias for an older mistyped command id.
537589
vscode.commands.registerCommand('totk-edit.addWorkspaceToArchives', addWorkspaceToArchives),
538590
vscode.commands.registerCommand('totk-editor.addProjectFolders', addProjectFolders),
591+
vscode.commands.registerCommand('totk-editor.createProject', createProject),
539592
vscode.commands.registerCommand('totk-editor.importTKMMProjects', importTKMMProjects),
540593
);
541594

0 commit comments

Comments
 (0)