用途:本资料是 IntelliJ 平台(jetbrains/intellij-community)中实现或修改 AnAction 动作及其注册的指南,面向需要为 IDE 插件添加动作的开发者。
主要能力与最佳实践:
- 不要在动作构造函数中实例化 Presentation,应使用无参构造函数。
- 在 plugin.xml 中定义 text、description 和 icon,而不是写在构造函数参数里。
- 使用 AnActionEvent#getCoroutineScope 启动挂起计算;actionPerformed 会随事件同步执行,可能冻结 IDE。
注册约定:在 plugin.xml 中为动作设置 id 属性;如需图标可选设置 icon 属性;在消息包(如 GitBundle.properties)中设置 text 和 description,格式为 action.<action-id>.text=Translated Action Text 与 action.<action-id>.description=Translated Action Description。
示例:Kotlin 中 class MyAction : AnAction();plugin.xml 中 <action id="My.Action.Id" class="my.package.MyAction" icon="my.package.MyIcons.ICON"/>;Bundle.properties 中 action.My.Action.Id.text=My Action 与 action.My.Action.Id.description=Description of my action。
限制:资料未提供收费、价格、平台支持范围或具体使用步骤等更多信息。