时隔很久之后,重新开发一个AS上的脚手架,记录过程
1、下载安装idea ,官网社区版下载
2、新建plugin project
打开 IDE—new Project 选择IntelliJ Platform Plugin,注意 Project SDK的配置
3、根据提示,输入必要信息,一路Next ,完成创建后,生成的项目结构如下图:
4、编写插件
有两种方式
4.1、src文件夹右击创建一个Action。Action是一个处理插件交互行为的类。(未实现,不做过多描述)
4.2、我采用的方式,手动添加对应类:
4.2.1、src文件夹下创建,对应的TestPlugin类
package con.test.plugin
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.project.Project
import com.intellij.openapi.ui.Messages
import com.intellij.openapi.vfs.VirtualFile
class TestPlugin:AnAction("new-plugin") {
var project: Project? = null
var selectGroup: VirtualFile? = null
override fun actionPerformed(e: AnActionEvent) {
project = e.project
val className =
Messages.showInputDialog(project, "please input activity name", "NewMvvmActivity", Messages.getQuestionIcon())
selectGroup = CommonDataKeys.VIRTUAL_FILE.getData(e.dataContext)
if (className == null || className == "") {
print("没有输入类名")
return
}
}
}
4.2.2、编辑plugin.xml
<idea-plugin>
<id>com.your.company.unique.plugin.id</id>
<name>test-new-plugin</name>
<version>5.0</version>
<vendor email="support@yourcompany.com" url="http://www.yourcompany.com">YourCompany</vendor>
<description><![CDATA[
Enter short description for your plugin here.<br>
<em>most HTML tags may be used</em>
]]></description>
<change-notes><![CDATA[
Add change notes here.<br>
<em>most HTML tags may be used</em>
]]>
</change-notes>
<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/build_number_ranges.html for description -->
<idea-version since-build="173.0"/>
<!-- please see https://www.jetbrains.org/intellij/sdk/docs/basics/getting_started/plugin_compatibility.html
on how to target different products -->
<depends>com.intellij.modules.platform</depends>
<extensions defaultExtensionNs="com.intellij">
<!-- Add your extensions here -->
</extensions>
<actions>
<!-- Add your actions here -->
<group id="com.test.plugin.action.id" text="NewPlugin" description="new plugin">
<add-to-group group-id="NewXml" anchor="before" relative-to-action="NewHtmlFile"/>
<action id="NewPlugin.activity.action" class="con.test.plugin.TestPlugin" text="Text _name"
description="new plugin"/>
</group>
</actions>
</idea-plugin>
此时运行 run plugin ,看到如下截图:
点击new-plugin 便会有TestPlugin类内编写的弹窗出现,剩下的便是在此类内编写自己的逻辑了。
参考:
//www.greatytc.com/p/cb3e7c7d694b
https://cloud.tencent.com/developer/article/1780118