Skip to content

Commit f325412

Browse files
authored
Adding menu items (#310)
1 parent 01eda1e commit f325412

File tree

4 files changed

+88
-6
lines changed

4 files changed

+88
-6
lines changed

src/common/pickers/managers.ts

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,57 @@ export async function pickCreator(creators: PythonProjectCreator[]): Promise<Pyt
131131
return creators[0];
132132
}
133133

134-
const items: (QuickPickItem & { c: PythonProjectCreator })[] = creators.map((c) => ({
135-
label: c.displayName ?? c.name,
136-
description: c.description,
137-
c: c,
138-
}));
134+
// First level menu
135+
const autoFindCreator = creators.find((c) => c.name === 'autoProjects');
136+
const existingProjectsCreator = creators.find((c) => c.name === 'existingProjects');
137+
const otherCreators = creators.filter((c) => c.name !== 'autoProjects' && c.name !== 'existingProjects');
138+
139+
const items: QuickPickItem[] = [
140+
{
141+
label: 'Auto Find',
142+
description: autoFindCreator?.description ?? 'Automatically find Python projects',
143+
},
144+
{
145+
label: 'Select Existing',
146+
description: existingProjectsCreator?.description ?? 'Select existing Python projects',
147+
},
148+
{
149+
label: 'Create New',
150+
description: 'Create a Python project from a template',
151+
},
152+
];
153+
139154
const selected = await showQuickPick(items, {
140155
placeHolder: Pickers.Managers.selectProjectCreator,
141156
ignoreFocusOut: true,
142157
});
143-
return (selected as { c: PythonProjectCreator })?.c;
158+
159+
if (!selected) {
160+
return undefined;
161+
}
162+
163+
// Return appropriate creator based on selection
164+
switch (selected.label) {
165+
case 'Auto Find':
166+
return autoFindCreator;
167+
case 'Select Existing':
168+
return existingProjectsCreator;
169+
case 'Create New':
170+
// Show second level menu for other creators
171+
if (otherCreators.length === 0) {
172+
return undefined;
173+
}
174+
const newItems: (QuickPickItem & { c: PythonProjectCreator })[] = otherCreators.map((c) => ({
175+
label: c.displayName ?? c.name,
176+
description: c.description,
177+
c: c,
178+
}));
179+
const newSelected = await showQuickPick(newItems, {
180+
placeHolder: 'Select project type for new project',
181+
ignoreFocusOut: true,
182+
});
183+
return newSelected?.c;
184+
}
185+
186+
return undefined;
144187
}

src/extension.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { commands, ExtensionContext, LogOutputChannel, Terminal, Uri } from 'vsc
33
import { PythonEnvironmentManagers } from './features/envManagers';
44
import { registerLogger, traceInfo } from './common/logging';
55
import { EnvManagerView } from './features/views/envManagersView';
6+
import { NewPackageProject } from './features/creators/newPackageProject';
7+
import { NewScriptProject } from './features/creators/newScriptProject';
68
import {
79
addPythonProject,
810
createEnvironmentCommand,
@@ -90,6 +92,8 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
9092
projectCreators,
9193
projectCreators.registerPythonProjectCreator(new ExistingProjects()),
9294
projectCreators.registerPythonProjectCreator(new AutoFindProjects(projectManager)),
95+
projectCreators.registerPythonProjectCreator(new NewPackageProject()),
96+
projectCreators.registerPythonProjectCreator(new NewScriptProject()),
9397
);
9498

9599
setPythonApi(envManagers, projectManager, projectCreators, terminalManager, envVarManager);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { MarkdownString, window } from 'vscode';
2+
import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api';
3+
// import { runInBackground } from '../execution/runInBackground';
4+
5+
export class NewPackageProject implements PythonProjectCreator {
6+
public readonly name = 'newPackage';
7+
public readonly displayName = 'Package';
8+
public readonly description = 'Create a new Python package';
9+
public readonly tooltip = new MarkdownString('Create a new Python package');
10+
11+
constructor() {}
12+
13+
async create(_options?: PythonProjectCreatorOptions): Promise<PythonProject | undefined> {
14+
// show notification that the package creation was selected than return undefined
15+
window.showInformationMessage('Creating a new Python package...');
16+
return undefined;
17+
}
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { MarkdownString, window } from 'vscode';
2+
import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api';
3+
4+
export class NewScriptProject implements PythonProjectCreator {
5+
public readonly name = 'newScript';
6+
public readonly displayName = 'Project';
7+
public readonly description = 'Create a new Python project';
8+
public readonly tooltip = new MarkdownString('Create a new Python project');
9+
10+
constructor() {}
11+
12+
async create(_options?: PythonProjectCreatorOptions): Promise<PythonProject | undefined> {
13+
// show notification that the script creation was selected than return undefined
14+
window.showInformationMessage('Creating a new Python project...');
15+
return undefined;
16+
}
17+
}

0 commit comments

Comments
 (0)