Skip selection of project when there is only one (#516)

Signed-off-by: Yan Zhang <yanzh@microsoft.com>
This commit is contained in:
Yan Zhang 2020-07-21 13:59:28 +08:00 коммит произвёл GitHub
Родитель a68f4d26cd
Коммит 520a94e04b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 29 добавлений и 33 удалений

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

@ -3,11 +3,11 @@
import * as fse from "fs-extra";
import * as vscode from "vscode";
import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider";
import { MavenProject } from "../explorer/model/MavenProject";
import { UserError } from "../utils/errorUtils";
import { ElementNode, getNodesByTag, XmlTagName } from "../utils/lexerUtils";
import { getArtifacts, IArtifactMetadata } from "../utils/requestUtils";
import { selectProjectIfNecessary } from "../utils/uiUtils";
export async function addDependencyHandler(options?: { pomPath?: string }): Promise<void> {
let pomPath: string;
@ -15,15 +15,7 @@ export async function addDependencyHandler(options?: { pomPath?: string }): Prom
pomPath = options.pomPath;
} else {
// select a project(pomfile)
const selectedProject: MavenProject | undefined = await vscode.window.showQuickPick(
mavenExplorerProvider.mavenProjectNodes.map(item => ({
value: item,
label: `$(primitive-dot) ${item.name}`,
description: undefined,
detail: item.pomPath
})),
{ placeHolder: "Select a Maven project ...", ignoreFocusOut: true }
).then(item => item ? item.value : undefined);
const selectedProject: MavenProject | undefined = await selectProjectIfNecessary();
if (!selectedProject) {
return;
}

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

@ -3,30 +3,21 @@
import * as _ from "lodash";
import * as vscode from "vscode";
import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider";
import { MavenProject } from "../explorer/model/MavenProject";
import { Settings } from "../Settings";
import { executeInTerminal } from "../utils/mavenUtils";
import { selectProjectIfNecessary } from "../utils/uiUtils";
import { debugCommand } from "./debugHandler";
type FavoriteCommand = { command: string, alias: string, debug?: boolean };
export async function runFavoriteCommandsHandler(project: MavenProject | undefined): Promise<void> {
let selectedProject: MavenProject | undefined = project;
if (!selectedProject) {
selectedProject = await vscode.window.showQuickPick(
mavenExplorerProvider.mavenProjectNodes.map(item => ({
value: item,
label: `$(primitive-dot) ${item.name}`,
description: undefined,
detail: item.pomPath
})),
{ placeHolder: "Select a Maven project ...", ignoreFocusOut: true }
).then(item => item ? item.value : undefined);
if (!selectedProject) {
return;
}
selectedProject = await selectProjectIfNecessary();
}
if (!selectedProject) {
return;
}
const favorites: FavoriteCommand[] | undefined = Settings.Terminal.favorites(vscode.Uri.file(selectedProject.pomPath));
if (!favorites || _.isEmpty(favorites)) {
const BUTTON_OPEN_SETTINGS: string = "Open Settings";

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

@ -17,6 +17,7 @@ import { getExtensionVersion, getPathToTempFolder, getPathToWorkspaceStorage } f
import { MavenNotFoundError } from "./errorUtils";
import { getLRUCommands, ICommandHistoryEntry } from "./historyUtils";
import { executeInTerminal, getMaven, pluginDescription, rawEffectivePom } from "./mavenUtils";
import { selectProjectIfNecessary } from "./uiUtils";
export namespace Utils {
@ -233,15 +234,7 @@ export namespace Utils {
export async function executeMavenCommand(): Promise<void> {
// select a project(pomfile)
const selectedProject: MavenProject | undefined = await window.showQuickPick(
mavenExplorerProvider.mavenProjectNodes.map(item => ({
value: item,
label: `$(primitive-dot) ${item.name}`,
description: undefined,
detail: item.pomPath
})),
{ placeHolder: "Select a Maven project ...", ignoreFocusOut: true }
).then(item => item ? item.value : undefined);
const selectedProject: MavenProject | undefined = await selectProjectIfNecessary();
if (!selectedProject) {
return;
}

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

@ -4,6 +4,8 @@
import * as fs from "fs-extra";
import * as vscode from "vscode";
import { OpenDialogOptions, Uri, window } from "vscode";
import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider";
import { MavenProject } from "../explorer/model/MavenProject";
import { mavenOutputChannel } from "../mavenOutputChannel";
const TROUBLESHOOTING_LINK: string = "https://github.com/Microsoft/vscode-maven/blob/master/Troubleshooting.md";
@ -56,3 +58,21 @@ export async function showTroubleshootingDialog(errorMessage: string): Promise<v
mavenOutputChannel.show();
}
}
export async function selectProjectIfNecessary(): Promise< MavenProject | undefined> {
if (!mavenExplorerProvider.mavenProjectNodes || mavenExplorerProvider.mavenProjectNodes.length === 0) {
return undefined;
}
if (mavenExplorerProvider.mavenProjectNodes.length === 1) {
return mavenExplorerProvider.mavenProjectNodes[0];
}
return await window.showQuickPick(
mavenExplorerProvider.mavenProjectNodes.map(item => ({
value: item,
label: `$(primitive-dot) ${item.name}`,
description: undefined,
detail: item.pomPath
})),
{ placeHolder: "Select a Maven project ...", ignoreFocusOut: true }
).then(item => item ? item.value : undefined);
}