add setting for project opening method (#717)

This commit is contained in:
Yan Zhang 2021-08-23 14:00:38 +08:00 коммит произвёл GitHub
Родитель 16920bc6b3
Коммит cee40635ee
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 40 добавлений и 12 удалений

Просмотреть файл

@ -673,6 +673,17 @@
"default": "true",
"description": "%configuration.maven.dependency.enableConflictDiagnostics%",
"scope": "window"
},
"maven.projectOpenBehavior": {
"default": "Interactive",
"type": "string",
"scope": "window",
"description": "%configuration.maven.projectOpenBehavior%",
"enum": [
"Interactive",
"Open",
"Add to Workspace"
]
}
}
}

Просмотреть файл

@ -38,5 +38,6 @@
"configuration.maven.terminal.favorites.command": "Content of the favorite command.",
"configuration.maven.terminal.favorites.debug": "Whether to execute in debug mode.",
"configuration.maven.settingsFile": "Specifies the absolute path of your maven configuration file, the default value is ~/.m2/settings.xml",
"configuration.maven.dependency.enableConflictDiagnostics": "Specify whether to show diagnostics for conflict dependencies."
"configuration.maven.dependency.enableConflictDiagnostics": "Specify whether to show diagnostics for conflict dependencies.",
"configuration.maven.projectOpenBehavior": "Default method of opening newly created project."
}

Просмотреть файл

@ -36,5 +36,6 @@
"configuration.maven.terminal.favorites.command": "命令的内容。",
"configuration.maven.terminal.favorites.debug": "是否以调试模式运行。",
"configuration.maven.settingsFile": "指定 maven 配置文件的绝对路径, 默认是 ~/.m2/settings.xml",
"configuration.maven.dependency.enableConflictDiagnostics": "指定是否在 POM 文件中显示依赖冲突。"
"configuration.maven.dependency.enableConflictDiagnostics": "指定是否在 POM 文件中显示依赖冲突。",
"configuration.maven.projectOpenBehavior": "新建项目的默认打开方式"
}

Просмотреть файл

@ -256,26 +256,41 @@ async function openPomHandler(node: MavenProject | { uri: string }): Promise<voi
}
function registerProjectCreationEndListener(context: vscode.ExtensionContext): void {
const OPEN_IN_NEW_WORKSPACE = "Open";
const OPEN_IN_CURRENT_WORKSPACE = "Add to Workspace";
const specifyOpenMethod = async (hasOpenFolder: boolean, projectName: string, projectLocation: string) => {
let openMethod = vscode.workspace.getConfiguration("maven").get<string>("projectOpenBehavior");
if (openMethod === OPEN_IN_CURRENT_WORKSPACE || openMethod === OPEN_IN_NEW_WORKSPACE) {
sendInfo("", {
name: "projectOpenBehavior(from setting)",
value: openMethod
}, {});
} else {
const candidates: string[] = <string[]>[
OPEN_IN_NEW_WORKSPACE,
hasOpenFolder ? OPEN_IN_CURRENT_WORKSPACE : undefined
].filter(Boolean);
openMethod = await vscode.window.showInformationMessage(`Maven project [${projectName}] is created under: ${projectLocation}`, ...candidates);
sendInfo("", {
name: "projectOpenBehavior(from choice)",
value: openMethod ?? "cancelled"
}, {});
}
return openMethod;
};
context.subscriptions.push(vscode.tasks.onDidEndTaskProcess(async (e) => {
if (e.execution.task.name === "createProject" && e.execution.task.source === "maven") {
if (e.exitCode !== 0) {
vscode.window.showErrorMessage("Failed to create the project, check terminal output for more details.");
return;
}
const { targetFolder, artifactId } = e.execution.task.definition;
const projectFolder = path.join(targetFolder, artifactId);
// Open project either is the same workspace or new workspace
const hasOpenFolder = vscode.workspace.workspaceFolders !== undefined;
const OPEN_IN_NEW_WORKSPACE = "Open";
const OPEN_IN_CURRENT_WORKSPACE = "Add to Workspace";
const candidates: string[] = <string[]>[
OPEN_IN_NEW_WORKSPACE,
hasOpenFolder ? OPEN_IN_CURRENT_WORKSPACE : undefined
].filter(Boolean);
const choice = await vscode.window.showInformationMessage(`Maven project [${artifactId}] is created under: ${targetFolder}`, ...candidates);
const choice = await specifyOpenMethod(hasOpenFolder, artifactId, targetFolder);
if (choice === OPEN_IN_NEW_WORKSPACE) {
vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(projectFolder), hasOpenFolder);
} else if (choice === OPEN_IN_CURRENT_WORKSPACE) {