From fd2bde19248c18991245714f841400d2f1c1d47c Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Thu, 18 Jun 2020 17:20:37 +0100 Subject: [PATCH 1/2] Use a common show all files setting --- .../plugins/unity/explorer/PackagesRoot.kt | 10 +- .../plugins/unity/explorer/UnityExplorer.kt | 93 +++++-------------- .../unity/explorer/UnityExplorerNode.kt | 18 ++-- 3 files changed, 38 insertions(+), 83 deletions(-) diff --git a/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/PackagesRoot.kt b/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/PackagesRoot.kt index 3760cff5ff..af568b25ca 100644 --- a/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/PackagesRoot.kt +++ b/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/PackagesRoot.kt @@ -15,6 +15,7 @@ import com.jetbrains.rider.projectView.views.FileSystemNodeBase import com.jetbrains.rider.projectView.views.SolutionViewNode import com.jetbrains.rider.projectView.views.addNonIndexedMark import com.jetbrains.rider.projectView.views.navigateToSolutionView +import com.jetbrains.rider.projectView.views.solutionExplorer.SolutionExplorerViewPane import icons.UnityIcons // Packages are included in a project by listing in the "dependencies" node of Packages/manifest.json. Packages can @@ -294,7 +295,7 @@ class BuiltinPackageNode(project: Project, private val packageData: PackageData) override fun calculateChildren(): MutableList> { - if (UnityExplorer.getInstance(project!!).showHiddenItems) { + if (SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles) { return super.calculateChildren() } @@ -314,14 +315,14 @@ class BuiltinPackageNode(project: Project, private val packageData: PackageData) } override fun canNavigateToSource(): Boolean { - if (UnityExplorer.getInstance(project!!).showHiddenItems) { + if (SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles) { return super.canNavigateToSource() } return true } override fun navigate(requestFocus: Boolean) { - if (UnityExplorer.getInstance(project!!).showHiddenItems) { + if (SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles) { return super.navigate(requestFocus) } @@ -336,8 +337,9 @@ class BuiltinPackageNode(project: Project, private val packageData: PackageData) override fun update(presentation: PresentationData) { presentation.addText(name, SimpleTextAttributes.REGULAR_ATTRIBUTES) presentation.setIcon(UnityIcons.Explorer.BuiltInPackage) - if (UnityExplorer.getInstance(myProject).showHiddenItems) + if (SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles) { presentation.addNonIndexedMark(myProject, virtualFile) + } val tooltip = getPackageTooltip(name, packageData) if (tooltip != name) { diff --git a/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/UnityExplorer.kt b/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/UnityExplorer.kt index 1e7a82c46e..d128daa9f9 100644 --- a/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/UnityExplorer.kt +++ b/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/UnityExplorer.kt @@ -3,18 +3,16 @@ package com.jetbrains.rider.plugins.unity.explorer import com.intellij.icons.AllIcons import com.intellij.ide.SelectInContext import com.intellij.ide.projectView.ProjectView -import com.intellij.openapi.actionSystem.* -import com.intellij.openapi.project.DumbAware +import com.intellij.openapi.actionSystem.ActionManager +import com.intellij.openapi.actionSystem.DefaultActionGroup import com.intellij.openapi.project.Project import com.intellij.openapi.util.JDOMExternalizerUtil -import com.jetbrains.rd.util.reflection.usingTrueFlag import com.jetbrains.rider.isUnityProject import com.jetbrains.rider.plugins.unity.packageManager.PackageManager -import com.jetbrains.rider.projectView.actions.ProjectViewActionBase -import com.jetbrains.rider.projectView.actions.assemblyExplorer.ViewInAssemblyExplorer import com.jetbrains.rider.projectView.nodes.IProjectModelNode import com.jetbrains.rider.projectView.views.SolutionViewPaneBase import com.jetbrains.rider.projectView.views.actions.ConfigureScratchesAction +import com.jetbrains.rider.projectView.views.actions.SolutionViewToggleAction import com.jetbrains.rider.projectView.views.impl.SolutionViewSelectInTargetBase import com.jetbrains.rider.projectView.views.solutionExplorer.SolutionExplorerViewPane import icons.UnityIcons @@ -26,7 +24,6 @@ class UnityExplorer(project: Project) : SolutionViewPaneBase(project, UnityExplo const val ID = "UnityExplorer" const val Title = "Unity" const val Weight = 1 - const val ShowHiddenItemsOption = "show-hidden-items" const val ShowProjectNamesOption = "show-project-names" const val ShowTildeFoldersOption = "show-tilde-folders" const val DefaultProjectPrefix = "Assembly-CSharp" @@ -41,9 +38,6 @@ class UnityExplorer(project: Project) : SolutionViewPaneBase(project, UnityExplo } } - var showHiddenItems = false - private set - var showTildeFolders = true private set @@ -75,16 +69,13 @@ class UnityExplorer(project: Project) : SolutionViewPaneBase(project, UnityExplo override fun writeExternal(element: Element) { super.writeExternal(element) - JDOMExternalizerUtil.writeField(element, ShowHiddenItemsOption, showHiddenItems.toString()) JDOMExternalizerUtil.writeField(element, ShowProjectNamesOption, showProjectNames.toString()) JDOMExternalizerUtil.writeField(element, ShowTildeFoldersOption, showTildeFolders.toString()) } override fun readExternal(element: Element) { super.readExternal(element) - var option = JDOMExternalizerUtil.readField(element, ShowHiddenItemsOption) - showHiddenItems = option != null && java.lang.Boolean.parseBoolean(option) - option = JDOMExternalizerUtil.readField(element, ShowProjectNamesOption) + var option = JDOMExternalizerUtil.readField(element, ShowProjectNamesOption) showProjectNames = option == null || java.lang.Boolean.parseBoolean(option) option = JDOMExternalizerUtil.readField(element, ShowTildeFoldersOption) showTildeFolders = option == null || java.lang.Boolean.parseBoolean(option) @@ -113,72 +104,30 @@ class UnityExplorer(project: Project) : SolutionViewPaneBase(project, UnityExplo // Adds to the tool window toolbar override fun addToolbarActions(actionGroup: DefaultActionGroup) { actionGroup.addAction(ConfigureScratchesAction()).setAsSecondary(true) - actionGroup.addAction(ShowProjectNamesAction()).setAsSecondary(true) - actionGroup.addAction(ShowTildeFoldersAction()).setAsSecondary(true) + actionGroup.addAction(SolutionViewToggleAction("Show Project Names", + "Show names of owning projects next to folders", + AllIcons.Actions.ListFiles, + { showProjectNames }, { showProjectNames = it } + )).setAsSecondary(true) + actionGroup.addAction(SolutionViewToggleAction("Show Hidden Folders", + "Show folders ending with '~'", + AllIcons.Actions.ListFiles, + { showTildeFolders }, { showTildeFolders = it } + )).setAsSecondary(true) super.addToolbarActions(actionGroup) } // Adds to the project view pane's own toolbar override fun addPrimaryToolbarActions(actionGroup: DefaultActionGroup) { - actionGroup.addAction(ShowHiddenItemsAction()) + actionGroup.addAction(SolutionViewToggleAction("Show All Files", + "Show all files, including .meta files", + AllIcons.Actions.ShowHiddens, { + SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles + }, { + SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles = it + })) ActionManager.getInstance().getAction("ViewInAssemblyExplorer")!!.let { actionGroup.addAction(it) } actionGroup.addSeparator() super.addPrimaryToolbarActions(actionGroup) } - - private inner class ShowHiddenItemsAction - : ToggleAction("Show All Files", "Show all files, including .meta files", AllIcons.Actions.ShowHiddens), DumbAware { - - override fun isSelected(event: AnActionEvent) = showHiddenItems - - override fun setSelected(event: AnActionEvent, flag: Boolean) { - if (showHiddenItems != flag) { - showHiddenItems = flag - updateFromRoot(false) - } - } - - override fun update(e: AnActionEvent) { - super.update(e) - e.presentation.isEnabledAndVisible = ProjectView.getInstance(myProject).currentProjectViewPane === this@UnityExplorer - } - } - - private inner class ShowTildeFoldersAction - : ToggleAction("Show Hidden Folders", "Show folders ending with '~'", AllIcons.Actions.ListFiles), DumbAware { - - override fun isSelected(event: AnActionEvent) = showTildeFolders - - override fun setSelected(event: AnActionEvent, flag: Boolean) { - if (showTildeFolders != flag) { - showTildeFolders = flag - updateFromRoot(false) - } - } - - override fun update(e: AnActionEvent) { - super.update(e) - e.presentation.isEnabledAndVisible = ProjectView.getInstance(myProject).currentProjectViewPane == this@UnityExplorer - } - } - - private inner class ShowProjectNamesAction - : ToggleAction("Show Project Names", "Show names of owning projects next to folders", AllIcons.Actions.ListFiles), DumbAware { - - override fun isSelected(event: AnActionEvent): Boolean { - return showProjectNames - } - - override fun setSelected(event: AnActionEvent, flag: Boolean) { - if (showProjectNames != flag) { - showProjectNames = flag - updateFromRoot(false) - } - } - - override fun update(e: AnActionEvent) { - super.update(e) - e.presentation.isEnabledAndVisible = ProjectView.getInstance(myProject).currentProjectViewPane === this@UnityExplorer - } - } } diff --git a/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/UnityExplorerNode.kt b/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/UnityExplorerNode.kt index 3b45ecdd5f..956e3e3d72 100644 --- a/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/UnityExplorerNode.kt +++ b/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/explorer/UnityExplorerNode.kt @@ -17,6 +17,7 @@ import com.jetbrains.rider.projectView.views.FileSystemNodeBase import com.jetbrains.rider.projectView.views.SolutionViewRootNodeBase import com.jetbrains.rider.projectView.views.actions.ConfigureScratchesAction import com.jetbrains.rider.projectView.views.fileSystemExplorer.FileSystemExplorerCustomization +import com.jetbrains.rider.projectView.views.solutionExplorer.SolutionExplorerViewPane import icons.UnityIcons import java.awt.Color import javax.swing.Icon @@ -124,9 +125,9 @@ open class UnityExplorerNode(project: Project, // Add tooltip for non-imported folders (anything ending with tilde). Also, show the full name if we're hiding // the tilde suffix - if (virtualFile.isDirectory && virtualFile.name.endsWith("~")) { + if (isHiddenFolder(virtualFile)) { var tooltip = if (presentation.tooltip.isNullOrEmpty()) "" else "
" - if (!unityExplorer.showHiddenItems) { + if (!SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles) { tooltip += virtualFile.name + "
" } presentation.tooltip = tooltip + "This folder is not imported into the asset database" @@ -136,12 +137,15 @@ open class UnityExplorerNode(project: Project, override fun getName(): String { // Remember that *~ is a default ignore pattern for IntelliJ. Any files/folders in and under this folder won't // be indexed. Hopefully this comment will stop someone wasting as much time as I did. - if (virtualFile.isDirectory && !UnityExplorer.getInstance(myProject).showHiddenItems) { + if (isHiddenFolder(virtualFile) && !SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles) { return super.getName().removeSuffix("~") } return super.getName() } + private fun isHiddenFolder(file: VirtualFile) + = descendentOf != AncestorNodeType.FileSystem && file.isDirectory && file.name.endsWith("~") + protected fun addProjects(presentation: PresentationData) { val projectNames = nodes // One node for each project that this directory is part of .mapNotNull { containingProjectNode(it) } @@ -286,7 +290,7 @@ open class UnityExplorerNode(project: Project, // Note that its only the root node that's marked as "unloaded"/not imported. Child files and folder icons // are rendered as normal - if (virtualFile.name.endsWith("~") && virtualFile.isDirectory) { + if (isHiddenFolder(virtualFile)) { return UnityIcons.Explorer.UnloadedFolder } } @@ -308,7 +312,7 @@ open class UnityExplorerNode(project: Project, } private fun shouldShowVirtualFile(file: VirtualFile): Boolean { - if (UnityExplorer.getInstance(myProject).showHiddenItems) { + if (SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles) { return true } @@ -329,8 +333,8 @@ open class UnityExplorerNode(project: Project, be used for distributing code, too. This code will not be treated as assets by Unity, but will still be added to the generated .csproj files to allow for use as e.g. command line tools */ - if (file.name.endsWith("~")) { - return file.isDirectory && UnityExplorer.getInstance(myProject).showTildeFolders + if (isHiddenFolder(file)) { + return UnityExplorer.getInstance(myProject).showTildeFolders } return true From 4f6deadbd2794182964b99b1f208dbe5978080b7 Mon Sep 17 00:00:00 2001 From: Matt Ellis Date: Thu, 18 Jun 2020 17:37:50 +0100 Subject: [PATCH 2/2] Hide .meta files from navbar Fixes RIDER-28425 --- .../UnityNavBarModelExtension.kt | 39 +++++++++++++++++++ rider/src/main/resources/META-INF/plugin.xml | 2 + 2 files changed, 41 insertions(+) create mode 100644 rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/ide/navigationToolbar/UnityNavBarModelExtension.kt diff --git a/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/ide/navigationToolbar/UnityNavBarModelExtension.kt b/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/ide/navigationToolbar/UnityNavBarModelExtension.kt new file mode 100644 index 0000000000..40ca269d55 --- /dev/null +++ b/rider/src/main/kotlin/com/jetbrains/rider/plugins/unity/ide/navigationToolbar/UnityNavBarModelExtension.kt @@ -0,0 +1,39 @@ +package com.jetbrains.rider.plugins.unity.ide.navigationToolbar + +import com.intellij.ide.navigationToolbar.AbstractNavBarModelExtension +import com.intellij.openapi.project.Project +import com.intellij.psi.PsiElement +import com.intellij.psi.PsiFile +import com.jetbrains.rider.plugins.unity.ideaInterop.fileTypes.yaml.UnityYamlFileType +import com.jetbrains.rider.projectView.views.solutionExplorer.SolutionExplorerViewPane + +// This class hides .meta files from the navigation bar, and they can be shown again using the "show all files" setting +// in Solution Explorer or Unity Explorer. +// We don't hide folders such as Library, obj and Temp because the navbar is a view of the filesystem, rather than a +// view of the project model (in IntelliJ that's essentially the same thing). We could ignore these folders, but what +// should happen to other files/folders in the project root? We hide `.meta` because there is one for each file and +// folder, and they create a lot of noise. +// The navbar only lists files and folders that are not already excluded by the File Types | Ignored Files and Folders +// list. This means we don't see `.git`, but it also means `*~` is filtered, which impacts Unity's "hidden" folders, +// such as `Documentation~` (named like this so the asset database doesn't import the files). We can't override this +// setting (mainly because it's hardcoded, and a global setting, not per-project), so we will have some files shown in +// the Unity Explorer, but not shown in the navbar. +class UnityNavBarModelExtension : AbstractNavBarModelExtension() { + override fun getPresentableText(o: Any?): String? = null + + override fun adjustElement(psiElement: PsiElement) = + if (shouldHide(psiElement)) null else super.adjustElement(psiElement) + + private fun shouldHide(psiElement: PsiElement) = isMetaFile(psiElement) && !shouldShowMetaFiles(psiElement.project) + + private fun shouldShowMetaFiles(project: Project): Boolean { + return SolutionExplorerViewPane.getInstance(project).myShowAllFiles + } + + private fun isMetaFile(psiElement: PsiElement): Boolean { + if (psiElement is PsiFile) { + return psiElement.fileType == UnityYamlFileType && psiElement.name.endsWith(".meta", false) + } + return false + } +} \ No newline at end of file diff --git a/rider/src/main/resources/META-INF/plugin.xml b/rider/src/main/resources/META-INF/plugin.xml index f0f377cb97..5e4b6a214e 100644 --- a/rider/src/main/resources/META-INF/plugin.xml +++ b/rider/src/main/resources/META-INF/plugin.xml @@ -120,6 +120,8 @@ + +