i am trying to create a right-click menu function. The point is by right-click on a property file it should show a new option in the context menu.
I tried the following code:
plugin.xml:
<idea-plugin>
<!-- Plugin details -->
<id>x.x.intellij.plugin</id>
<name>x Translator Tool</name>
<vendor>x</vendor>
<description>This is a description of your plugin.This is a description of your plugin This is a description of your plugin</description> <!-- Add a valid description here -->
<!-- Dependencies -->
<depends>com.intellij.modules.platform</depends>
<depends>org.jetbrains.compose.intellij.platform</depends>
<depends>org.jetbrains.kotlin</depends>
<actions>
<!-- Add your actions here -->
<action id="x.x.intellij.plugin.actions.TranslateAction"
class="cx.x.intellij.plugin.actions.TranslateAction"
text="Translate This File">
<add-to-group group-id="ProjectViewPopupMenu" anchor="last"/>
</action>
</actions>
<extensions defaultExtensionNs="com.intellij">
</extensions>a
</idea-plugin>
in build.gradle:
import org.jetbrains.changelog.Changelog
import org.jetbrains.changelog.markdownToHTML
fun properties(key: String) = providers.gradleProperty(key)
fun environment(key: String) = providers.environmentVariable(key)
plugins {
id("java") // Java support
alias(libs.plugins.kotlin) // Kotlin support
alias(libs.plugins.gradleIntelliJPlugin) // Gradle IntelliJ Plugin
alias(libs.plugins.changelog) // Gradle Changelog Plugin
alias(libs.plugins.qodana) // Gradle Qodana Plugin
alias(libs.plugins.kover) // Gradle Kover Plugin
}
group = properties("pluginGroup").get()
version = properties("pluginVersion").get()
repositories {
mavenCentral() // from settings.xml
}
kotlin {
jvmToolchain(17)
}
intellij {
pluginName = properties("pluginName")
version = properties("platformVersion")
type = properties("platformType")
plugins = properties("platformPlugins").map { it.split(',').map(String::trim).filter(String::isNotEmpty) }
}
tasks {
wrapper {
gradleVersion = properties("gradleVersion").get()
}
patchPluginXml {
version = properties("pluginVersion")
sinceBuild = properties("pluginSinceBuild")
untilBuild = properties("pluginUntilBuild")
pluginDescription = providers.fileContents(layout.projectDirectory.file("README.md")).asText.map {
val start = "<!-- Plugin description -->"
val end = "<!-- Plugin description end -->"
with (it.lines()) {
if (!containsAll(listOf(start, end))) {
throw GradleException("Plugin description section not found in README.md:\n$start ... $end")
}
subList(indexOf(start) + 1, indexOf(end)).joinToString("\n").let(::markdownToHTML)
}
}
val changelog = project.changelog // local variable for configuration cache compatibility
// Get the latest available change notes from the changelog file
changeNotes = properties("pluginVersion").map { pluginVersion ->
with(changelog) {
renderItem(
(getOrNull(pluginVersion) ?: getUnreleased())
.withHeader(false)
.withEmptySections(false),
Changelog.OutputType.HTML,
)
}
}
}
}
in src/package/TranslateAction:
package x.x.intellij.plugin.actions
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.ui.Messages
class TranslateAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
Messages.showMessageDialog("Translate action executed!", "Translation", Messages.getInformationIcon())
}
override fun update(e: AnActionEvent) {
super.update(e)
// Enable the action only when right-clicking on the file "ResourceBundle"
val file = e.getData(CommonDataKeys.PSI_FILE)
e.presentation.isEnabled = file?.name == "ValidationMessages_de.properties"
}
}