Skip to content
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

Add Makefile location next to its name in files tree #867

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
41 changes: 41 additions & 0 deletions makefile/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
fun properties(key: String) = project.findProperty(key).toString()

plugins {
// Java support
id("java")
// Kotlin support
id("org.jetbrains.kotlin.jvm") version "1.6.20"
// gradle-intellij-plugin - read more: https://github.com/JetBrains/gradle-intellij-plugin
id("org.jetbrains.intellij") version "1.5.2"
// gradle-grammar-kit-plugin - read more: https://github.com/JetBrains/gradle-grammar-kit-plugin
id("org.jetbrains.grammarkit") version "2021.2.2"
}

group = properties("pluginGroup")
version = properties("pluginVersion")

sourceSets["main"].java.srcDirs("src", "gen")
sourceSets["main"].resources.srcDir("resources")
sourceSets["test"].java.srcDirs("test")

// Configure project's dependencies
repositories {
mavenCentral()
}

dependencies {
implementation(kotlin("stdlib-jdk8"))
}

// Configure gradle-intellij-plugin plugin.
// Read more: https://github.com/JetBrains/gradle-intellij-plugin
intellij {
pluginName.set(properties("pluginName"))
version.set(properties("platformVersion"))
type.set(properties("platformType"))
downloadSources.set(properties("platformDownloadSources").toBoolean())
updateSinceUntilBuild.set(true)

// Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
}
22 changes: 22 additions & 0 deletions makefile/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# IntelliJ Platform Artifacts Repositories
# -> https://www.jetbrains.org/intellij/sdk/docs/reference_guide/intellij_artifacts.html

pluginGroup = org.jetbrains
pluginName = Makefile
pluginVersion = 1.0-SNAPSHOT
pluginSinceBuild = 212
pluginUntilBuild = 221.*
# Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
# See https://jb.gg/intellij-platform-builds-list for available build versions
pluginVerifierIdeVersions = 2022.1

platformType = IC
platformVersion = 2022.1
platformDownloadSources = true
# Plugin Dependencies -> https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_dependencies.html
# Example: platformPlugins = com.intellij.java, com.jetbrains.php:203.4449.22
platformPlugins = terminal

# Opt-out flag for bundling Kotlin standard library.
# See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for details.
kotlin.stdlib.default.dependency = false
Binary file added makefile/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions makefile/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 1 addition & 0 deletions makefile/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "makefile"
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ import javax.swing.*
class MakefileCellRenderer : ColoredTreeCellRenderer() {
override fun customizeCellRenderer(tree: JTree, value: Any, selected: Boolean, expanded: Boolean, leaf: Boolean, row: Int, hasFocus: Boolean) {
value as MakefileTreeNode
icon = value.icon
if (value is MakefileTargetNode && value.target.isSpecialTarget) {
append(value.name, SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES)
} else {
append(value.name)
}
value.render(this)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.jetbrains.lang.makefile.toolWindow

import com.intellij.psi.*
import com.intellij.ui.ColoredTreeCellRenderer
import com.intellij.ui.SimpleTextAttributes
import icons.MakefileIcons
import java.util.*
import java.util.Collections.*
Expand Down Expand Up @@ -32,4 +34,9 @@ class MakefileFileNode(val psiFile: PsiFile, private val targets: List<MakefileT
override fun getIndex(node: TreeNode) = targets.indexOf(node)

override fun getAllowsChildren() = true

override fun renderName(renderer: ColoredTreeCellRenderer) {
super.renderName(renderer)
renderer.append(" ${psiFile.virtualFile.path}", SimpleTextAttributes.GRAYED_ITALIC_ATTRIBUTES, false)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to make this fragment right-aligned? I tried different values for padding of this and filename fragments together with alignment = RIGHT - no effect.

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.jetbrains.lang.makefile.toolWindow

import com.intellij.ui.ColoredTreeCellRenderer
import com.intellij.ui.SimpleTextAttributes
import com.jetbrains.lang.makefile.*
import com.jetbrains.lang.makefile.psi.*
import java.util.*
Expand All @@ -25,4 +27,12 @@ class MakefileTargetNode(val target: MakefileTarget) : MakefileTreeNode(target.n
override fun getIndex(node: TreeNode) = 0

override fun getAllowsChildren() = false

override fun renderName(renderer: ColoredTreeCellRenderer) {
if (target.isSpecialTarget) {
renderer.append(name, SimpleTextAttributes.REGULAR_ITALIC_ATTRIBUTES)
} else {
super.renderName(renderer)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.jetbrains.lang.makefile.toolWindow

import com.intellij.openapi.util.NlsSafe
import com.intellij.ui.ColoredTreeCellRenderer
import com.intellij.ui.SimpleTextAttributes
import javax.swing.*
import javax.swing.tree.*

Expand All @@ -9,4 +11,17 @@ abstract class MakefileTreeNode(@NlsSafe val name: String) : TreeNode {
object Comparator : kotlin.Comparator<MakefileTreeNode> {
override fun compare(a: MakefileTreeNode, b: MakefileTreeNode): Int = a.name.compareTo(b.name, ignoreCase = true)
}

protected open fun renderIcon(renderer: ColoredTreeCellRenderer) {
renderer.icon = this.icon
}

protected open fun renderName(renderer: ColoredTreeCellRenderer) {
renderer.append(name, SimpleTextAttributes.REGULAR_ATTRIBUTES, true/*, name.length + 10, SwingConstants.LEFT*/)
fan-tom marked this conversation as resolved.
Show resolved Hide resolved
}

open fun render(renderer: ColoredTreeCellRenderer) {
renderIcon(renderer)
renderName(renderer)
}
}
10 changes: 9 additions & 1 deletion makefile/test/com/jetbrains/lang/makefile/MakefileTestUtils.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.jetbrains.lang.makefile

import com.intellij.openapi.application.PathManager
import java.io.File

/**
* Test data directory
*/
internal val BASE_TEST_DATA_PATH: String = PathManager.getHomePath() + "/contrib/makefile/testData"
internal val BASE_TEST_DATA_PATH: String = findTestDataPath()

private fun findTestDataPath(): String {
val f = File("testData")
return if (f.exists()) {
f.absolutePath
} else PathManager.getHomePath() + "/contrib/makefile/testData"
}