Skip to content

Commit a60b2b1

Browse files
committed
Adding menu items (#310)
1 parent 6170c64 commit a60b2b1

File tree

4 files changed

+88
-7
lines changed

4 files changed

+88
-7
lines changed

src/common/pickers/managers.ts

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

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

src/extension.ts

Lines changed: 4 additions & 1 deletion
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';
@@ -20,6 +19,8 @@ import { createManagerReady } from './features/common/managerReady';
2019
import { GetEnvironmentInfoTool, InstallPackageTool } from './features/copilotTools';
2120
import { AutoFindProjects } from './features/creators/autoFindProjects';
2221
import { ExistingProjects } from './features/creators/existingProjects';
22+
import { NewPackageProject } from './features/creators/newPackageProject';
23+
import { NewScriptProject } from './features/creators/newScriptProject';
2324
import { ProjectCreatorsImpl } from './features/creators/projectCreators';
2425
import {
2526
addPythonProjectCommand,
@@ -108,6 +109,8 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
108109
projectCreators,
109110
projectCreators.registerPythonProjectCreator(new ExistingProjects(projectManager)),
110111
projectCreators.registerPythonProjectCreator(new AutoFindProjects(projectManager)),
112+
projectCreators.registerPythonProjectCreator(new NewPackageProject()),
113+
projectCreators.registerPythonProjectCreator(new NewScriptProject()),
111114
);
112115

113116
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)