Skip to content
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

Add 'New Swing in New Window' command #98

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ After you install the CodeSwing extension, you can create new swings at any time

- `CodeSwing: New Swing in Directory...` - Creates a swing in a local directory, which allows you to re-open it later, and easily share it with others (e.g. store it in a GitHub repo).

- `CodeSwing: New Swing in New Window...` - Creates a new temporary swing in a new VS Code window.

After creating a swing, your editor layout will be automatically setup to accomodate the needs of the selected template. Furthermore, if you open a directory that represents a swing, or you run the `CodeSwing: Open Swing...` command, then the selected swing will be automatically launched.

### Language Support
Expand Down Expand Up @@ -265,6 +267,8 @@ When you install CodeSwing, the following commands are available from the comman

- `CodeSwing: Open Swing in New Windows...` - Opens a swing in a new VS Code window.

- `CodeSwing: New Swing in New Window...` - Creates a new temporary swing in a new VS Code window.

- `CodeSwing: Set OpenAI API Key` - Configures the OpenAI API key that is used to support generating AI swings.

Additionally, when you have a swing currently open, the following commands are available:
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@
"command": "codeswing.uploadSwingFile",
"title": "Upload File(s)",
"icon": "$(cloud-upload)"
},
{
"command": "codeswing.newSwingInNewWindow",
"title": "New Swing in New Window...",
"category": "CodeSwing"
}
],
"views": {
Expand Down
26 changes: 22 additions & 4 deletions src/creation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ async function getTemplates(): Promise<CodeSwingTemplateItem[]> {

export async function newSwing(
uri: vscode.Uri | ((files: SwingFile[]) => Promise<vscode.Uri>),
title: string = "Create new swing"
title: string = "Create new swing",
openInNewWindow: boolean = false
) {
const quickPick = vscode.window.createQuickPick();
quickPick.title = title;
Expand Down Expand Up @@ -118,7 +119,7 @@ export async function newSwing(
},
];
await withProgress("Creating swing...", async () =>
newSwingFromTemplate(template.files!, uri)
newSwingFromTemplate(template.files!, uri, openInNewWindow)
);

await storage.addTemplateToMRU(template.label);
Expand All @@ -145,7 +146,8 @@ async function synthesizeTemplate(

async function newSwingFromTemplate(
files: SwingFile[],
uri: vscode.Uri | ((files: SwingFile[]) => Promise<vscode.Uri>)
uri: vscode.Uri | ((files: SwingFile[]) => Promise<vscode.Uri>),
openInNewWindow: boolean = false
) {
const manifest = files.find((file) => file.filename === SWING_FILE);
if (!manifest) {
Expand Down Expand Up @@ -184,7 +186,13 @@ async function newSwingFromTemplate(
swingUri = uri;
}

openSwing(swingUri);
if (openInNewWindow) {
vscode.commands.executeCommand("vscode.openFolder", swingUri, {
forceNewWindow: true,
});
} else {
openSwing(swingUri);
}
}

async function promptForGalleryConfiguration(
Expand Down Expand Up @@ -319,6 +327,16 @@ export function registerCreationModule(
)
);

context.subscriptions.push(
vscode.commands.registerCommand(
`${EXTENSION_NAME}.newSwingInNewWindow`,
async () => {
const uri = await createSwingDirectory();
newSwing(uri, "Create swing in new window", true);
}
)
);

initializeStorage(context, syncKeys);

api.newSwing = newSwing;
Expand Down