From b304e48da2463a3d81633c66713d8a0505cd1483 Mon Sep 17 00:00:00 2001 From: Sheng Chen Date: Fri, 21 Apr 2023 12:57:25 +0800 Subject: [PATCH] fix: Change the setting 'java.project.explorer.filters' to 'java.project.explorer.showNonJavaResources' (#755) --- CHANGELOG.md | 3 +-- package.json | 33 +++++++++++++++------------- package.nls.json | 6 ++--- package.nls.zh-cn.json | 6 ++--- src/commands.ts | 4 +++- src/settings.ts | 16 +++++--------- src/views/dependencyExplorer.ts | 22 +++++-------------- test/maven-suite/projectView.test.ts | 6 ++--- 8 files changed, 42 insertions(+), 54 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ba5835..0ecb5aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,14 +8,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Display non-Java files in Java Projects explorer. [#145](https://github.com/microsoft/vscode-java-dependency/issues/145) - Show non-Java projects in the Java Projects explorer. [#736](https://github.com/microsoft/vscode-java-dependency/issues/736) -- Introduce a setting: `java.project.explorer.filters` to control whether non-Java resources show in Java Projects explorer. [#751](https://github.com/microsoft/vscode-java-dependency/issues/751) +- Introduce a setting: `java.project.explorer.showNonJavaResources` to control whether non-Java resources show in Java Projects explorer. [#751](https://github.com/microsoft/vscode-java-dependency/issues/751) - Support creating files and folders in Java Projects explorer. [#598](https://github.com/microsoft/vscode-java-dependency/issues/598) - Apply file decorators to project level. [#481](https://github.com/microsoft/vscode-java-dependency/issues/481) - Give more hints about the project import status. [#580](https://github.com/microsoft/vscode-java-dependency/issues/580) ### Fixed - Apply `files.exclude` to Java Projects explorer. [#214](https://github.com/microsoft/vscode-java-dependency/issues/214) - Empty packages will not appear sometimes. [#600](https://github.com/microsoft/vscode-java-dependency/issues/600) -- Show `module-info.java` at source roots. [#698](https://github.com/microsoft/vscode-java-dependency/issues/698) - Show Java files which does not have a primary type in the Java Projects explorer. [#748](https://github.com/microsoft/vscode-java-dependency/issues/748) ## 0.21.2 diff --git a/package.json b/package.json index 5cc552a..a69a3e1 100644 --- a/package.json +++ b/package.json @@ -143,8 +143,13 @@ } }, { - "command": "java.project.explorer.configureFilters", - "title": "%contributes.commands.java.project.explorer.configureFilters%", + "command": "java.project.explorer.showNonJavaResources", + "title": "%contributes.commands.java.project.explorer.showNonJavaResources%", + "category": "Java" + }, + { + "command": "java.project.explorer.hideNonJavaResources", + "title": "%contributes.commands.java.project.explorer.hideNonJavaResources%", "category": "Java" }, { @@ -270,17 +275,10 @@ "markdownDescription": "%configuration.java.project.exportJar.targetPath.customization%", "default": "${workspaceFolder}/${workspaceFolderBasename}.jar" }, - "java.project.explorer.filters": { - "type": "object", - "description": "%configuration.java.project.explorer.filters%", - "default": {}, - "properties": { - "nonJavaResources": { - "type": "boolean", - "description": "%configuration.java.project.explorer.filters.nonJavaResources%", - "default": false - } - } + "java.project.explorer.showNonJavaResources": { + "type": "boolean", + "description": "%configuration.java.project.explorer.showNonJavaResources%", + "default": true } } }, @@ -509,8 +507,13 @@ "group": "overflow_10@20" }, { - "command": "java.project.explorer.configureFilters", - "when": "view == javaProjectExplorer && java:serverMode == Standard", + "command": "java.project.explorer.showNonJavaResources", + "when": "view == javaProjectExplorer && java:serverMode == Standard && !config.java.project.explorer.showNonJavaResources", + "group": "overflow_10@30" + }, + { + "command": "java.project.explorer.hideNonJavaResources", + "when": "view == javaProjectExplorer && java:serverMode == Standard && config.java.project.explorer.showNonJavaResources", "group": "overflow_10@30" }, { diff --git a/package.nls.json b/package.nls.json index b390d80..f02c36f 100644 --- a/package.nls.json +++ b/package.nls.json @@ -15,7 +15,8 @@ "contributes.commands.java.view.package.changeToHierarchicalPackageView":"Hierarchical View", "contributes.commands.java.view.package.linkWithFolderExplorer":"Synchronize with Editor", "contributes.commands.java.view.package.unlinkWithFolderExplorer":"Desynchronize with Editor", - "contributes.commands.java.project.explorer.configureFilters": "Configure Filters", + "contributes.commands.java.project.explorer.showNonJavaResources": "Show Non-Java Resources", + "contributes.commands.java.project.explorer.hideNonJavaResources": "Hide Non-Java Resources", "contributes.commands.java.view.package.revealFileInOS": "Reveal in Explorer", "contributes.commands.java.view.package.exportJar": "Export Jar...", "contributes.commands.java.view.package.copyFilePath": "Copy Path", @@ -35,8 +36,7 @@ "configuration.java.dependency.autoRefresh": "Synchronize Java Projects explorer with changes", "configuration.java.dependency.refreshDelay": "The delay time (ms) the auto refresh is invoked when changes are detected", "configuration.java.dependency.packagePresentation": "Package presentation mode: flat or hierarchical", - "configuration.java.project.explorer.filters": "Filters for the Java Projects explorer.", - "configuration.java.project.explorer.filters.nonJavaResources": "Specify whether non-Java resources will be filtered out.", + "configuration.java.project.explorer.showNonJavaResources": "When enabled, the explorer shows non-Java resources.", "configuration.java.project.exportJar.targetPath.customization": "The output path of the exported jar. Leave it empty if you want to manually pick the output location.", "configuration.java.project.exportJar.targetPath.workspaceFolder": "Export the jar file into the workspace folder. Its name is the same as the folder's.", "configuration.java.project.exportJar.targetPath.select": "Select output location manually when exporting the jar file.", diff --git a/package.nls.zh-cn.json b/package.nls.zh-cn.json index a672972..4234ad5 100644 --- a/package.nls.zh-cn.json +++ b/package.nls.zh-cn.json @@ -15,7 +15,8 @@ "contributes.commands.java.view.package.changeToHierarchicalPackageView":"层级显示", "contributes.commands.java.view.package.linkWithFolderExplorer":"启用编辑器关联", "contributes.commands.java.view.package.unlinkWithFolderExplorer":"关闭编辑器关联", - "contributes.commands.java.project.explorer.configureFilters": "设置过滤器", + "contributes.commands.java.project.explorer.showNonJavaResources": "显示非 Java 资源", + "contributes.commands.java.project.explorer.hideNonJavaResources": "隐藏非 Java 资源", "contributes.commands.java.view.package.revealFileInOS": "打开所在的文件夹", "contributes.commands.java.view.package.exportJar": "导出到 Jar 文件...", "contributes.commands.java.view.package.copyFilePath": "复制路径", @@ -35,8 +36,7 @@ "configuration.java.dependency.autoRefresh": "在 Java 项目管理器中自动同步修改", "configuration.java.dependency.refreshDelay": "控制 Java 项目管理器刷新的延迟时间 (毫秒)", "configuration.java.dependency.packagePresentation": "Java 包显示方式: 平行显示或者分层显示", - "configuration.java.project.explorer.filters": "设置 Java 项目管理器要过滤的内容。", - "configuration.java.project.explorer.filters.nonJavaResources": "是否需要过滤非 Java 资源。", + "configuration.java.project.explorer.showNonJavaResources": "启用时 Java 项目管理器将显示非 Java 资源。", "configuration.java.project.exportJar.targetPath.customization": "导出 Jar 文件的路径。您可以将此选项置为空串来手动选择 jar 文件的导出路径。", "configuration.java.project.exportJar.targetPath.workspaceFolder": "导出 Jar 文件到工作空间文件夹下。Jar 文件的名称和工作空间文件夹的名称相同。", "configuration.java.project.exportJar.targetPath.select": "在导出 Jar 文件时手动选择输出目录。", diff --git a/src/commands.ts b/src/commands.ts index 1976893..c64f0f3 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -18,7 +18,9 @@ export namespace Commands { export const VIEW_PACKAGE_UNLINKWITHFOLDER = "java.view.package.unlinkWithFolderExplorer"; - export const JAVA_PROJECT_EXPLORER_CONFIGURE_FILTERS = "java.project.explorer.configureFilters"; + export const JAVA_PROJECT_EXPLORER_SHOW_NONJAVA_RESOURCES = "java.project.explorer.showNonJavaResources"; + + export const JAVA_PROJECT_EXPLORER_HIDE_NONJAVA_RESOURCES = "java.project.explorer.hideNonJavaResources"; export const VIEW_PACKAGE_REFRESH = "java.view.package.refresh"; diff --git a/src/settings.ts b/src/settings.ts index 35dd9b8..bea8e7c 100644 --- a/src/settings.ts +++ b/src/settings.ts @@ -17,7 +17,7 @@ export class Settings { if ((e.affectsConfiguration("java.dependency.syncWithFolderExplorer") && Settings.syncWithFolderExplorer()) || e.affectsConfiguration("java.dependency.showMembers") || e.affectsConfiguration("java.dependency.packagePresentation") || - e.affectsConfiguration("java.project.explorer.filters") || + e.affectsConfiguration("java.project.explorer.showNonJavaResources") || e.affectsConfiguration("files.exclude")) { commands.executeCommand(Commands.VIEW_PACKAGE_INTERNAL_REFRESH); } else if (e.affectsConfiguration("java.dependency.autoRefresh")) { @@ -60,9 +60,10 @@ export class Settings { public static switchNonJavaResourceFilter(enabled: boolean): void { workspace.getConfiguration("java.project.explorer").update( - "filters", - { nonJavaResources: enabled }, - ConfigurationTarget.Workspace); + "showNonJavaResources", + enabled, + ConfigurationTarget.Workspace + ); } public static updateReferencedLibraries(libraries: IReferencedLibraries): void { @@ -116,8 +117,7 @@ export class Settings { * Get whether non-Java resources should be filtered in the explorer. */ public static nonJavaResourcesFiltered(): boolean { - const filter: IExplorerFilter = workspace.getConfiguration("java.project.explorer").get("filters", {}); - return !!filter.nonJavaResources; + return !workspace.getConfiguration("java.project.explorer").get("showNonJavaResources", true); } } @@ -131,7 +131,3 @@ export interface IReferencedLibraries { exclude: string[]; sources: { [binary: string]: string }; } - -interface IExplorerFilter { - nonJavaResources?: boolean -} diff --git a/src/views/dependencyExplorer.ts b/src/views/dependencyExplorer.ts index 6d1d0a1..90384d1 100644 --- a/src/views/dependencyExplorer.ts +++ b/src/views/dependencyExplorer.ts @@ -90,23 +90,11 @@ export class DependencyExplorer implements Disposable { this.reveal(uri, false /*force to reveal even the sync setting is turned off*/); }), - instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_EXPLORER_CONFIGURE_FILTERS, async () => { - const filters = await window.showQuickPick( - [{ - label: "Non-Java resources", - picked: Settings.nonJavaResourcesFiltered(), - }], - { - placeHolder: "Select filters to apply to the Java Projects Explorer", - canPickMany: true, - ignoreFocusOut: true, - } - ); - if (!filters) { - return; - } - - Settings.switchNonJavaResourceFilter(filters.some((filter) => filter.label === "Non-Java resources")); + instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_EXPLORER_SHOW_NONJAVA_RESOURCES, async () => { + Settings.switchNonJavaResourceFilter(true); + }), + instrumentOperationAsVsCodeCommand(Commands.JAVA_PROJECT_EXPLORER_HIDE_NONJAVA_RESOURCES, async () => { + Settings.switchNonJavaResourceFilter(false); }), ); diff --git a/test/maven-suite/projectView.test.ts b/test/maven-suite/projectView.test.ts index 31a10d4..cdb6913 100644 --- a/test/maven-suite/projectView.test.ts +++ b/test/maven-suite/projectView.test.ts @@ -243,10 +243,10 @@ suite("Maven Project View Tests", () => { assert.ok(!projectChildren.find((node: DataNode) => node.nodeData.name === ".hidden")); }); - test("Can apply 'java.project.explorer.filters.nonJavaResources'", async function() { + test("Can apply 'java.project.explorer.showNonJavaResources'", async function() { await vscode.workspace.getConfiguration("java.project.explorer").update( - "filters", - { nonJavaResources:true } + "showNonJavaResources", + false ); const explorer = DependencyExplorer.getInstance(contextManager.context);