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

feat: Allow specifying project open behaviour after creating new project #1282

Merged
merged 3 commits into from
Sep 20, 2022
Merged
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ This extension contributes the following settings:
- `gradle.debug`: Show extra debug info in the output panel (boolean)
- `gradle.disableConfirmations`: Disable the warning confirm messages when performing batch actions (eg clear tasks, stop daemons etc) (boolean)
- `gradle.allowParallelRun`: Allow to run tasks in parallel, each running will create a new terminal. This configuration will override `gradle.reuseTerminals` and always create new task terminals when running or debugging a task.
- `gradle.projectOpenBehaviour`: Specify the default method of opening newly created project ("Interactive", "Open" or "Add to Workspace")

## Gradle & Java Settings

Expand Down
11 changes: 11 additions & 0 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,17 @@
"default": false,
"scope": "window",
"markdownDescription": "Allow to run tasks in parallel, each running will create a new terminal. This configuration will override `gradle.reuseTerminals` and always create new task terminals when running or debugging a task."
},
"gradle.projectOpenBehaviour": {
"default": "Interactive",
"type": "string",
"scope": "window",
"description": "Default method of opening newly created project.",
"enum": [
"Interactive",
"Open",
"Add to Workspace"
]
}
}
},
Expand Down
43 changes: 37 additions & 6 deletions extension/src/commands/CreateProjectCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getRunTaskCommandCancellationKey } from "../client/CancellationKeys";
import { selectProjectTypeStep } from "../createProject/SelectProjectTypeStep";
import { selectScriptDSLStep } from "../createProject/SelectScriptDSLStep";
import { IProjectCreationMetadata, IProjectCreationStep, ProjectType, StepResult } from "../createProject/types";
import { getProjectOpenBehaviour, ProjectOpenBehaviourValue } from "../util/config";
import { Command } from "./Command";

export const COMMAND_CREATE_PROJECT = "gradle.createProject";
Expand Down Expand Up @@ -48,12 +49,42 @@ export class CreateProjectCommand extends Command {
const success = await this.runSteps(metadata);
if (success) {
await this.createProject(metadata);
const openInNewWindow = folders !== undefined;
vscode.commands.executeCommand(
"vscode.openFolder",
vscode.Uri.file(metadata.targetFolder),
openInNewWindow
);
const hasOpenFolder = folders !== undefined;
const insideWorkspace: boolean =
folders?.find((workspaceFolder) =>
metadata.targetFolder.startsWith(workspaceFolder.uri?.fsPath)
) !== undefined;
let openProjectBehaviour = getProjectOpenBehaviour();
if (openProjectBehaviour === ProjectOpenBehaviourValue.INTERACTIVE) {
const candidates: string[] = [
ProjectOpenBehaviourValue.OPEN,
hasOpenFolder && insideWorkspace === false
? ProjectOpenBehaviourValue.ADDTOWORKSPACE
: undefined,
].filter(Boolean) as string[];
const choice = await vscode.window.showInformationMessage(
`Gradle project [${metadata.projectName}] is created under: ${metadata.targetFolder}`,
...candidates
);
if (choice) {
openProjectBehaviour = choice;
}
}
if (openProjectBehaviour === ProjectOpenBehaviourValue.OPEN) {
vscode.commands.executeCommand(
"vscode.openFolder",
vscode.Uri.file(metadata.targetFolder),
hasOpenFolder
);
} else if (openProjectBehaviour === ProjectOpenBehaviourValue.ADDTOWORKSPACE) {
// check here in case of setting to "Add to Workspace" manually
// if generated folder is inside any current workspace (insideWorkspace === true), extension will do nothing
if (!insideWorkspace) {
vscode.workspace.updateWorkspaceFolders(folders ? folders.length : 0, null, {
uri: vscode.Uri.file(metadata.targetFolder),
});
}
}
}
}
return;
Expand Down
12 changes: 12 additions & 0 deletions extension/src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ export function getAllowParallelRun(): boolean {
return vscode.workspace.getConfiguration("gradle").get<boolean>("allowParallelRun", false);
}

export enum ProjectOpenBehaviourValue {
INTERACTIVE = "Interactive",
OPEN = "Open",
ADDTOWORKSPACE = "Add to Workspace",
}

export function getProjectOpenBehaviour(): string {
return vscode.workspace
.getConfiguration("gradle")
.get<string>("projectOpenBehaviour", ProjectOpenBehaviourValue.INTERACTIVE);
}

export function getGradleConfig(): GradleConfig {
const gradleConfig = new GradleConfig();
const gradleHome = getConfigJavaImportGradleHome();
Expand Down