Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the development method of the IDEA plug-in

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly explains "what is the development method of the IDEA plug-in". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "what is the development method of the IDEA plug-in".

Recently I found an interesting project in the IDEA plug-in, StopCoding stop coding, the idea is very simple. Today, with the help of this project and the relevant development experience of EOS plug-ins, I will introduce you to the relevant operations of IDEA plug-in development.

IntelliJDEA and intelliJ Platform

IntelliJ IDEA, referred to as IDEA, is a JAVA development tool of Jetbrains, which supports the development of Java, Scala, Groovy and other languages. at the same time, it supports the current mainstream technologies and frameworks, and is good at the development of enterprise applications, mobile applications and Web applications. Intelligent code assistant, code auto-hint, refactoring, J2EE support, various version tools (git, svn, etc.), JUnit, CVS integration, code analysis, innovative GUI design, etc.

IntelliJ Platform is an open source platform for building IDE. The IDE built on it includes IntelliJ IDEA, WebStorm, DataGrip, Android Studio, and so on. IDEA plug-ins are also developed based on IntelliJ Platform.

Construction of development environment

Official development document IntelliJ Platform SDK:

Https://plugins.jetbrains.com/docs/intellij/welcome.html

The development tool uses Intellij IDEA, download address:

Https://www.jetbrains.com/idea/

There are two versions of IDEA:

Community version (Community): completely free, open source code, but lacks some advanced features in the flagship version.

Flagship version (Ultimate): free for 30 days, supports all functions, and does not open source code.

The community version of the plug-in for developing IDEA is recommended because it is open source and you can debug the source code when developing the plug-in.

Develop a simple plug-in

The official documentation guide gives two ways to develop:

Gradle

DevKit

New project in 1.Gradle mode

The new project catalogue is as follows:

1 my_gradle_plugin 2 ├── build.gradle 3 ├── gradle 4 │ └── wrapper 5 │ ├── gradle-wrapper.jar 6 │ └── gradle-wrapper.properties 7 ├── gradlew 8 ├── gradlew.bat 9 ├── settings.gradle10 └── src11 ├── main12 │ ├── java13 │ └── resources14 │ └── META-INF15 plugin.xml16 test17 java18 resources

The root directory build.gradle configuration is as follows:

1plugins {2 id 'java' 3 id' org.jetbrains.intellij' version '0.6.5' 4} 5 6group' com.your.company' 7version '1.0' 8sourceCompatibility = 1.8 910repositories {11 mavenCentral () 12} 13dependencies {14 testImplementation group:' junit', name: 'junit' Version: '4.12: 15} 1617 https://github.com/JetBrains/gradle-intellij-plugin/18intellij / See https://github.com/JetBrains/gradle-intellij-plugin/18intellij {19 version' 2020.1: 20} 21patchPluginXml {22 changeNotes "" 23 Add change notes here.24 most HTML tags may be usedem > "" 25}

Gradle type project Running method:

It is recommended to use gradle to develop plug-ins. Gradle requires less on the local environment and does not need to configure complex sdk and other related content.

2.DevKit development mode

Enable Plugin DevKit

Plugin DevKit is a plug-in for IntelliJ that uses IntelliJ IDEA's own build system to support the development of IDEA plug-ins. You need to install and enable Plugin DevKit before developing the IDEA plug-in.

Open IDEA and navigate to Settings | Plugins. If there is no Plugin DevKit in the plug-in list, click Install JetBrains plugin, search and install.

Configure IntelliJ Platform Plugin SDK

Navigate to File | Project Structure and select SDKs under Platform Settings in the left sidebar of the dialog box.

Click the + button, first select JDK, specify the path of JDK, then create IntelliJ Platform Plugin SDK, and specify home path as the installation path of IDEA, as shown below:

In this example, a simple action is added to the official action as an example. The original address is as follows:

Https://plugins.jetbrains.com/docs/intellij/working-with-custom-actions.html#developing-the-anaction-methods

1. Define action

Define a Java class, inherit the AnAction class, and override the actionPerformed method, such as:

