Skip to content

Hide .meta files from navigation bar #1703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -294,7 +295,7 @@ class BuiltinPackageNode(project: Project, private val packageData: PackageData)

override fun calculateChildren(): MutableList<AbstractTreeNode<*>> {

if (UnityExplorer.getInstance(project!!).showHiddenItems) {
if (SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles) {
return super.calculateChildren()
}

Expand All @@ -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)
}

Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -41,9 +38,6 @@ class UnityExplorer(project: Project) : SolutionViewPaneBase(project, UnityExplo
}
}

var showHiddenItems = false
private set

var showTildeFolders = true
private set

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 "<br/>"
if (!unityExplorer.showHiddenItems) {
if (!SolutionExplorerViewPane.getInstance(myProject).myShowAllFiles) {
tooltip += virtualFile.name + "<br/>"
}
presentation.tooltip = tooltip + "This folder is not imported into the asset database"
Expand All @@ -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) }
Expand Down Expand Up @@ -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
}
}
Expand All @@ -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
}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
2 changes: 2 additions & 0 deletions rider/src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@
<standardResourceProvider implementation="com.jetbrains.rider.plugins.unity.settings.fileLayout.AdditionalFileLayoutStandardResourceProvider"/>
<xml.schemaProvider implementation="com.jetbrains.rider.plugins.unity.settings.fileLayout.AdditionalFileLayoutSchemaProvider"/>

<navbar implementation="com.jetbrains.rider.plugins.unity.ide.navigationToolbar.UnityNavBarModelExtension"/>

<projectService serviceImplementation="com.jetbrains.rider.plugins.unity.ui.UnityUIManager"/>
<projectService serviceImplementation="com.jetbrains.rider.UnityProjectDiscoverer"/>

Expand Down