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

UX: Allow switching mode when creating new project #1283

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
5 changes: 0 additions & 5 deletions extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -326,11 +326,6 @@
"category": "Gradle",
"title": "Create a Gradle Java Project..."
},
{
"command": "gradle.createProjectAdvanced",
"category": "Gradle",
"title": "Create a Gradle Java Project... (Advanced)"
},
{
"command": "gradle.runTasks",
"category": "Gradle",
Expand Down
3 changes: 1 addition & 2 deletions extension/src/commands/Commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import { GradleTaskProvider } from "../tasks";
import { isJavaExtEnabled } from "../util/javaExtension";
import { GradleDaemonsTreeDataProvider, GradleTasksTreeDataProvider, RecentTasksTreeDataProvider } from "../views";
import { Command } from "./Command";
import { COMMAND_CREATE_PROJECT, COMMAND_CREATE_PROJECT_ADVANCED, CreateProjectCommand } from "./CreateProjectCommand";
import { COMMAND_CREATE_PROJECT, CreateProjectCommand } from "./CreateProjectCommand";
import { HideStoppedDaemonsCommand, HIDE_STOPPED_DAEMONS } from "./HideStoppedDaemonsCommand";
import { COMMAND_RELOAD_JAVA_PROJECT, ReloadJavaProjectsCommand } from "./ReloadJavaProjectsCommand";
import { COMMAND_RUN_TASKS, RunTasksCommand } from "./RunTasksCommand";
Expand Down Expand Up @@ -186,7 +186,6 @@ export class Commands {
this.registerCommand(SHOW_STOPPED_DAEMONS, new ShowStoppedDaemonsCommand(this.gradleDaemonsTreeDataProvider));
this.registerCommand(HIDE_STOPPED_DAEMONS, new HideStoppedDaemonsCommand(this.gradleDaemonsTreeDataProvider));
this.registerCommand(COMMAND_CREATE_PROJECT, new CreateProjectCommand(this.client), [false]);
this.registerCommand(COMMAND_CREATE_PROJECT_ADVANCED, new CreateProjectCommand(this.client), [true]);
this.registerCommand(COMMAND_RUN_TASKS, new RunTasksCommand(this.gradleTaskProvider));
if (isJavaExtEnabled()) {
this.registerCommand(COMMAND_RELOAD_JAVA_PROJECT, new ReloadJavaProjectsCommand());
Expand Down
10 changes: 6 additions & 4 deletions extension/src/commands/CreateProjectCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { getProjectOpenBehaviour, ProjectOpenBehaviourValue } from "../util/conf
import { Command } from "./Command";

export const COMMAND_CREATE_PROJECT = "gradle.createProject";
export const COMMAND_CREATE_PROJECT_ADVANCED = "gradle.createProjectAdvanced";

export class CreateProjectCommand extends Command {
constructor(private client: GradleClient) {
Expand All @@ -32,7 +31,7 @@ export class CreateProjectCommand extends Command {
canSelectFolders: true,
canSelectMany: false,
});
const isAdvanced = params[0] as boolean;
const isAdvanced = false;
if (targetFolderUri) {
const metadata: IProjectCreationMetadata = {
isAdvanced: isAdvanced,
Expand All @@ -43,7 +42,7 @@ export class CreateProjectCommand extends Command {
projectName: path.basename(targetFolderUri[0].fsPath),
sourcePackageName: await this.client.getNormalizedPackageName(path.basename(targetFolderUri[0].fsPath)),
steps: [],
nextStep: isAdvanced ? selectProjectTypeStep : selectScriptDSLStep,
nextStep: selectScriptDSLStep,
client: this.client,
};
const success = await this.runSteps(metadata);
Expand Down Expand Up @@ -104,6 +103,10 @@ export class CreateProjectCommand extends Command {
}
step = metadata.steps.pop();
break;
case StepResult.RESTART:
metadata.steps = [];
step = selectProjectTypeStep;
break;
case StepResult.STOP:
return false; // user cancellation
default:
Expand All @@ -113,7 +116,6 @@ export class CreateProjectCommand extends Command {
return true;
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
private async createProject(metadata: IProjectCreationMetadata): Promise<void> {
const cancellationKey = getRunTaskCommandCancellationKey(metadata.targetFolder, "init");
const args: string[] = ["init"];
Expand Down
5 changes: 2 additions & 3 deletions extension/src/createProject/SelectProjectTypeStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as vscode from "vscode";
import { selectScriptDSLStep } from "./SelectScriptDSLStep";
import { IProjectCreationMetadata, IProjectCreationStep, ProjectType, StepResult } from "./types";
import { updateTotalSteps } from "./utils";

export class SelectProjectTypeStep implements IProjectCreationStep {
public async run(metadata: IProjectCreationMetadata): Promise<StepResult> {
Expand All @@ -25,19 +26,17 @@ export class SelectProjectTypeStep implements IProjectCreationStep {
switch (selectedType.label) {
case "application":
metadata.projectType = ProjectType.JAVA_APPLICATION;
metadata.totalSteps = 5;
break;
case "library":
metadata.projectType = ProjectType.JAVA_LIBRARY;
metadata.totalSteps = 5;
break;
case "Gradle plugin":
metadata.projectType = ProjectType.JAVA_GRADLE_PLUGIN;
metadata.totalSteps = 4; // when creating gradle plugin, we shouldn't specify test framework
break;
default:
resolve(StepResult.STOP);
}
updateTotalSteps(metadata);
metadata.steps.push(selectProjectTypeStep);
metadata.nextStep = selectScriptDSLStep;
resolve(StepResult.NEXT);
Expand Down
21 changes: 11 additions & 10 deletions extension/src/createProject/SelectScriptDSLStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as vscode from "vscode";
import { selectTestFrameworkStep } from "./SelectTestFrameworkStep";
import { specifyProjectNameStep } from "./SpecifyProjectNameStep";
import { IProjectCreationMetadata, IProjectCreationStep, ProjectType, StepResult } from "./types";
import { createQuickInputButtons, switchToAdvancedLabel, updateTotalSteps } from "./utils";

export class SelectScriptDSLStep implements IProjectCreationStep {
public async run(metadata: IProjectCreationMetadata): Promise<StepResult> {
Expand All @@ -19,16 +20,7 @@ export class SelectScriptDSLStep implements IProjectCreationStep {
pickBox.matchOnDescription = true;
pickBox.ignoreFocusOut = true;
pickBox.items = this.getScriptDSLPickItems();
if (metadata.steps.length) {
pickBox.buttons = [vscode.QuickInputButtons.Back];
disposables.push(
pickBox.onDidTriggerButton((item) => {
if (item === vscode.QuickInputButtons.Back) {
resolve(StepResult.PREVIOUS);
}
})
);
}
pickBox.buttons = createQuickInputButtons(metadata);
disposables.push(
pickBox.onDidAccept(() => {
const selectedScriptDSL = pickBox.selectedItems[0];
Expand All @@ -52,6 +44,15 @@ export class SelectScriptDSLStep implements IProjectCreationStep {
resolve(StepResult.NEXT);
}
}),
pickBox.onDidTriggerButton((item) => {
if (item === vscode.QuickInputButtons.Back) {
resolve(StepResult.PREVIOUS);
} else if (item.tooltip === switchToAdvancedLabel) {
metadata.isAdvanced = true;
updateTotalSteps(metadata);
resolve(StepResult.RESTART);
}
}),
pickBox.onDidHide(() => {
resolve(StepResult.STOP);
})
Expand Down
17 changes: 7 additions & 10 deletions extension/src/createProject/SelectTestFrameworkStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as vscode from "vscode";
import { specifyProjectNameStep } from "./SpecifyProjectNameStep";
import { IProjectCreationMetadata, IProjectCreationStep, StepResult, TestFramework } from "./types";
import { createQuickInputButtons } from "./utils";

export class SelectTestFrameworkStep implements IProjectCreationStep {
public async run(metadata: IProjectCreationMetadata): Promise<StepResult> {
Expand All @@ -18,16 +19,7 @@ export class SelectTestFrameworkStep implements IProjectCreationStep {
pickBox.matchOnDescription = true;
pickBox.ignoreFocusOut = true;
pickBox.items = this.getTestFrameworkPickItems();
if (metadata.steps.length) {
pickBox.buttons = [vscode.QuickInputButtons.Back];
disposables.push(
pickBox.onDidTriggerButton((item) => {
if (item === vscode.QuickInputButtons.Back) {
resolve(StepResult.PREVIOUS);
}
})
);
}
pickBox.buttons = createQuickInputButtons(metadata);
disposables.push(
pickBox.onDidAccept(() => {
const selectedTestFramework = pickBox.selectedItems[0];
Expand All @@ -54,6 +46,11 @@ export class SelectTestFrameworkStep implements IProjectCreationStep {
resolve(StepResult.NEXT);
}
}),
pickBox.onDidTriggerButton((item) => {
if (item === vscode.QuickInputButtons.Back) {
resolve(StepResult.PREVIOUS);
}
}),
pickBox.onDidHide(() => {
resolve(StepResult.STOP);
})
Expand Down
21 changes: 11 additions & 10 deletions extension/src/createProject/SpecifyProjectNameStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import * as vscode from "vscode";
import { specifySourcePackageNameStep } from "./SpecifySourcePackageNameStep";
import { IProjectCreationMetadata, IProjectCreationStep, StepResult } from "./types";
import { createQuickInputButtons, switchToAdvancedLabel, updateTotalSteps } from "./utils";

export class SpecifyProjectNameStep implements IProjectCreationStep {
public async run(metadata: IProjectCreationMetadata): Promise<StepResult> {
Expand All @@ -19,16 +20,7 @@ export class SpecifyProjectNameStep implements IProjectCreationStep {
inputBox.value = metadata.projectName;
inputBox.ignoreFocusOut = true;
inputBox.validationMessage = this.isValidProjectName(metadata.projectName);
if (metadata.steps.length) {
inputBox.buttons = [vscode.QuickInputButtons.Back];
disposables.push(
inputBox.onDidTriggerButton((item) => {
if (item === vscode.QuickInputButtons.Back) {
resolve(StepResult.PREVIOUS);
}
})
);
}
inputBox.buttons = createQuickInputButtons(metadata);
disposables.push(
inputBox.onDidChangeValue(() => {
inputBox.validationMessage = this.isValidProjectName(inputBox.value);
Expand All @@ -42,6 +34,15 @@ export class SpecifyProjectNameStep implements IProjectCreationStep {
metadata.nextStep = !metadata.isAdvanced ? undefined : specifySourcePackageNameStep;
resolve(StepResult.NEXT);
}),
inputBox.onDidTriggerButton((item) => {
if (item === vscode.QuickInputButtons.Back) {
resolve(StepResult.PREVIOUS);
} else if (item.tooltip === switchToAdvancedLabel) {
metadata.isAdvanced = true;
updateTotalSteps(metadata);
resolve(StepResult.RESTART);
}
}),
inputBox.onDidHide(() => {
resolve(StepResult.STOP);
})
Expand Down
18 changes: 7 additions & 11 deletions extension/src/createProject/SpecifySourcePackageNameStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import * as vscode from "vscode";
import { IProjectCreationMetadata, IProjectCreationStep, StepResult } from "./types";
import { asyncDebounce } from "./utils";
import { asyncDebounce, createQuickInputButtons } from "./utils";

export class SpecifySourcePackageNameStep implements IProjectCreationStep {
public static GET_NORMALIZED_PACKAGE_NAME = "getNormalizedPackageName";
Expand Down Expand Up @@ -33,16 +33,7 @@ export class SpecifySourcePackageNameStep implements IProjectCreationStep {
inputBox.placeholder = "e.g. " + normalizedName;
inputBox.value = normalizedName as string;
inputBox.ignoreFocusOut = true;
if (metadata.steps.length) {
inputBox.buttons = [vscode.QuickInputButtons.Back];
disposables.push(
inputBox.onDidTriggerButton((item) => {
if (item === vscode.QuickInputButtons.Back) {
resolve(StepResult.PREVIOUS);
}
})
);
}
inputBox.buttons = createQuickInputButtons(metadata);
disposables.push(
inputBox.onDidChangeValue(async () => {
const normalizedName = await getNormalizedPackageNameTrigger(inputBox.value);
Expand All @@ -66,6 +57,11 @@ export class SpecifySourcePackageNameStep implements IProjectCreationStep {
resolve(StepResult.NEXT);
}
}),
inputBox.onDidTriggerButton((item) => {
if (item === vscode.QuickInputButtons.Back) {
resolve(StepResult.PREVIOUS);
}
}),
inputBox.onDidHide(() => {
resolve(StepResult.STOP);
})
Expand Down
2 changes: 2 additions & 0 deletions extension/src/createProject/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export enum StepResult {
NEXT,
STOP,
PREVIOUS,
// used for switching mode and restart all steps
RESTART,
}

export enum ProjectType {
Expand Down
29 changes: 29 additions & 0 deletions extension/src/createProject/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

/* eslint-disable @typescript-eslint/no-explicit-any */
import { debounce } from "lodash";
import { QuickInputButton, QuickInputButtons, ThemeIcon } from "vscode";
import { IProjectCreationMetadata, ProjectType } from "./types";

export const switchToAdvancedLabel = "Switch to advanced mode...";

export function asyncDebounce(func: any, wait: any, bind: any) {
const debounced = debounce(async (resolve, reject, bindSelf, args) => {
Expand All @@ -22,3 +26,28 @@ export function asyncDebounce(func: any, wait: any, bind: any) {

return returnFunc;
}

export function updateTotalSteps(metadata: IProjectCreationMetadata): void {
if (!metadata.isAdvanced) {
metadata.totalSteps = 2;
} else if (metadata.projectType === ProjectType.JAVA_GRADLE_PLUGIN) {
// when creating gradle plugin, we shouldn't specify test framework
metadata.totalSteps = 4;
} else {
metadata.totalSteps = 5;
}
}

export function createQuickInputButtons(metadata: IProjectCreationMetadata): QuickInputButton[] {
const buttons: QuickInputButton[] = [];
if (metadata.steps.length) {
buttons.push(QuickInputButtons.Back);
}
if (!metadata.isAdvanced) {
buttons.push({
iconPath: new ThemeIcon("settings-gear"),
tooltip: switchToAdvancedLabel,
});
}
return buttons;
}