1 public class PopupDialogAction extends AnAction {2 @ Override3 public void actionPerformed (@ NotNull AnActionEvent event) {4 StringBuffer dlgMsg / Using the event, create and show a dialog5 Project currentProject = event.getProject (); 6 StringBuffer dlgMsg = new StringBuffer (event.getPresentation (). GetText () + "Selected!"); 7 String dlgTitle = event.getPresentation (). GetDescription (); 8 / / If an element is selected in the editor, add info about it.9 Navigatable nav = event.getData** (* * CommonDataKeys.NAVIGATABLE) 10 if (nav! = null) {11 dlgMsg.append (String.format ("nSelected Element:% s", nav.toString (); 12} 13 Messages.showMessageDialog (currentProject, dlgMsg.toString (), dlgTitle, Messages.getInformationIcon ()); 14} 15}

2. Register Action

Register within the element of the plugin.xml file.

1 id= "org.intellij.sdk.action.PopupDialogAction" class= "org.intellij.sdk.action.PopupDialogAction" 2 text= "Action Basics Plugin: Pop DialogAction" description= "SDK action example" icon= "SdkIcons.Sdk_default_icon" > 34 text place= "MainMenu" text= "Pop DialogAction" / > 56 first-keystroke= "control alt A" second-keystroke= "C" keymap= "$default" / > 7 8 keystroke= "control button3 doubleClick" keymap= "$default" / > 910 to-group group-id= "ToolsMenu" anchor= "first" / > 1112

The above example defines a first location that is added to the IDEA tools menu (anchor= "first") and adds the "Pop Dialog Action" menu, which will pop up a "Action Basics Plugin: Pop Dialog Action Selected!" Item, as shown below:

Click on the "Pop Dialog Action" item and a dialog box prompts you for a name.

StopCoding principle and Source Code Analysis

Open source address:

Https://github.com/jogeen/StopCoding.git

Step1. Then tools- > StopCoding in the menu bar.

Step2. Set the parameters that suit you and save them.

Step3. Happy Coding, you don't have to worry about being addicted to it anymore. When the working hours are over, the following box will pop up to remind you. Of course, this box cannot be closed. It will shut down automatically only if you have enough time to rest.

Engineering structure analysis:

1. 2 ├── image 3 │ ├── step1.png 4 │ ├── step2.png 5 │ ├── step3.png 6 │ └── step.gif 7 ├── LICENSE 8 ├── readme.md 9 ├── readme_ZH.md10 ├── resources11 │ ├── img12 │ │ └── stop.png13 │ META-INF14 pluginIcon_dark.svg15 ─ pluginIcon.svg16 │ └── plugin.xml17 ├── src18 │ └── icu19 │ └── jogeen20 │ └── stopcoding21 │ ├── data22 │ │ ├── DataCenter.java23 │ │ └── SettingData.java24 │ service25 └── TimerService.java26 │ ├── StopCodingSettingAction.java27 │ ├── task28 │ │ ├── RestTask.java29 │ │ └── WorkTask.java30 │ └── ui31 │ ├── SettingDialog.form32 │ ├── SettingDialog.java33 │ ├── TipsDialog.form34 │ └── TipsDialog.java35 └── StopCoding.iml

As can be seen in the above figure, the project structure is very simple and is developed based on devkit mode.

Data package SettingData. The configuration information corresponds to model. DataCenter, as the data center of the runtime, are static global variables.

Service TimerService this timing calculation of the core code.

Scheduled tasks during the task RestTask break. Scheduled tasks while WorkTask is working.

Dialog box for ui SettingDialog settings information. The dialog box that TipsDialog reminds you when you take a break. StopCodingSettingAction starts the action of the portal.

Plugin.xml this is the core configuration file of the plug-in project. Detailed comments have been added to each item. If you have any questions, you can leave a message on the official account. Let's discuss it together.

12 4 icu.jogeen.StopCoding.id 5 6 7 StopCoding 8 910 1.2.111 1213 jogeen1415 1617 This is a work timer.It can set every working period to remind you that it's time to have a rest, drink some water and exercise your body.19 Only in this way can you really work healthily

20 21 In the tools menu bar, open stopcoding.22 Set working hours and rest time, and save them.23 When the set time comes, there will be a pop-up box to remind you to rest, so that you can not operate idea temporarily.24 25 26

If you are often addicted to writing code and forget to get up for a break and drink water, try this plug-in

27 28 in the Tools in the menu bar, open the StopCoding plug-in to set the working time and rest time 29, and save 30 when the set time is up, there will be a pop-up box to remind you to rest, so that you can not operate idea31 32 for the time being

Project address: https://github.com/jogeen/StopCoding

33] > 3435 37 39 V1.2 add icon (Thanks for the icon provided by my good friend Hu Wei). 40 V1.1 update Guide to use.41 V1.0 release.42 43] > 44 4546 47 48 49 com.intellij.modules.lang505152 53 5455 58 59 61 62 63 64 6566

As you can see from public.xml, this plug-in is relatively simple, with only one StopCoding_setting_id configuration item, and so is the entry class.

Icu.jogeen.stopcoding.StopCodingSettingAction

1 public class StopCodingSettingAction extends AnAction {23 @ Override4 public void actionPerformed (AnActionEvent e) {5 SettingDialog settingDialog = new SettingDialog (); 6 settingDialog.setVisible (true); 7} 8}

The source code only shows SettingDialog and draws a visual interface based on Swing.

Icu.jogeen.stopcoding.ui.SettingDialog

1 move / bind determine button event 2 buttonOK.addActionListener (new ActionListener () {3 public void actionPerformed (ActionEvent e) {4 onOK (); 5} 6}); 7 / bind cancel button event 8 buttonCancel.addActionListener (new ActionListener () {9 public void actionPerformed (ActionEvent e) {10 onCancel (); 11} 12})) 13 / / bind close button event 14 setDefaultCloseOperation (DO_NOTHING_ON_CLOSE); 15 addWindowListener (new WindowAdapter () {16 public void windowClosing (WindowEvent e) {17 onCancel (); 18} 19}); 20 contentPane.registerKeyboardAction (new ActionListener () {21 public void actionPerformed (ActionEvent e) {22 onCancel () 23} 24}, KeyStroke.getKeyStroke (KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); 25 / bind enable select button time 26 openRbtn.addChangeListener (new ChangeListener () {27 @ Override28 public void stateChanged (ChangeEvent e) {29 openRbtn.setText (openRbtn.isSelected ()? "Running": "Stopped"); 30} 31})

The main idea of listening for events in SettingDialog is to schedule to add a scheduled task and to use cancel to cancel the task stop timer. Then a dialog pops up to prevent persistent coding.

Thank you for reading, the above is the content of "what is the development method of IDEA plug-in". After the study of this article, I believe you have a deeper understanding of what the development method of IDEA plug-in is, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 273

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report