Created a UI to add favorites into the user workspace scope. (#906)
This commit is contained in:
Родитель
a0d7361e9b
Коммит
a771212de9
|
@ -4,6 +4,7 @@ All notable changes to the "vscode-maven" extension will be documented in this f
|
|||
## 0.40.0
|
||||
### Added
|
||||
- Created a new FavoritesMenu. This menu allows shortcuts to execute the favorite commands. [#884](https://github.com/microsoft/vscode-maven/issues/884)
|
||||
- Created a UI to add favorites into the user workspace scope. [#901](https://github.com/microsoft/vscode-maven/issues/901)
|
||||
|
||||
## 0.39.2
|
||||
### Fixed
|
||||
|
|
12
package.json
12
package.json
|
@ -59,6 +59,7 @@
|
|||
"onCommand:maven.plugin.execute",
|
||||
"onCommand:maven.project.addDependency",
|
||||
"onCommand:maven.project.excludeDependency",
|
||||
"onCommand:maven.project.addFavorite",
|
||||
"onView:mavenProjects"
|
||||
],
|
||||
"main": "./dist/extension",
|
||||
|
@ -222,6 +223,12 @@
|
|||
"category": "Maven",
|
||||
"icon": "$(wrench)"
|
||||
},
|
||||
{
|
||||
"command": "maven.project.addFavorite",
|
||||
"title": "%contributes.commands.maven.project.addFavorite%",
|
||||
"category": "Maven",
|
||||
"icon": "$(add)"
|
||||
},
|
||||
{
|
||||
"command": "maven.dependency.goToEffective",
|
||||
"title": "%contributes.commands.maven.dependency.goToEffective%",
|
||||
|
@ -556,6 +563,11 @@
|
|||
"when": "view == mavenProjects && viewItem == maven:dependenciesMenu",
|
||||
"group": "inline@0"
|
||||
},
|
||||
{
|
||||
"command": "maven.project.addFavorite",
|
||||
"when": "view == mavenProjects && viewItem == maven:favoritesMenu",
|
||||
"group": "inline@0"
|
||||
},
|
||||
{
|
||||
"command": "maven.explorer.refresh",
|
||||
"when": "view == mavenProjects && viewItem == maven:dependenciesMenu",
|
||||
|
|
|
@ -15,10 +15,11 @@
|
|||
"contributes.commands.maven.view.flat": "Switch to flat view",
|
||||
"contributes.commands.maven.project.addDependency": "Add a dependency...",
|
||||
"contributes.commands.maven.project.showDependencies": "Show Dependencies",
|
||||
"contributes.commands.maven.project.goToDefinition": "Go to Definition",
|
||||
"contributes.commands.maven.project.excludeDependency": "Exclude Dependency",
|
||||
"contributes.commands.maven.project.setDependencyVersion": "Resolve Conflict...",
|
||||
"contributes.commands.maven.project.addFavorite": "Add a favorite...",
|
||||
"contributes.commands.maven.dependency.goToEffective": "Go to Effective Dependency",
|
||||
"contributes.commands.maven.project.goToDefinition": "Go to Definition",
|
||||
"contributes.views.explorer.mavenProjects": "Maven",
|
||||
"contributes.viewsWelcome.mavenProjects.untrustedWorkspaces": "Advanced features (e.g. executing lifecycle phases and plugin goals) are disabled in Restricted Mode for security concern.\nPOM editing assistance (e.g. [add a dependency](command:maven.project.addDependency)) is still available.\nLearn more about [Workspace Trust](https://aka.ms/vscode-workspace-trust).\n[Manage Workspace Trust](command:workbench.trust.manage)",
|
||||
"configuration.maven.excludedFolders": "Specifies file path pattern of folders to exclude while searching for Maven projects.",
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
"contributes.commands.maven.project.goToDefinition": "转到定义",
|
||||
"contributes.commands.maven.project.excludeDependency": "删除依赖",
|
||||
"contributes.commands.maven.project.setDependencyVersion": "指定依赖版本为...",
|
||||
"contributes.commands.maven.project.addFavorite": "添加常用命令...",
|
||||
"contributes.commands.maven.dependency.goToEffective": "转到有效的依赖项",
|
||||
"contributes.views.explorer.mavenProjects": "Maven",
|
||||
"contributes.viewsWelcome.mavenProjects.untrustedWorkspaces": "高级功能(例如:执行生命周期阶段与插件的目标命令)将会因为安全考量在限制模式中被停用。\nPOM编辑辅助功能(例如:[添加依赖](command:maven.project.addDependency))仍可以使用。\n学习更多关于[工作区信任](https://aka.ms/vscode-workspace-trust)\n[管理工作区信任](command:workbench.trust.manage)",
|
||||
|
|
|
@ -15,10 +15,11 @@
|
|||
"contributes.commands.maven.view.flat": "切換到扁平檢視",
|
||||
"contributes.commands.maven.project.addDependency": "新增相依套件…",
|
||||
"contributes.commands.maven.project.showDependencies": "顯示所有相依套件",
|
||||
"contributes.commands.maven.project.goToDefinition": "移至定義",
|
||||
"contributes.commands.maven.project.excludeDependency": "刪除相依套件",
|
||||
"contributes.commands.maven.project.setDependencyVersion": "指定相依套件版本為...",
|
||||
"contributes.commands.maven.project.addFavorite": "添加常用命令...",
|
||||
"contributes.commands.maven.dependency.goToEffective": "移至有效的相依套件項",
|
||||
"contributes.commands.maven.project.goToDefinition": "移至定義",
|
||||
"contributes.views.explorer.mavenProjects": "Maven",
|
||||
"contributes.viewsWelcome.mavenProjects.untrustedWorkspaces": "進階功能 (例如: 執行生命週期階段與 Plugin 的目標命令) 將會因為安全考量在限制模式中被停用。\nPOM 編輯輔助功能 (例如: [新增相依套件](command:maven.project.addDependency)) 還是可以使用。\n學習更多關於 [工作區信任](https://aka.ms/vscode-workspace-trust)\n[管理工作區信任](command:workbench.trust.manage)",
|
||||
"configuration.maven.excludedFolders": "指定搜尋 Maven 專案時要排除的文件夾。",
|
||||
|
|
|
@ -6,6 +6,7 @@ import { Uri, workspace } from "vscode";
|
|||
import { FavoriteCommand } from "./explorer/model/FavoriteCommand";
|
||||
import { MavenProject } from "./explorer/model/MavenProject";
|
||||
|
||||
type FavoriteFormat = {alias: string; command: string; debug?: boolean}
|
||||
export namespace Settings {
|
||||
export function excludedFolders(resource: Uri): string[] {
|
||||
const ret: string[] | undefined = _getMavenSection<string[]>("excludedFolders", resource);
|
||||
|
@ -32,6 +33,12 @@ export namespace Settings {
|
|||
workspace.getConfiguration().update("maven.view", "hierarchical", false);
|
||||
}
|
||||
|
||||
export function storeFavorite(favorite: FavoriteFormat): void {
|
||||
const favorites: FavoriteFormat[] = workspace.getConfiguration().get("maven.terminal.favorites") ?? [];
|
||||
favorites.push(favorite);
|
||||
workspace.getConfiguration().update("maven.terminal.favorites", favorites);
|
||||
}
|
||||
|
||||
export function setMavenExecutablePath(mvnPath: string): void {
|
||||
workspace.getConfiguration().update("maven.executable.path", mvnPath, true);
|
||||
}
|
||||
|
|
|
@ -15,6 +15,10 @@ export class FavoritesMenu extends Menu implements ITreeItem {
|
|||
this.name = "Favorites";
|
||||
}
|
||||
|
||||
public getContextValue(): string {
|
||||
return "maven:favoritesMenu";
|
||||
}
|
||||
|
||||
public async getChildren(): Promise<FavoriteCommand[] | undefined> {
|
||||
return Settings.Terminal.favorites(this.project);
|
||||
}
|
||||
|
|
|
@ -27,11 +27,12 @@ import { pluginInfoProvider } from "./explorer/pluginInfoProvider";
|
|||
import { debugHandler } from "./handlers/debugHandler";
|
||||
import { addDependencyHandler } from "./handlers/dependency/addDependencyHandler";
|
||||
import { excludeDependencyHandler } from "./handlers/dependency/excludeDependencyHandler";
|
||||
import { addFavoriteHandler } from "./handlers/favorites/addFavoriteHandler";
|
||||
import { goToEffectiveHandler } from "./handlers/dependency/goToEffectiveHandler";
|
||||
import { jumpToDefinitionHandler } from "./handlers/dependency/jumpToDefinitionHandler";
|
||||
import { setDependencyVersionHandler } from "./handlers/dependency/setDependencyVersionHandler";
|
||||
import { showDependenciesHandler } from "./handlers/dependency/showDependenciesHandler";
|
||||
import { runFavoriteCommandsHandler } from "./handlers/runFavoriteCommandsHandler";
|
||||
import { runFavoriteCommandsHandler } from "./handlers/favorites/runFavoriteCommandsHandler";
|
||||
import { hoverProvider } from "./hover/hoverProvider";
|
||||
import { registerArtifactSearcher } from "./jdtls/artifactSearcher";
|
||||
import { isJavaExtEnabled } from "./jdtls/commands";
|
||||
|
@ -134,6 +135,9 @@ async function doActivate(_operationId: string, context: vscode.ExtensionContext
|
|||
registerCommand(context, "maven.project.setDependencyVersion", setDependencyVersionHandler);
|
||||
registerCommand(context, "maven.project.goToDefinition", jumpToDefinitionHandler);
|
||||
|
||||
// favorites
|
||||
registerCommand(context, "maven.project.addFavorite", addFavoriteHandler);
|
||||
|
||||
// debug
|
||||
registerCommand(context, "maven.plugin.debug", debugHandler);
|
||||
vscode.debug.onDidTerminateDebugSession((session) => {
|
||||
|
@ -202,6 +206,7 @@ function registerConfigChangeListener(context: vscode.ExtensionContext): void {
|
|||
if (e.affectsConfiguration("maven.view")
|
||||
|| e.affectsConfiguration("maven.pomfile.globPattern")
|
||||
|| e.affectsConfiguration("maven.explorer.projectName")
|
||||
|| e.affectsConfiguration("maven.terminal.favorites")
|
||||
) {
|
||||
MavenExplorerProvider.getInstance().refresh();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
import { Settings } from "../../Settings";
|
||||
import * as vscode from "vscode";
|
||||
|
||||
export async function addFavoriteHandler() {
|
||||
|
||||
const command = await vscode.window.showInputBox({
|
||||
title: "Add favorite",
|
||||
ignoreFocusOut: true,
|
||||
prompt: "Input a command for your favorite execute.",
|
||||
placeHolder: "e.g. clean install",
|
||||
validateInput: (text: string) => {
|
||||
if (text.trim().length < 2) {
|
||||
return "Command is too short.";
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
if (!command) {
|
||||
return;
|
||||
}
|
||||
|
||||
const alias = await vscode.window.showInputBox({
|
||||
title: "Add favorite",
|
||||
ignoreFocusOut: true,
|
||||
prompt: "Input an alias for your favorite.",
|
||||
placeHolder: "e.g. Clean and Build Project",
|
||||
value: command,
|
||||
validateInput: (text: string) => {
|
||||
if (text.trim().length < 3) {
|
||||
return "Favorite is too short.";
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
if (!alias) {
|
||||
return;
|
||||
}
|
||||
|
||||
const executionMode = await vscode.window.showQuickPick(
|
||||
["Run", "Debug"],
|
||||
{
|
||||
title: "Add favorite",
|
||||
placeHolder: "Select the command execution mode...",
|
||||
}
|
||||
);
|
||||
|
||||
if (!executionMode) {
|
||||
return;
|
||||
}
|
||||
|
||||
// store favorite into workspace settings
|
||||
const debug: boolean = executionMode === 'Debug';
|
||||
Settings.storeFavorite({alias, command, debug});
|
||||
}
|
|
@ -1,59 +1,59 @@
|
|||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import * as _ from "lodash";
|
||||
import * as vscode from "vscode";
|
||||
import { MavenProject } from "../explorer/model/MavenProject";
|
||||
import { Settings } from "../Settings";
|
||||
import { executeInTerminal } from "../utils/mavenUtils";
|
||||
import { selectProjectIfNecessary } from "../utils/uiUtils";
|
||||
import { debugCommand, IDebugOptions } from "./debugHandler";
|
||||
import { FavoriteCommand } from "../explorer/model/FavoriteCommand";
|
||||
|
||||
export async function runFavoriteCommandsHandler(project: MavenProject | undefined, command?: FavoriteCommand): Promise<void> {
|
||||
let selectedProject: MavenProject | undefined = project;
|
||||
if (!selectedProject) {
|
||||
selectedProject = await selectProjectIfNecessary();
|
||||
}
|
||||
if (!selectedProject) {
|
||||
return;
|
||||
}
|
||||
const favorites: FavoriteCommand[] | undefined = Settings.Terminal.favorites(selectedProject);
|
||||
if (!favorites || _.isEmpty(favorites)) {
|
||||
const BUTTON_OPEN_SETTINGS: string = "Open Settings";
|
||||
const choice: string | undefined = await vscode.window.showInformationMessage("Found no favorite commands. You can specify `maven.terminal.favorites` in Settings.", BUTTON_OPEN_SETTINGS);
|
||||
if (choice === BUTTON_OPEN_SETTINGS) {
|
||||
await vscode.commands.executeCommand("workbench.action.openSettings", "maven.terminal.favorites");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let selectedCommand: FavoriteCommand | undefined = command;
|
||||
if (!selectedCommand) {
|
||||
selectedCommand = await vscode.window.showQuickPick(
|
||||
favorites.map(item => ({
|
||||
value: item,
|
||||
label: item.alias,
|
||||
description: item.command
|
||||
})), {
|
||||
ignoreFocusOut: true,
|
||||
placeHolder: "Select a favorite command ...",
|
||||
matchOnDescription: true
|
||||
}
|
||||
).then(item => item ? item.value : undefined);
|
||||
}
|
||||
if (!selectedCommand) {
|
||||
return;
|
||||
}
|
||||
|
||||
const config: IDebugOptions = {
|
||||
command: selectedCommand.command,
|
||||
pomfile: selectedProject.pomPath,
|
||||
projectName: selectedProject.artifactId
|
||||
};
|
||||
if (selectedCommand.debug) {
|
||||
await debugCommand(config);
|
||||
} else {
|
||||
await executeInTerminal(config);
|
||||
}
|
||||
}
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT license.
|
||||
|
||||
import * as _ from "lodash";
|
||||
import * as vscode from "vscode";
|
||||
import { MavenProject } from "../../explorer/model/MavenProject";
|
||||
import { Settings } from "../../Settings";
|
||||
import { executeInTerminal } from "../../utils/mavenUtils";
|
||||
import { selectProjectIfNecessary } from "../../utils/uiUtils";
|
||||
import { debugCommand, IDebugOptions } from "../debugHandler";
|
||||
import { FavoriteCommand } from "../../explorer/model/FavoriteCommand";
|
||||
|
||||
export async function runFavoriteCommandsHandler(project: MavenProject | undefined, command?: FavoriteCommand): Promise<void> {
|
||||
let selectedProject: MavenProject | undefined = project;
|
||||
if (!selectedProject) {
|
||||
selectedProject = await selectProjectIfNecessary();
|
||||
}
|
||||
if (!selectedProject) {
|
||||
return;
|
||||
}
|
||||
const favorites: FavoriteCommand[] | undefined = Settings.Terminal.favorites(selectedProject);
|
||||
if (!favorites || _.isEmpty(favorites)) {
|
||||
const BUTTON_OPEN_SETTINGS: string = "Open Settings";
|
||||
const choice: string | undefined = await vscode.window.showInformationMessage("Found no favorite commands. You can specify `maven.terminal.favorites` in Settings.", BUTTON_OPEN_SETTINGS);
|
||||
if (choice === BUTTON_OPEN_SETTINGS) {
|
||||
await vscode.commands.executeCommand("workbench.action.openSettings", "maven.terminal.favorites");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
let selectedCommand: FavoriteCommand | undefined = command;
|
||||
if (!selectedCommand) {
|
||||
selectedCommand = await vscode.window.showQuickPick(
|
||||
favorites.map(item => ({
|
||||
value: item,
|
||||
label: item.alias,
|
||||
description: item.command
|
||||
})), {
|
||||
ignoreFocusOut: true,
|
||||
placeHolder: "Select a favorite command ...",
|
||||
matchOnDescription: true
|
||||
}
|
||||
).then(item => item ? item.value : undefined);
|
||||
}
|
||||
if (!selectedCommand) {
|
||||
return;
|
||||
}
|
||||
|
||||
const config: IDebugOptions = {
|
||||
command: selectedCommand.command,
|
||||
pomfile: selectedProject.pomPath,
|
||||
projectName: selectedProject.artifactId
|
||||
};
|
||||
if (selectedCommand.debug) {
|
||||
await debugCommand(config);
|
||||
} else {
|
||||
await executeInTerminal(config);
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ import { DEFAULT_MAVEN_LIFECYCLES } from "../completion/constants";
|
|||
import { FavoriteCommand } from "../explorer/model/FavoriteCommand";
|
||||
import { LifecyclePhase } from "../explorer/model/LifecyclePhase";
|
||||
import { MavenProject } from "../explorer/model/MavenProject";
|
||||
import { runFavoriteCommandsHandler } from "../handlers/runFavoriteCommandsHandler";
|
||||
import { runFavoriteCommandsHandler } from "../handlers/favorites/runFavoriteCommandsHandler";
|
||||
import { MavenProjectManager } from "../project/MavenProjectManager";
|
||||
import { Settings } from "../Settings";
|
||||
import { getExtensionVersion, getPathToTempFolder, getPathToWorkspaceStorage } from "./contextUtils";
|
||||
|
|
Загрузка…
Ссылка в новой задаче