|
1 | 1 | import { commands, ExtensionContext, LogOutputChannel, Terminal, Uri, window } from 'vscode'; |
2 | | -import { PythonEnvironment, PythonEnvironmentApi } from './api'; |
| 2 | +import { PythonEnvironment, PythonEnvironmentApi, PythonProjectCreator } from './api'; |
3 | 3 | import { ensureCorrectVersion } from './common/extVersion'; |
4 | 4 | import { registerTools } from './common/lm.apis'; |
5 | 5 | import { registerLogger, traceError, traceInfo } from './common/logging'; |
@@ -265,12 +265,37 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron |
265 | 265 | await terminalManager.deactivate(terminal); |
266 | 266 | } |
267 | 267 | }), |
268 | | - commands.registerCommand('python-envs.createNewProjectFromTemplate', async () => { |
269 | | - const selected = await newProjectSelection(projectCreators.getProjectCreators()); |
270 | | - if (selected) { |
271 | | - await selected.create(); |
272 | | - } |
273 | | - }), |
| 268 | + commands.registerCommand( |
| 269 | + 'python-envs.createNewProjectFromTemplate', |
| 270 | + async (projectType: string, quickCreate: boolean, newProjectName: string, newProjectPath: string) => { |
| 271 | + if (quickCreate) { |
| 272 | + if (!projectType || !newProjectName || !newProjectPath) { |
| 273 | + throw new Error('Project type, name, and path are required for quick create.'); |
| 274 | + } |
| 275 | + const creators = projectCreators.getProjectCreators(); |
| 276 | + let selected: PythonProjectCreator | undefined; |
| 277 | + if (projectType === 'python-package') { |
| 278 | + selected = creators.find((c) => c.name === 'newPackage'); |
| 279 | + } |
| 280 | + if (projectType === 'python-script') { |
| 281 | + selected = creators.find((c) => c.name === 'newScript'); |
| 282 | + } |
| 283 | + if (!selected) { |
| 284 | + throw new Error(`Project creator for type "${projectType}" not found.`); |
| 285 | + } |
| 286 | + await selected.create({ |
| 287 | + quickCreate: true, |
| 288 | + name: newProjectName, |
| 289 | + rootUri: Uri.file(newProjectPath), |
| 290 | + }); |
| 291 | + } else { |
| 292 | + const selected = await newProjectSelection(projectCreators.getProjectCreators()); |
| 293 | + if (selected) { |
| 294 | + await selected.create(); |
| 295 | + } |
| 296 | + } |
| 297 | + }, |
| 298 | + ), |
274 | 299 | terminalActivation.onDidChangeTerminalActivationState(async (e) => { |
275 | 300 | await setActivateMenuButtonContext(e.terminal, e.environment, e.activated); |
276 | 301 | }), |
|
0 commit comments