Skip to content

Adding menu items #310

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 49 additions & 6 deletions src/common/pickers/managers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,57 @@ export async function pickCreator(creators: PythonProjectCreator[]): Promise<Pyt
return creators[0];
}

const items: (QuickPickItem & { c: PythonProjectCreator })[] = creators.map((c) => ({
label: c.displayName ?? c.name,
description: c.description,
c: c,
}));
// First level menu
const autoFindCreator = creators.find((c) => c.name === 'autoProjects');
const existingProjectsCreator = creators.find((c) => c.name === 'existingProjects');
const otherCreators = creators.filter((c) => c.name !== 'autoProjects' && c.name !== 'existingProjects');

const items: QuickPickItem[] = [
{
label: 'Auto Find',
description: autoFindCreator?.description ?? 'Automatically find Python projects',
},
{
label: 'Select Existing',
description: existingProjectsCreator?.description ?? 'Select existing Python projects',
},
{
label: 'Create New...',
description: 'Create a new Python project from a template',
},
];

const selected = await showQuickPick(items, {
placeHolder: Pickers.Managers.selectProjectCreator,
ignoreFocusOut: true,
});
return (selected as { c: PythonProjectCreator })?.c;

if (!selected) {
return undefined;
}

// Return appropriate creator based on selection
switch (selected.label) {
case 'Auto Find':
return autoFindCreator;
case 'Select Existing':
return existingProjectsCreator;
case 'Create New...':
// Show second level menu for other creators
if (otherCreators.length === 0) {
return undefined;
}
const newItems: (QuickPickItem & { c: PythonProjectCreator })[] = otherCreators.map((c) => ({
label: c.displayName ?? c.name,
description: c.description,
c: c,
}));
const newSelected = await showQuickPick(newItems, {
placeHolder: 'Select project type for new project',
ignoreFocusOut: true,
});
return newSelected?.c;
}

return undefined;
}
4 changes: 4 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { commands, ExtensionContext, LogOutputChannel, Terminal, Uri } from 'vsc
import { PythonEnvironmentManagers } from './features/envManagers';
import { registerLogger, traceInfo } from './common/logging';
import { EnvManagerView } from './features/views/envManagersView';
import { NewPackageProject } from './features/creators/newPackageProject';
import { NewScriptProject } from './features/creators/newScriptProject';
import {
addPythonProject,
createEnvironmentCommand,
Expand Down Expand Up @@ -90,6 +92,8 @@ export async function activate(context: ExtensionContext): Promise<PythonEnviron
projectCreators,
projectCreators.registerPythonProjectCreator(new ExistingProjects()),
projectCreators.registerPythonProjectCreator(new AutoFindProjects(projectManager)),
projectCreators.registerPythonProjectCreator(new NewPackageProject(projectManager)),
projectCreators.registerPythonProjectCreator(new NewScriptProject(projectManager)),
);

setPythonApi(envManagers, projectManager, projectCreators, terminalManager, envVarManager);
Expand Down
19 changes: 19 additions & 0 deletions src/features/creators/newPackageProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { MarkdownString, window } from 'vscode';
import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api';
import { PythonProjectManager } from '../../internal.api';
// import { runInBackground } from '../execution/runInBackground';

export class NewPackageProject implements PythonProjectCreator {
public readonly name = 'newPackage';
public readonly displayName = 'Python Package';
public readonly description = 'Create a new Python package project';
public readonly tooltip = new MarkdownString('Create a new Python package with proper structure');

constructor(private readonly pm: PythonProjectManager) {}

Check failure on line 12 in src/features/creators/newPackageProject.ts

View workflow job for this annotation

GitHub Actions / TypeScript Unit Tests (ubuntu-latest)

Property 'pm' is declared but its value is never read.

Check failure on line 12 in src/features/creators/newPackageProject.ts

View workflow job for this annotation

GitHub Actions / TypeScript Unit Tests (windows-latest)

Property 'pm' is declared but its value is never read.

async create(_options?: PythonProjectCreatorOptions): Promise<PythonProject | undefined> {
// show notification that the pkg creation was selected than return undefined
window.showInformationMessage('Creating a new Python package project...');
return undefined;
}
}
18 changes: 18 additions & 0 deletions src/features/creators/newScriptProject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MarkdownString, window } from 'vscode';
import { PythonProject, PythonProjectCreator, PythonProjectCreatorOptions } from '../../api';
import { PythonProjectManager } from '../../internal.api';

export class NewScriptProject implements PythonProjectCreator {
public readonly name = 'newScript';
public readonly displayName = 'Script';
public readonly description = 'Create a new Python script project';
public readonly tooltip = new MarkdownString('Create a new Python script with basic structure');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly here, should we be presenting this as the base "Python project"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so do you think I should just say "project" for the display name then too? Once we get pep 723 then we will look to separate them since the requirements will be done differently?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also do we care these are the same wording:

public readonly description = 'Create a new Python project';
public readonly tooltip = new MarkdownString('Create a new Python project');


constructor(private readonly pm: PythonProjectManager) {}

Check failure on line 11 in src/features/creators/newScriptProject.ts

View workflow job for this annotation

GitHub Actions / TypeScript Unit Tests (ubuntu-latest)

Property 'pm' is declared but its value is never read.

Check failure on line 11 in src/features/creators/newScriptProject.ts

View workflow job for this annotation

GitHub Actions / TypeScript Unit Tests (windows-latest)

Property 'pm' is declared but its value is never read.

async create(_options?: PythonProjectCreatorOptions): Promise<PythonProject | undefined> {
// show notification that the script creation was selected than return undefined
window.showInformationMessage('Creating a new Python script project...');
return undefined;
}
}
Loading