Skip to content

Commit b806a30

Browse files
authored
Restore icon provider (#30)
1 parent c313672 commit b806a30

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [Unreleased]
44

55
- Extend compatibility for PyCharm Professional
6+
- Fix Icon provider did not survive migration to v2
67

78
## [2.0.0] - 2024-08-12
89

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.github.pyvenvmanage
2+
3+
import javax.swing.Icon
4+
5+
import com.intellij.ide.IconLayerProvider
6+
import com.intellij.ide.IconProvider
7+
import com.intellij.openapi.util.Iconable
8+
import com.intellij.psi.PsiDirectory
9+
import com.intellij.psi.PsiElement
10+
11+
import com.jetbrains.python.icons.PythonIcons.Python.Virtualenv
12+
import com.jetbrains.python.sdk.PythonSdkUtil
13+
14+
class VenvIconProvider :
15+
IconProvider(),
16+
IconLayerProvider {
17+
override fun getLayerDescription(): String = "Python virtual environment"
18+
19+
override fun getIcon(
20+
element: PsiElement,
21+
flags: Int,
22+
): Icon? = determineIcon(element)
23+
24+
override fun getLayerIcon(
25+
element: Iconable,
26+
isLocked: Boolean,
27+
): Icon? = determineIcon(element)
28+
29+
private fun determineIcon(element: Any): Icon? {
30+
if (element is PsiDirectory) {
31+
val venvRootPath = element.virtualFile.path
32+
if (PythonSdkUtil.getPythonExecutable(venvRootPath) != null) {
33+
return Virtualenv
34+
}
35+
}
36+
return null
37+
}
38+
}

src/main/resources/META-INF/plugin.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
<extensions defaultExtensionNs="com.intellij">
1010
<notificationGroup id="Python SDK change" displayType="BALLOON"/>
11+
<iconProvider implementation="com.github.pyvenvmanage.VenvIconProvider" />
12+
<iconLayerProvider implementation="com.github.pyvenvmanage.VenvIconProvider" />
1113
</extensions>
1214

1315
<actions>
@@ -30,4 +32,5 @@
3032
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
3133
</action>
3234
</actions>
35+
3336
</idea-plugin>

0 commit comments

Comments
 (0)