Skip to content

Commit 13b993c

Browse files
committed
Adding menu items (#310)
1 parent 04dac71 commit 13b993c

File tree

4 files changed

+88
-7
lines changed

4 files changed

+88
-7
lines changed

src/common/pickers/managers.ts

+49-6
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,57 @@ export async function pickCreator(creators: PythonProjectCreator[]): Promise<Pyt
133133
return creators[0];
134134
}
135135

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

src/extension.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { commands, ExtensionContext, LogOutputChannel, Terminal, Uri } from 'vscode';
2-
32
import { PythonEnvironment, PythonEnvironmentApi } from './api';
43
import { ensureCorrectVersion } from './common/extVersion';
54
import { registerTools } from './common/lm.apis';
@@ -19,6 +18,8 @@ import {
1918
import { GetEnvironmentInfoTool, InstallPackageTool } from './features/copilotTools';
2019
import { AutoFindProjects } from './features/creators/autoFindProjects';
2120
import { ExistingProjects } from './features/creators/existingProjects';
21+
import { NewPackageProject } from './features/creators/newPackageProject';
22+
import { NewScriptProject } from './features/creators/newScriptProject';
2223
import { ProjectCreatorsImpl } from './features/creators/projectCreators';
2324
import {
2425
addPythonProject,
@@ -110,6 +111,8 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
110111
projectCreators,
111112
projectCreators.registerPythonProjectCreator(new ExistingProjects(projectManager)),
112113
projectCreators.registerPythonProjectCreator(new AutoFindProjects(projectManager)),
114+
projectCreators.registerPythonProjectCreator(new NewPackageProject()),
115+
projectCreators.registerPythonProjectCreator(new NewScriptProject()),
113116
);
114117

115118
setPythonApi(envManagers, projectManager, projectCreators, terminalManager, envVarManager);
+18
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+
}
+17
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)