Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
HannahSchellekens committed Nov 7, 2018
0 parents commit 10fa96b
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 0 deletions.
78 changes: 78 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Created by .ignore support plugin (hsz.mobi)
### Kotlin template
# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/dictionaries
.idea/**/shelf
.idea/misc.xml
.idea/inspectionProfiles/

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# CMake
cmake-build-debug/
cmake-build-release/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

1 change: 1 addition & 0 deletions .idea/.name

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions KotlinIcon.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PLUGIN_MODULE" version="4">
<component name="DevKit.ModuleBuildProperties" url="file://$MODULE_DIR$/resources/META-INF/plugin.xml" />
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/out/production/KotlinIcon" />
<output-test url="file://$MODULE_DIR$/out/test/KotlinIcon" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/resources" type="java-resource" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
26 changes: 26 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<idea-plugin>
<id>nl.rubensten.kotlinicon</id>
<name>Kotlin Icon</name>
<version>1.1</version>
<idea-version since-build="141.0"/>
<vendor url="http://ruben-sten.github.io">Ruben-Sten</vendor>

<description><![CDATA[
Adds a nice icon to global kotlin files. Because now it's ugly.
]]></description>

<change-notes><![CDATA[
Please check out our other plugin, TeXiFy-IDEA!
]]>
</change-notes>


<extensions defaultExtensionNs="com.intellij">
<projectViewNodeDecorator implementation="nl.rubensten.kotlinicon.KotlinIconDecorator"/>
<fileIconProvider implementation="nl.rubensten.kotlinicon.KotlinIconDecorator"/>
<iconProvider implementation="nl.rubensten.kotlinicon.KotlinIconDecorator"/>
</extensions>

<actions>
</actions>
</idea-plugin>
Binary file added resources/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions src/nl/rubensten/kotlinicon/KotlinFiles.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package nl.rubensten.kotlinicon

import com.intellij.psi.PsiFile

val PsiFile.hasTopLevelCallables: Boolean
get() {
val hasTopLevelCallablesField = javaClass.getDeclaredField("hasTopLevelCallables")
hasTopLevelCallablesField.isAccessible = true
return hasTopLevelCallablesField.get(this) == true
}
60 changes: 60 additions & 0 deletions src/nl/rubensten/kotlinicon/KotlinIconDecorator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package nl.rubensten.kotlinicon

import com.intellij.ide.FileIconProvider
import com.intellij.ide.IconProvider
import com.intellij.ide.projectView.PresentationData
import com.intellij.ide.projectView.ProjectViewNode
import com.intellij.ide.projectView.ProjectViewNodeDecorator
import com.intellij.openapi.project.Project
import com.intellij.openapi.util.IconLoader
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.packageDependencies.ui.PackageDependenciesNode
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiFile
import com.intellij.ui.ColoredTreeCellRenderer
import javax.swing.Icon

/**
* @author Ruben Schellekens
*/
class KotlinIconDecorator : IconProvider(), ProjectViewNodeDecorator, FileIconProvider {

companion object {
val KOTLIN_ICON = IconLoader.getIcon("/icon.png")
}

override fun getIcon(element: PsiElement, flags: Int): Icon? {
if (element is PsiFile && element.name.endsWith(".kt") && element.hasTopLevelCallables) {
return KOTLIN_ICON
}

return null
}

override fun decorate(node: ProjectViewNode<*>?, presentation: PresentationData?) {
val file = node?.virtualFile ?: return
if (file.isDirectory) {
return
}

val extension: String = file.extension ?: return
when (extension) {
"kt" -> {
presentation?.setIcon(KOTLIN_ICON)
presentation?.presentableText = file.nameWithoutExtension
}
}
}

override fun decorate(node: PackageDependenciesNode?, cellRenderer: ColoredTreeCellRenderer?) {
// Do nothing.
}

override fun getIcon(file: VirtualFile, flags: Int, project: Project?): Icon? {
if (file.extension == "kt") {
return KOTLIN_ICON
}

return null
}
}

0 comments on commit 10fa96b

Please sign in to comment.