generated from JetBrains/intellij-platform-plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Lang.kt
56 lines (47 loc) 路 2.01 KB
/
Lang.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package com.github.pushpavel.autocp.build
import com.github.pushpavel.autocp.common.res.R
import com.github.pushpavel.autocp.common.ui.swing.TileCellRenderer
import com.intellij.openapi.fileTypes.FileTypeManager
import com.intellij.openapi.fileTypes.LanguageFileType
import com.intellij.openapi.project.Project
import java.nio.file.Paths
import kotlin.io.path.Path
import kotlin.io.path.pathString
data class Lang(
val extension: String,
val buildCommand: String?,
val executeCommand: String,
val isDefault: Boolean,
) {
fun constructBuildCommand(project: Project, inputPath: String, dirPath: String): String {
if (buildCommand == null) return "internal error"
return constructCommand(project, buildCommand, inputPath, dirPath)
}
fun constructExecuteCommand(project: Project, inputPath: String, dirPath: String): String {
return constructCommand(project, executeCommand, inputPath, dirPath)
}
private fun constructCommand(project: Project, command: String, inputPath: String, dirPath: String): String {
val relPath = Path(inputPath)
val path = Paths.get(Path(project.basePath!!).pathString, relPath.pathString)
return command.replace(R.keys.inputPathMacro, "\"${path.pathString}\"")
.replace(R.keys.dirUnquotedPathMacro, dirPath)
.replace(R.keys.dirPathMacro, "\"$dirPath\"")
}
companion object {
fun cellRenderer(emptyText: String = "None"): TileCellRenderer<Lang> {
return TileCellRenderer(emptyText = emptyText) {
FileTypeManager.getInstance().getFileTypeByExtension(it.extension).let { ft ->
text = if (ft is LanguageFileType)
ft.language.displayName + " (${it.extension})"
else
ft.displayName + " (${it.extension})"
icon = ft.icon
}
}
}
}
}
data class DefaultLangData(
val extension: String,
val commands: List<Pair<String?, String>>
)