Skip selection of project when there is only one (#516)
Signed-off-by: Yan Zhang <yanzh@microsoft.com>
This commit is contained in:
Родитель
a68f4d26cd
Коммит
520a94e04b
|
@ -3,11 +3,11 @@
|
||||||
|
|
||||||
import * as fse from "fs-extra";
|
import * as fse from "fs-extra";
|
||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider";
|
|
||||||
import { MavenProject } from "../explorer/model/MavenProject";
|
import { MavenProject } from "../explorer/model/MavenProject";
|
||||||
import { UserError } from "../utils/errorUtils";
|
import { UserError } from "../utils/errorUtils";
|
||||||
import { ElementNode, getNodesByTag, XmlTagName } from "../utils/lexerUtils";
|
import { ElementNode, getNodesByTag, XmlTagName } from "../utils/lexerUtils";
|
||||||
import { getArtifacts, IArtifactMetadata } from "../utils/requestUtils";
|
import { getArtifacts, IArtifactMetadata } from "../utils/requestUtils";
|
||||||
|
import { selectProjectIfNecessary } from "../utils/uiUtils";
|
||||||
|
|
||||||
export async function addDependencyHandler(options?: { pomPath?: string }): Promise<void> {
|
export async function addDependencyHandler(options?: { pomPath?: string }): Promise<void> {
|
||||||
let pomPath: string;
|
let pomPath: string;
|
||||||
|
@ -15,15 +15,7 @@ export async function addDependencyHandler(options?: { pomPath?: string }): Prom
|
||||||
pomPath = options.pomPath;
|
pomPath = options.pomPath;
|
||||||
} else {
|
} else {
|
||||||
// select a project(pomfile)
|
// select a project(pomfile)
|
||||||
const selectedProject: MavenProject | undefined = await vscode.window.showQuickPick(
|
const selectedProject: MavenProject | undefined = await selectProjectIfNecessary();
|
||||||
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) {
|
if (!selectedProject) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,30 +3,21 @@
|
||||||
|
|
||||||
import * as _ from "lodash";
|
import * as _ from "lodash";
|
||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider";
|
|
||||||
import { MavenProject } from "../explorer/model/MavenProject";
|
import { MavenProject } from "../explorer/model/MavenProject";
|
||||||
import { Settings } from "../Settings";
|
import { Settings } from "../Settings";
|
||||||
import { executeInTerminal } from "../utils/mavenUtils";
|
import { executeInTerminal } from "../utils/mavenUtils";
|
||||||
|
import { selectProjectIfNecessary } from "../utils/uiUtils";
|
||||||
import { debugCommand } from "./debugHandler";
|
import { debugCommand } from "./debugHandler";
|
||||||
|
|
||||||
type FavoriteCommand = { command: string, alias: string, debug?: boolean };
|
type FavoriteCommand = { command: string, alias: string, debug?: boolean };
|
||||||
export async function runFavoriteCommandsHandler(project: MavenProject | undefined): Promise<void> {
|
export async function runFavoriteCommandsHandler(project: MavenProject | undefined): Promise<void> {
|
||||||
let selectedProject: MavenProject | undefined = project;
|
let selectedProject: MavenProject | undefined = project;
|
||||||
if (!selectedProject) {
|
if (!selectedProject) {
|
||||||
selectedProject = await vscode.window.showQuickPick(
|
selectedProject = await selectProjectIfNecessary();
|
||||||
mavenExplorerProvider.mavenProjectNodes.map(item => ({
|
}
|
||||||
value: item,
|
if (!selectedProject) {
|
||||||
label: `$(primitive-dot) ${item.name}`,
|
return;
|
||||||
description: undefined,
|
|
||||||
detail: item.pomPath
|
|
||||||
})),
|
|
||||||
{ placeHolder: "Select a Maven project ...", ignoreFocusOut: true }
|
|
||||||
).then(item => item ? item.value : undefined);
|
|
||||||
if (!selectedProject) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const favorites: FavoriteCommand[] | undefined = Settings.Terminal.favorites(vscode.Uri.file(selectedProject.pomPath));
|
const favorites: FavoriteCommand[] | undefined = Settings.Terminal.favorites(vscode.Uri.file(selectedProject.pomPath));
|
||||||
if (!favorites || _.isEmpty(favorites)) {
|
if (!favorites || _.isEmpty(favorites)) {
|
||||||
const BUTTON_OPEN_SETTINGS: string = "Open Settings";
|
const BUTTON_OPEN_SETTINGS: string = "Open Settings";
|
||||||
|
|
|
@ -17,6 +17,7 @@ import { getExtensionVersion, getPathToTempFolder, getPathToWorkspaceStorage } f
|
||||||
import { MavenNotFoundError } from "./errorUtils";
|
import { MavenNotFoundError } from "./errorUtils";
|
||||||
import { getLRUCommands, ICommandHistoryEntry } from "./historyUtils";
|
import { getLRUCommands, ICommandHistoryEntry } from "./historyUtils";
|
||||||
import { executeInTerminal, getMaven, pluginDescription, rawEffectivePom } from "./mavenUtils";
|
import { executeInTerminal, getMaven, pluginDescription, rawEffectivePom } from "./mavenUtils";
|
||||||
|
import { selectProjectIfNecessary } from "./uiUtils";
|
||||||
|
|
||||||
export namespace Utils {
|
export namespace Utils {
|
||||||
|
|
||||||
|
@ -233,15 +234,7 @@ export namespace Utils {
|
||||||
|
|
||||||
export async function executeMavenCommand(): Promise<void> {
|
export async function executeMavenCommand(): Promise<void> {
|
||||||
// select a project(pomfile)
|
// select a project(pomfile)
|
||||||
const selectedProject: MavenProject | undefined = await window.showQuickPick(
|
const selectedProject: MavenProject | undefined = await selectProjectIfNecessary();
|
||||||
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) {
|
if (!selectedProject) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
import * as fs from "fs-extra";
|
import * as fs from "fs-extra";
|
||||||
import * as vscode from "vscode";
|
import * as vscode from "vscode";
|
||||||
import { OpenDialogOptions, Uri, window } from "vscode";
|
import { OpenDialogOptions, Uri, window } from "vscode";
|
||||||
|
import { mavenExplorerProvider } from "../explorer/mavenExplorerProvider";
|
||||||
|
import { MavenProject } from "../explorer/model/MavenProject";
|
||||||
import { mavenOutputChannel } from "../mavenOutputChannel";
|
import { mavenOutputChannel } from "../mavenOutputChannel";
|
||||||
|
|
||||||
const TROUBLESHOOTING_LINK: string = "https://github.com/Microsoft/vscode-maven/blob/master/Troubleshooting.md";
|
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();
|
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);
|
||||||
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче