Skip to content

Commit

Permalink
Restore icon provider (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Aug 12, 2024
1 parent c313672 commit b806a30
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

- Extend compatibility for PyCharm Professional
- Fix Icon provider did not survive migration to v2

## [2.0.0] - 2024-08-12

Expand Down
38 changes: 38 additions & 0 deletions src/main/kotlin/com/github/pyvenvmanage/VenvIconProvider.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.github.pyvenvmanage

import javax.swing.Icon

import com.intellij.ide.IconLayerProvider
import com.intellij.ide.IconProvider
import com.intellij.openapi.util.Iconable
import com.intellij.psi.PsiDirectory
import com.intellij.psi.PsiElement

import com.jetbrains.python.icons.PythonIcons.Python.Virtualenv
import com.jetbrains.python.sdk.PythonSdkUtil

class VenvIconProvider :
IconProvider(),
IconLayerProvider {
override fun getLayerDescription(): String = "Python virtual environment"

override fun getIcon(
element: PsiElement,
flags: Int,
): Icon? = determineIcon(element)

override fun getLayerIcon(
element: Iconable,
isLocked: Boolean,
): Icon? = determineIcon(element)

private fun determineIcon(element: Any): Icon? {
if (element is PsiDirectory) {
val venvRootPath = element.virtualFile.path
if (PythonSdkUtil.getPythonExecutable(venvRootPath) != null) {
return Virtualenv
}
}
return null
}
}
3 changes: 3 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

<extensions defaultExtensionNs="com.intellij">
<notificationGroup id="Python SDK change" displayType="BALLOON"/>
<iconProvider implementation="com.github.pyvenvmanage.VenvIconProvider" />
<iconLayerProvider implementation="com.github.pyvenvmanage.VenvIconProvider" />
</extensions>

<actions>
Expand All @@ -30,4 +32,5 @@
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
</action>
</actions>

</idea-plugin>

0 comments on commit b806a30

Please sign in to comment.