-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c313672
commit b806a30
Showing
3 changed files
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/com/github/pyvenvmanage/VenvIconProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters