SlideShare a Scribd company logo
1 of 29
IntelliJ IDEA
PLUGIN DEVELOPMENT
Plugin Components
Components are the fundamental concept of plugin
integration. There are three kinds of components:
 Application-level
 Project-level
 Module-level
Plugin Extensions and Extension Points
The IntelliJ Platform provides the concept of extensions
and extension points that allows a plugin to interact
with other plugins or with the IDE itself.
Plugin Services
A service is a plugin component loaded on demand.
IntelliJ Platform ensures that only one instance of a
service is loaded even though the service is called
several times.
Plugin Actions
Intellij IDEA provides the concept of actions. An action
is a class, derived from the AnAction class, whose
actionPerformed method is called when the menu item
or toolbar button is selected.
Plugin Content
.IntelliJIDEAx0
plugins
sample.jar/
com/foo/.....
...
...
META-INF
plugin.xml
Android Styler plugin development
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/stub"
android:textColor="@android:color/black"/>
</LinearLayout>
styles.xml
<style name="TextStub">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item>
<item name="android:textColor">@android:color/black</item>
</style>
Default solution
Extract style
Usage
 copy lines with future style from your layout.xml file
 paste it to styles.xml file with Ctrl+Shift+D
 enter name of new style in the modal window
 your style is prepared!
Plan
 Prepare environment
 Create project and implement functionality
 Build jar and upload it into Plugin Repository
Preparations
 Install IntellijIDEA Community Edition
 Download sources of IntellijIDEA Community Edition
(optional)
Create project
plugin.xml
<idea-plugin version="2">
<!-- … -->
<depends>com.intellij.modules.lang</depends>
<!-- … -->
<actions>
<!-- Add your actions here -->
<action id="3421" class="pro.alex_zaitsev.androidstyler.PasteAction" text="Paste Style"
description="Paste Style">
<add-to-group group-id="EditorPopupMenu" anchor="after" relative-to-action="PasteMultiple"/>
<add-to-group group-id="ConsoleView.PopupMenu" anchor="after" relative-to-action="ConsoleView.Copy"/>
<add-to-group group-id="EditorActions" anchor="first"/>
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift D"/>
</action>
</actions>
</idea-plugin>
<depends> tag
<depends>com.intellij.modules.lang</depends>
<actions> tag
<actions>
<!-- Add your actions here -->
<action id="3421" class="pro.alex_zaitsev.androidstyler.PasteAction" text="Paste Style"
description="Paste Style">
<add-to-group group-id="EditorPopupMenu" anchor="after" relative-to-action="PasteMultiple"/>
<add-to-group group-id="ConsoleView.PopupMenu" anchor="after" relative-to-action="ConsoleView.Copy"/>
<add-to-group group-id="EditorActions" anchor="first"/>
<keyboard-shortcut keymap="$default" first-keystroke="ctrl shift D"/>
</action>
</actions>
PasteAction
public class PasteAction extends EditorAction {
public PasteAction(EditorActionHandler defaultHandler) {
super(defaultHandler);
}
public PasteAction() {
this(new StylePasteHandler());
}
private static class StylePasteHandler extends EditorWriteActionHandler {
private StylePasteHandler() {
}
@Override
public void executeWriteAction(Editor editor, DataContext dataContext) {
// implementation
}
}
}
Implementation
Get text from buffer using
CopyPasteManager
private String getCopiedText() {
try {
return (String) CopyPasteManager.getInstance().getContents().getTransferData(DataFlavor.stringFlavor);
} catch (NullPointerException | IOException | UnsupportedFlavorException e) {
e.printStackTrace();
}
return null;
}
Get new style name
private String getStyleName() {
return (String) JOptionPane.showInputDialog(
new JFrame(), Consts.DIALOG_NAME_CONTENT,
Consts.DIALOG_NAME_TITLE,
JOptionPane.PLAIN_MESSAGE,
null,
null, "");
}
Delete selected text
private void deleteSelectedText(Editor editor, Document document) {
SelectionModel selectionModel = editor.getSelectionModel();
document.deleteString(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd());
}
Insert result, move caret and scroll
CaretModel caretModel = editor.getCaretModel();
// insert new string into the document
document.insertString(caretModel.getOffset(), output);
// move caret to the end of inserted text
caretModel.moveToOffset(caretModel.getOffset() + output.length());
// scroll to the end of inserted text
editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
Publish
Build jar
Upload to JetBrains Plugin Repository
https://plugins.jetbrains.com/
Wait for approve (up to 3 work days)
Share
Have a good plugin development!

More Related Content

What's hot

Automating with selenium2
Automating with selenium2Automating with selenium2
Automating with selenium2mindqqa
 
Selenium ide1
Selenium ide1Selenium ide1
Selenium ide1mindqqa
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using seleniummindqqa
 
I/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidI/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidSittiphol Phanvilai
 
Android Life Cycle
Android Life CycleAndroid Life Cycle
Android Life Cyclemssaman
 
What's new in Android P @ I/O Extended Bangkok 2018
What's new in Android P @ I/O Extended Bangkok 2018What's new in Android P @ I/O Extended Bangkok 2018
What's new in Android P @ I/O Extended Bangkok 2018Somkiat Khitwongwattana
 
Training Session 2
Training Session 2 Training Session 2
Training Session 2 Vivek Bhusal
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17Vivek chan
 
Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgetsPrajyot Mainkar
 
UI5con 2017 - Create your own UI5 controls – what’s coming up
UI5con 2017 - Create your own UI5 controls – what’s coming upUI5con 2017 - Create your own UI5 controls – what’s coming up
UI5con 2017 - Create your own UI5 controls – what’s coming upAndreas Kunz
 
Java applet basics
Java applet basicsJava applet basics
Java applet basicsSunil Pandey
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfacesC.o. Nieto
 

What's hot (20)

Automating with selenium2
Automating with selenium2Automating with selenium2
Automating with selenium2
 
Selenium ide1
Selenium ide1Selenium ide1
Selenium ide1
 
Installing the java sdk
Installing the java sdkInstalling the java sdk
Installing the java sdk
 
Test automation using selenium
Test automation using seleniumTest automation using selenium
Test automation using selenium
 
Android Basic Components
Android Basic ComponentsAndroid Basic Components
Android Basic Components
 
I/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in AndroidI/O Rewind 215: What's new in Android
I/O Rewind 215: What's new in Android
 
Android Life Cycle
Android Life CycleAndroid Life Cycle
Android Life Cycle
 
What's new in Android P @ I/O Extended Bangkok 2018
What's new in Android P @ I/O Extended Bangkok 2018What's new in Android P @ I/O Extended Bangkok 2018
What's new in Android P @ I/O Extended Bangkok 2018
 
Applet
 Applet Applet
Applet
 
Android Basics
Android BasicsAndroid Basics
Android Basics
 
Training Session 2
Training Session 2 Training Session 2
Training Session 2
 
Java Applet
Java AppletJava Applet
Java Applet
 
Hierarchy viewer
Hierarchy viewerHierarchy viewer
Hierarchy viewer
 
12 asp.net session17
12 asp.net session1712 asp.net session17
12 asp.net session17
 
Ch2 first app
Ch2 first appCh2 first app
Ch2 first app
 
Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgets
 
UI5con 2017 - Create your own UI5 controls – what’s coming up
UI5con 2017 - Create your own UI5 controls – what’s coming upUI5con 2017 - Create your own UI5 controls – what’s coming up
UI5con 2017 - Create your own UI5 controls – what’s coming up
 
Android layouts
Android layoutsAndroid layouts
Android layouts
 
Java applet basics
Java applet basicsJava applet basics
Java applet basics
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfaces
 

Viewers also liked

Geologia y minas(1)
Geologia y minas(1)Geologia y minas(1)
Geologia y minas(1)pantene1
 
PhoneGap - Now and the Future
PhoneGap - Now and the FuturePhoneGap - Now and the Future
PhoneGap - Now and the FutureTim Kim
 
Womensecurityapp12
Womensecurityapp12Womensecurityapp12
Womensecurityapp12Aman Raj
 
Mobile Cross Platform Development - AIR - PhoneGap - Hybrid vs Native
Mobile Cross Platform Development - AIR - PhoneGap - Hybrid vs NativeMobile Cross Platform Development - AIR - PhoneGap - Hybrid vs Native
Mobile Cross Platform Development - AIR - PhoneGap - Hybrid vs NativeLaurent Jayr
 
Artisan Project (design for 'Lions in Four' brand)
Artisan Project (design for 'Lions in Four' brand)Artisan Project (design for 'Lions in Four' brand)
Artisan Project (design for 'Lions in Four' brand)Sarif Patwary, Ph.D.
 
Australia's cultural legacy
Australia's cultural legacyAustralia's cultural legacy
Australia's cultural legacyLe Suong
 

Viewers also liked (15)

Geologia y minas(1)
Geologia y minas(1)Geologia y minas(1)
Geologia y minas(1)
 
PhoneGap - Now and the Future
PhoneGap - Now and the FuturePhoneGap - Now and the Future
PhoneGap - Now and the Future
 
Womensecurityapp12
Womensecurityapp12Womensecurityapp12
Womensecurityapp12
 
Mobile Cross Platform Development - AIR - PhoneGap - Hybrid vs Native
Mobile Cross Platform Development - AIR - PhoneGap - Hybrid vs NativeMobile Cross Platform Development - AIR - PhoneGap - Hybrid vs Native
Mobile Cross Platform Development - AIR - PhoneGap - Hybrid vs Native
 
Hybrid App Development using PhoneGap/Cordova
Hybrid App Development using PhoneGap/CordovaHybrid App Development using PhoneGap/Cordova
Hybrid App Development using PhoneGap/Cordova
 
From Idea to App Store
From Idea to App StoreFrom Idea to App Store
From Idea to App Store
 
Kinesics
KinesicsKinesics
Kinesics
 
Artisan Project (design for 'Lions in Four' brand)
Artisan Project (design for 'Lions in Four' brand)Artisan Project (design for 'Lions in Four' brand)
Artisan Project (design for 'Lions in Four' brand)
 
NOV2015
NOV2015NOV2015
NOV2015
 
CV Lukas 20161216
CV Lukas 20161216CV Lukas 20161216
CV Lukas 20161216
 
Coping with Stress
Coping with StressCoping with Stress
Coping with Stress
 
Australia's cultural legacy
Australia's cultural legacyAustralia's cultural legacy
Australia's cultural legacy
 
Sarfraz CV Standard
Sarfraz CV StandardSarfraz CV Standard
Sarfraz CV Standard
 
Prueba 2
Prueba 2Prueba 2
Prueba 2
 
Digital_Realty_-_Deep_Value_Case_Study
Digital_Realty_-_Deep_Value_Case_StudyDigital_Realty_-_Deep_Value_Case_Study
Digital_Realty_-_Deep_Value_Case_Study
 

Similar to IntelliJ IDEA Plugin Development

Android apps development
Android apps developmentAndroid apps development
Android apps developmentMonir Zzaman
 
Creation of simple application using - step by step
Creation of simple application using - step by stepCreation of simple application using - step by step
Creation of simple application using - step by steppriya Nithya
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivitiesmaamir farooq
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activitiesmaamir farooq
 
ElggCamp Santiago> For Developers!
ElggCamp Santiago> For Developers!ElggCamp Santiago> For Developers!
ElggCamp Santiago> For Developers!Condiminds
 
ElggCamp Santiago - Dev Edition
ElggCamp Santiago - Dev EditionElggCamp Santiago - Dev Edition
ElggCamp Santiago - Dev EditionBrett Profitt
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Ontico
 
Take Your XPages Development to the Next Level
Take Your XPages Development to the Next LevelTake Your XPages Development to the Next Level
Take Your XPages Development to the Next Levelbalassaitis
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycleKumar
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress pluginAnthony Montalbano
 
Lightning Components Workshop
Lightning Components WorkshopLightning Components Workshop
Lightning Components WorkshopGordon Bockus
 
L0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-inL0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-inTonny Madsen
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_programEyad Almasri
 
React.js: You deserve to know about it
React.js: You deserve to know about itReact.js: You deserve to know about it
React.js: You deserve to know about itAnderson Aguiar
 
Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2Vivek Bhusal
 
Handling action bar in Android
Handling action bar in AndroidHandling action bar in Android
Handling action bar in Androidindiangarg
 
Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Oro Inc.
 

Similar to IntelliJ IDEA Plugin Development (20)

Angular2 + rxjs
Angular2 + rxjsAngular2 + rxjs
Angular2 + rxjs
 
Android apps development
Android apps developmentAndroid apps development
Android apps development
 
Creation of simple application using - step by step
Creation of simple application using - step by stepCreation of simple application using - step by step
Creation of simple application using - step by step
 
Leture5 exercise onactivities
Leture5 exercise onactivitiesLeture5 exercise onactivities
Leture5 exercise onactivities
 
Lecture exercise on activities
Lecture exercise on activitiesLecture exercise on activities
Lecture exercise on activities
 
ElggCamp Santiago> For Developers!
ElggCamp Santiago> For Developers!ElggCamp Santiago> For Developers!
ElggCamp Santiago> For Developers!
 
ElggCamp Santiago - Dev Edition
ElggCamp Santiago - Dev EditionElggCamp Santiago - Dev Edition
ElggCamp Santiago - Dev Edition
 
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
Паразитируем на React-экосистеме (Angular 4+) / Алексей Охрименко (IPONWEB)
 
Take Your XPages Development to the Next Level
Take Your XPages Development to the Next LevelTake Your XPages Development to the Next Level
Take Your XPages Development to the Next Level
 
React django
React djangoReact django
React django
 
Android lifecycle
Android lifecycleAndroid lifecycle
Android lifecycle
 
Write your first WordPress plugin
Write your first WordPress pluginWrite your first WordPress plugin
Write your first WordPress plugin
 
Lightning Components Workshop
Lightning Components WorkshopLightning Components Workshop
Lightning Components Workshop
 
L0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-inL0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-in
 
Lec005 android start_program
Lec005 android start_programLec005 android start_program
Lec005 android start_program
 
React.js: You deserve to know about it
React.js: You deserve to know about itReact.js: You deserve to know about it
React.js: You deserve to know about it
 
Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2
 
Magento++
Magento++Magento++
Magento++
 
Handling action bar in Android
Handling action bar in AndroidHandling action bar in Android
Handling action bar in Android
 
Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)Adding custom ui controls to your application (1)
Adding custom ui controls to your application (1)
 

IntelliJ IDEA Plugin Development

  • 2. Plugin Components Components are the fundamental concept of plugin integration. There are three kinds of components:  Application-level  Project-level  Module-level
  • 3. Plugin Extensions and Extension Points The IntelliJ Platform provides the concept of extensions and extension points that allows a plugin to interact with other plugins or with the IDE itself.
  • 4. Plugin Services A service is a plugin component loaded on demand. IntelliJ Platform ensures that only one instance of a service is loaded even though the service is called several times.
  • 5. Plugin Actions Intellij IDEA provides the concept of actions. An action is a class, derived from the AnAction class, whose actionPerformed method is called when the menu item or toolbar button is selected.
  • 7. Android Styler plugin development
  • 8. layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="@string/stub" android:textColor="@android:color/black"/> </LinearLayout>
  • 9. styles.xml <style name="TextStub"> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> <item name="android:layout_gravity">center</item> <item name="android:textColor">@android:color/black</item> </style>
  • 12. Usage  copy lines with future style from your layout.xml file  paste it to styles.xml file with Ctrl+Shift+D  enter name of new style in the modal window  your style is prepared!
  • 13. Plan  Prepare environment  Create project and implement functionality  Build jar and upload it into Plugin Repository
  • 14. Preparations  Install IntellijIDEA Community Edition  Download sources of IntellijIDEA Community Edition (optional)
  • 16. plugin.xml <idea-plugin version="2"> <!-- … --> <depends>com.intellij.modules.lang</depends> <!-- … --> <actions> <!-- Add your actions here --> <action id="3421" class="pro.alex_zaitsev.androidstyler.PasteAction" text="Paste Style" description="Paste Style"> <add-to-group group-id="EditorPopupMenu" anchor="after" relative-to-action="PasteMultiple"/> <add-to-group group-id="ConsoleView.PopupMenu" anchor="after" relative-to-action="ConsoleView.Copy"/> <add-to-group group-id="EditorActions" anchor="first"/> <keyboard-shortcut keymap="$default" first-keystroke="ctrl shift D"/> </action> </actions> </idea-plugin>
  • 18. <actions> tag <actions> <!-- Add your actions here --> <action id="3421" class="pro.alex_zaitsev.androidstyler.PasteAction" text="Paste Style" description="Paste Style"> <add-to-group group-id="EditorPopupMenu" anchor="after" relative-to-action="PasteMultiple"/> <add-to-group group-id="ConsoleView.PopupMenu" anchor="after" relative-to-action="ConsoleView.Copy"/> <add-to-group group-id="EditorActions" anchor="first"/> <keyboard-shortcut keymap="$default" first-keystroke="ctrl shift D"/> </action> </actions>
  • 19. PasteAction public class PasteAction extends EditorAction { public PasteAction(EditorActionHandler defaultHandler) { super(defaultHandler); } public PasteAction() { this(new StylePasteHandler()); } private static class StylePasteHandler extends EditorWriteActionHandler { private StylePasteHandler() { } @Override public void executeWriteAction(Editor editor, DataContext dataContext) { // implementation } } }
  • 21. Get text from buffer using CopyPasteManager private String getCopiedText() { try { return (String) CopyPasteManager.getInstance().getContents().getTransferData(DataFlavor.stringFlavor); } catch (NullPointerException | IOException | UnsupportedFlavorException e) { e.printStackTrace(); } return null; }
  • 22. Get new style name private String getStyleName() { return (String) JOptionPane.showInputDialog( new JFrame(), Consts.DIALOG_NAME_CONTENT, Consts.DIALOG_NAME_TITLE, JOptionPane.PLAIN_MESSAGE, null, null, ""); }
  • 23. Delete selected text private void deleteSelectedText(Editor editor, Document document) { SelectionModel selectionModel = editor.getSelectionModel(); document.deleteString(selectionModel.getSelectionStart(), selectionModel.getSelectionEnd()); }
  • 24. Insert result, move caret and scroll CaretModel caretModel = editor.getCaretModel(); // insert new string into the document document.insertString(caretModel.getOffset(), output); // move caret to the end of inserted text caretModel.moveToOffset(caretModel.getOffset() + output.length()); // scroll to the end of inserted text editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
  • 27. Upload to JetBrains Plugin Repository https://plugins.jetbrains.com/ Wait for approve (up to 3 work days)
  • 28. Share
  • 29. Have a good plugin development!