feat: Support create different kind of resources from inline new button. (#754)

This commit is contained in:
Sheng Chen 2023-04-14 16:31:35 +08:00 коммит произвёл GitHub
Родитель 100b67772e
Коммит 3b75af221b
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
7 изменённых файлов: 69 добавлений и 8 удалений

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

@ -168,6 +168,12 @@
"title": "%contributes.commands.java.view.package.copyRelativeFilePath%",
"category": "Java"
},
{
"command": "java.view.package.new",
"title": "%contributes.commands.java.view.package.new%",
"category": "Java",
"icon": "$(add)"
},
{
"command": "java.view.menus.file.newJavaClass",
"title": "%contributes.commands.java.view.menus.file.newJavaClass%",
@ -382,6 +388,10 @@
"command": "java.project.refreshLibraries",
"when": "false"
},
{
"command": "java.view.package.new",
"when": "false"
},
{
"command": "java.view.package.newJavaClass",
"when": "false"
@ -576,13 +586,8 @@
"group": "1_new@10"
},
{
"command": "java.view.package.newJavaClass",
"when": "view == javaProjectExplorer && viewItem =~ /java:project(?=.*?\\b\\+java\\b)(?=.*?\\b\\+uri\\b)/",
"group": "inline@add_0"
},
{
"command": "java.view.package.newJavaClass",
"when": "view == javaProjectExplorer && viewItem =~ /java:(package|packageRoot)(?=.*?\\b\\+source\\b)(?=.*?\\b\\+uri\\b)/",
"command": "java.view.package.new",
"when": "view == javaProjectExplorer && viewItem =~ /java(?!:container)(?!:jar)(?!.*?\\b\\+binary\\b)(?=.*?\\b\\+uri\\b)/",
"group": "inline@add_0"
},
{

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

@ -20,6 +20,7 @@
"contributes.commands.java.view.package.exportJar": "Export Jar...",
"contributes.commands.java.view.package.copyFilePath": "Copy Path",
"contributes.commands.java.view.package.copyRelativeFilePath": "Copy Relative Path",
"contributes.commands.java.view.package.new": "New...",
"contributes.commands.java.view.package.newJavaClass": "Java Class",
"contributes.commands.java.view.package.newPackage": "Package",
"contributes.commands.java.view.package.newFile": "File",

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

@ -20,6 +20,7 @@
"contributes.commands.java.view.package.exportJar": "导出到 Jar 文件...",
"contributes.commands.java.view.package.copyFilePath": "复制路径",
"contributes.commands.java.view.package.copyRelativeFilePath": "复制相对路径",
"contributes.commands.java.view.package.new": "创建...",
"contributes.commands.java.view.package.newJavaClass": "Java 类",
"contributes.commands.java.view.package.newPackage": "包",
"contributes.commands.java.view.package.newFile": "文件",

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

@ -19,6 +19,7 @@
"contributes.commands.java.view.package.exportJar": "匯出成 Jar 檔案...",
"contributes.commands.java.view.package.copyFilePath": "複製路徑",
"contributes.commands.java.view.package.copyRelativeFilePath": "複製相對路徑",
"contributes.commands.java.view.package.new": "建立...",
"contributes.commands.java.view.package.newJavaClass": "Java 類別",
"contributes.commands.java.view.package.newPackage": "套件",
"contributes.commands.java.view.package.newFile": "檔案",

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

@ -36,6 +36,8 @@ export namespace Commands {
export const EXPORT_JAR_REPORT = "java.view.package.exportJarReport";
export const VIEW_PACKAGE_NEW = "java.view.package.new";
export const VIEW_PACKAGE_NEW_JAVA_CLASS = "java.view.package.newJavaClass";
export const VIEW_PACKAGE_NEW_JAVA_PACKAGE = "java.view.package.newPackage";

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

@ -13,6 +13,54 @@ import { resourceRoots } from "../views/packageRootNode";
import { checkJavaQualifiedName } from "./utility";
import { sendError, setUserError } from "vscode-extension-telemetry-wrapper";
export async function newResource(node: DataNode): Promise<void> {
const availableTypes: string[] = [];
// add options for Java nodes
if (node.nodeData.kind === NodeKind.Project ||
(node.nodeData.kind === NodeKind.PackageRoot && !resourceRoots.includes(node.nodeData.name)) ||
node.nodeData.kind === NodeKind.Package ||
node.nodeData.kind === NodeKind.PrimaryType ||
node.nodeData.kind === NodeKind.CompilationUnit) {
availableTypes.push("$(symbol-class) Java Class", "$(symbol-namespace) Package");
}
// add new file option
availableTypes.push("$(file) File");
// add new folder option
if (node.nodeData.kind === NodeKind.Project ||
(node.nodeData.kind === NodeKind.PackageRoot && resourceRoots.includes(node.nodeData.name)) ||
node.nodeData.kind === NodeKind.Folder ||
node.nodeData.kind === NodeKind.File) {
availableTypes.push("$(folder) Folder");
}
const type = await window.showQuickPick(
availableTypes,
{
placeHolder: "Select resource type to create.",
ignoreFocusOut: true,
}
);
switch (type) {
case "$(symbol-class) Java Class":
await newJavaClass(node);
break;
case "$(symbol-namespace) Package":
await newPackage(node);
break;
case "$(file) File":
await newFile(node);
break;
case "$(folder) Folder":
await newFolder(node);
break;
default:
break;
}
}
// TODO: separate to two function to handle creation from menu bar and explorer.
export async function newJavaClass(node?: DataNode): Promise<void> {
let packageFsPath: string | undefined;

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

@ -12,7 +12,7 @@ import {
import { instrumentOperationAsVsCodeCommand, sendInfo } from "vscode-extension-telemetry-wrapper";
import { Commands } from "../commands";
import { deleteFiles } from "../explorerCommands/delete";
import { newFile, newFolder, newJavaClass, newPackage } from "../explorerCommands/new";
import { newFile, newFolder, newJavaClass, newPackage, newResource } from "../explorerCommands/new";
import { renameFile } from "../explorerCommands/rename";
import { getCmdNode } from "../explorerCommands/utility";
import { Jdtls } from "../java/jdtls";
@ -125,6 +125,9 @@ export class DependencyExplorer implements Disposable {
// register keybinding commands
context.subscriptions.push(
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW, async (node: DataNode) => {
newResource(node);
}),
instrumentOperationAsVsCodeCommand(Commands.VIEW_PACKAGE_NEW_JAVA_CLASS, async (node?: DataNode) => {
newJavaClass(node);
}),