mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-29 17:57:53 +08:00
Add Review
This commit is contained in:
parent
ad74c65a3c
commit
7812e7d651
@ -1,8 +1,13 @@
|
|||||||
|
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'org.jetbrains.intellij' version '0.4.9'
|
id 'org.jetbrains.intellij' version '0.4.10'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group 'org.intellij.sdk'
|
||||||
|
version '2.0.0'
|
||||||
|
|
||||||
sourceCompatibility = 1.8
|
sourceCompatibility = 1.8
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
@ -15,15 +20,11 @@ dependencies {
|
|||||||
|
|
||||||
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||||
intellij {
|
intellij {
|
||||||
|
|
||||||
// Define IntelliJ Platform API version to use for building this plugin
|
|
||||||
version '2019.1'
|
version '2019.1'
|
||||||
|
|
||||||
// Prevents patching <idea-version> attributes in plugin.xml
|
|
||||||
updateSinceUntilBuild = false
|
updateSinceUntilBuild = false
|
||||||
// Define a shared sandbox directory for running code sample plugins within an IDE.
|
}
|
||||||
sandboxDirectory = file("${project.projectDir}/../_idea-sandbox")
|
patchPluginXml {
|
||||||
|
version = project.version
|
||||||
}
|
}
|
||||||
|
|
||||||
// Force javadoc rebuild before jar is built
|
// Force javadoc rebuild before jar is built
|
||||||
|
@ -1,2 +1 @@
|
|||||||
rootProject.name = 'action_basics'
|
rootProject.name = 'action'
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
|
|
||||||
<!-- Compatible with the following versions of IntelliJ Platform:
|
<!-- Compatible with the following versions of IntelliJ Platform:
|
||||||
version 2018.3 (build #183) and newer. -->
|
version 2018.3 (build #183) and newer. -->
|
||||||
<idea-version since-build="183"/>
|
<idea-version since-build="191"/>
|
||||||
|
|
||||||
<!-- Indicate this plugin can be loaded in all IntelliJ Platform-based products. -->
|
<!-- Indicate this plugin can be loaded in all IntelliJ Platform-based products. -->
|
||||||
<depends>com.intellij.modules.lang</depends>
|
<depends>com.intellij.modules.lang</depends>
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'java'
|
id 'java'
|
||||||
id 'org.jetbrains.intellij' version '0.4.9'
|
id 'org.jetbrains.intellij' version '0.4.10'
|
||||||
}
|
}
|
||||||
|
|
||||||
group 'org.intellij.sdk'
|
group 'org.intellij.sdk'
|
||||||
@ -20,7 +20,7 @@ dependencies {
|
|||||||
|
|
||||||
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||||
intellij {
|
intellij {
|
||||||
version '2019.2'
|
version '2019.1'
|
||||||
updateSinceUntilBuild = false
|
updateSinceUntilBuild = false
|
||||||
}
|
}
|
||||||
patchPluginXml {
|
patchPluginXml {
|
||||||
|
@ -6,13 +6,14 @@ import com.intellij.openapi.actionSystem.*;
|
|||||||
import com.intellij.openapi.editor.*;
|
import com.intellij.openapi.editor.*;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.ui.Messages;
|
import com.intellij.openapi.ui.Messages;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If conditions support it, makes a menu visible to display information
|
* If conditions support it, makes a menu visible to display information
|
||||||
* about the caret.
|
* about the caret.
|
||||||
* @author Anna Bulenkova
|
*
|
||||||
* @see com.intellij.openapi.actionSystem.AnAction
|
* @see com.intellij.openapi.actionSystem.AnAction
|
||||||
*/
|
*/
|
||||||
public class EditorAreaIllustration extends AnAction {
|
public class EditorAreaIllustration extends AnAction {
|
||||||
@ -22,32 +23,35 @@ public class EditorAreaIllustration extends AnAction {
|
|||||||
* @param e Event related to this action
|
* @param e Event related to this action
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(AnActionEvent e) {
|
public void actionPerformed(@NotNull final AnActionEvent e) {
|
||||||
// Get access to the editor and caret model. update() validated editor's existence.
|
// Get access to the editor and caret model. update() validated editor's existence.
|
||||||
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
||||||
CaretModel caretModel = editor.getCaretModel();
|
final CaretModel caretModel = editor.getCaretModel();
|
||||||
// Getting the primary caret ensures we get the right one of a possible many.
|
// Getting the primary caret ensures we get the correct one of a possible many.
|
||||||
Caret primaryCaret = caretModel.getPrimaryCaret();
|
final Caret primaryCaret = caretModel.getPrimaryCaret();
|
||||||
|
// Get the caret information
|
||||||
|
LogicalPosition logicalPos = primaryCaret.getLogicalPosition();
|
||||||
|
VisualPosition visualPos = primaryCaret.getVisualPosition();
|
||||||
|
int caretOffset = primaryCaret.getOffset();
|
||||||
// Build and display the caret report.
|
// Build and display the caret report.
|
||||||
StringBuilder report = new StringBuilder();
|
StringBuilder report = new StringBuilder(logicalPos.toString() + "\n");
|
||||||
report.append(primaryCaret.getLogicalPosition().toString() + "\n");
|
report.append(visualPos.toString() + "\n");
|
||||||
report.append(primaryCaret.getVisualPosition().toString() + "\n");
|
report.append("Offset: " + caretOffset);
|
||||||
report.append("Offset: " + primaryCaret.getOffset());
|
|
||||||
Messages.showInfoMessage(report.toString(), "Caret Parameters Inside The Editor");
|
Messages.showInfoMessage(report.toString(), "Caret Parameters Inside The Editor");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets visibility of this action menu item if:
|
* Sets visibility and enables this action menu item if:
|
||||||
* A project is open,
|
* A project is open,
|
||||||
* An editor is active,
|
* An editor is active,
|
||||||
* @param e Event related to this action
|
* @param e Event related to this action
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(AnActionEvent e) {
|
public void update(@NotNull final AnActionEvent e) {
|
||||||
// Get required data keys
|
// Get required data keys
|
||||||
final Project project = e.getProject();
|
final Project project = e.getProject();
|
||||||
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||||
//Set visibility only in case of existing project and editor
|
//Set visibility only in case of existing project and editor
|
||||||
e.getPresentation().setVisible(project != null && editor != null);
|
e.getPresentation().setEnabledAndVisible(project != null && editor != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,14 +10,14 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Menu action to clone a new caret based on an existing one.
|
* Menu action to clone a new caret based on an existing one.
|
||||||
* @author Anna Bulenkova
|
*
|
||||||
* @see com.intellij.openapi.actionSystem.AnAction
|
* @see com.intellij.openapi.actionSystem.AnAction
|
||||||
*/
|
*/
|
||||||
public class EditorHandlerIllustration extends AnAction {
|
public class EditorHandlerIllustration extends AnAction {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This block of static code does not pertain to this class.
|
* This block of static code does not pertain to this class.
|
||||||
* It registers the custom MyTypedHandler, an TypedActionHandler
|
* It registers the custom MyTypedHandler, a TypedActionHandler
|
||||||
* that handles actions activated by typing in the editor.
|
* that handles actions activated by typing in the editor.
|
||||||
* This registration code just needs to appear in a class (like AnAction class)
|
* This registration code just needs to appear in a class (like AnAction class)
|
||||||
* that gets instantiated as part of IntelliJ startup.
|
* that gets instantiated as part of IntelliJ startup.
|
||||||
@ -33,19 +33,19 @@ public class EditorHandlerIllustration extends AnAction {
|
|||||||
* @param e Event related to this action
|
* @param e Event related to this action
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
public void actionPerformed(@NotNull final AnActionEvent e) {
|
||||||
// Editor is known to exist from update, so it's not null
|
// Editor is known to exist from update, so it's not null
|
||||||
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
||||||
// Get the action manager in order to get the necessary action handler...
|
// Get the action manager in order to get the necessary action handler...
|
||||||
EditorActionManager actionManager = EditorActionManager.getInstance();
|
final EditorActionManager actionManager = EditorActionManager.getInstance();
|
||||||
// Get the action handler registered to clone carets
|
// Get the action handler registered to clone carets
|
||||||
EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW);
|
final EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_CLONE_CARET_BELOW);
|
||||||
// Clone one caret below the active caret
|
// Clone one caret below the active caret
|
||||||
actionHandler.execute(editor, editor.getCaretModel().getPrimaryCaret(), e.getDataContext());
|
actionHandler.execute(editor, editor.getCaretModel().getPrimaryCaret(), e.getDataContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets visibility of this action menu item if:
|
* Enables and sets visibility of this action menu item if:
|
||||||
* A project is open,
|
* A project is open,
|
||||||
* An editor is active,
|
* An editor is active,
|
||||||
* At least one caret exists
|
* At least one caret exists
|
||||||
@ -53,15 +53,15 @@ public class EditorHandlerIllustration extends AnAction {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(@NotNull final AnActionEvent e) {
|
public void update(@NotNull final AnActionEvent e) {
|
||||||
boolean visibility = false;
|
|
||||||
//Set visible if at least one caret is available
|
|
||||||
final Project project = e.getProject();
|
final Project project = e.getProject();
|
||||||
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||||
|
// Make sure at least one caret is available
|
||||||
|
boolean menuAllowed = false;
|
||||||
if (editor != null && project != null) {
|
if (editor != null && project != null) {
|
||||||
// Ensure the list of carets in the editor is not empty
|
// Ensure the list of carets in the editor is not empty
|
||||||
visibility = !editor.getCaretModel().getAllCarets().isEmpty();
|
menuAllowed = !editor.getCaretModel().getAllCarets().isEmpty();
|
||||||
}
|
}
|
||||||
e.getPresentation().setVisible(visibility);
|
e.getPresentation().setEnabledAndVisible(menuAllowed);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,20 +7,21 @@ import com.intellij.openapi.command.WriteCommandAction;
|
|||||||
import com.intellij.openapi.editor.*;
|
import com.intellij.openapi.editor.*;
|
||||||
import com.intellij.openapi.editor.actionSystem.*;
|
import com.intellij.openapi.editor.actionSystem.*;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Menu action to replace a selection of characters with a fixed string.
|
* Menu action to replace a selection of characters with a fixed string.
|
||||||
* @author Anna Bulenkova
|
*
|
||||||
* @see com.intellij.openapi.actionSystem.AnAction
|
* @see com.intellij.openapi.actionSystem.AnAction
|
||||||
*/
|
*/
|
||||||
public class EditorIllustration extends AnAction {
|
public class EditorIllustrationAction extends AnAction {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replaces the run of text selected by the primary caret with a fixed string.
|
* Replaces the run of text selected by the primary caret with a fixed string.
|
||||||
* @param e Event related to this action
|
* @param e Event related to this action
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(final AnActionEvent e) {
|
public void actionPerformed(@NotNull final AnActionEvent e) {
|
||||||
// Get all the required data from data keys
|
// Get all the required data from data keys
|
||||||
// Editor and Project were verified in update(), so they are not null.
|
// Editor and Project were verified in update(), so they are not null.
|
||||||
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
||||||
@ -40,18 +41,18 @@ public class EditorIllustration extends AnAction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets visibility of this action menu item if:
|
* Sets visibility and enables this action menu item if:
|
||||||
* A project is open,
|
* A project is open,
|
||||||
* An editor is active,
|
* An editor is active,
|
||||||
* Some characters are selected
|
* Some characters are selected
|
||||||
* @param e Event related to this action
|
* @param e Event related to this action
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void update(final AnActionEvent e) {
|
public void update(@NotNull final AnActionEvent e) {
|
||||||
// Get required data keys
|
// Get required data keys
|
||||||
final Project project = e.getProject();
|
final Project project = e.getProject();
|
||||||
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||||
//Set visibility only in case of existing project and editor and if a selection exists
|
// Set visibility and enable only in case of existing project and editor and if a selection exists
|
||||||
e.getPresentation().setVisible((project != null && editor != null && editor.getSelectionModel().hasSelection()));
|
e.getPresentation().setEnabledAndVisible( project != null && editor != null && editor.getSelectionModel().hasSelection() );
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -15,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
* The execute method inserts a fixed string at Offset 0 of the document.
|
* The execute method inserts a fixed string at Offset 0 of the document.
|
||||||
* Document changes are made in the context of a write action.
|
* Document changes are made in the context of a write action.
|
||||||
* MyTypedHandler is registered by static code in the EditorHandlerIllustration class.
|
* MyTypedHandler is registered by static code in the EditorHandlerIllustration class.
|
||||||
* @author Anna Bulenkova
|
*
|
||||||
* @see com.intellij.openapi.editor.actionSystem.TypedActionHandler
|
* @see com.intellij.openapi.editor.actionSystem.TypedActionHandler
|
||||||
*/
|
*/
|
||||||
class MyTypedHandler implements TypedActionHandler {
|
class MyTypedHandler implements TypedActionHandler {
|
||||||
@ -23,7 +23,7 @@ class MyTypedHandler implements TypedActionHandler {
|
|||||||
public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) {
|
public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) {
|
||||||
// Get the document and project
|
// Get the document and project
|
||||||
final Document document = editor.getDocument();
|
final Document document = editor.getDocument();
|
||||||
Project project = editor.getProject();
|
final Project project = editor.getProject();
|
||||||
// Construct the runnable to substitute the string at offset 0 in the document
|
// Construct the runnable to substitute the string at offset 0 in the document
|
||||||
Runnable runnable = () -> document.insertString(0, "editor_basics\n");
|
Runnable runnable = () -> document.insertString(0, "editor_basics\n");
|
||||||
// Make the document change in the context of a write action.
|
// Make the document change in the context of a write action.
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
<version>2.0.0</version>
|
<version>2.0.0</version>
|
||||||
|
|
||||||
<!-- Compatible with the following versions of IntelliJ Platform -->
|
<!-- Compatible with the following versions of IntelliJ Platform -->
|
||||||
<idea-version since-build="171"/>
|
<idea-version since-build="191"/>
|
||||||
|
|
||||||
<!-- Product and plugin compatibility requirements -->
|
<!-- Product and plugin compatibility requirements -->
|
||||||
<depends>com.intellij.modules.lang</depends>
|
<depends>com.intellij.modules.lang</depends>
|
||||||
@ -36,8 +36,8 @@
|
|||||||
<vendor url="https://plugins.jetbrains.com">IntelliJ Platform SDK</vendor>
|
<vendor url="https://plugins.jetbrains.com">IntelliJ Platform SDK</vendor>
|
||||||
|
|
||||||
<actions>
|
<actions>
|
||||||
<action id="EditorBasics.EditorIllustration"
|
<action id="EditorBasics.EditorIllustrationAction"
|
||||||
class="org.intellij.sdk.editor.EditorIllustration"
|
class="org.intellij.sdk.editor.EditorIllustrationAction"
|
||||||
text="Editor Replace Text"
|
text="Editor Replace Text"
|
||||||
description="Replaces selected text with 'Replacement'."
|
description="Replaces selected text with 'Replacement'."
|
||||||
icon="EditorBasicsIcons.Sdk_default_icon">
|
icon="EditorBasicsIcons.Sdk_default_icon">
|
||||||
|
1
gradle_plugin_demo/settings.gradle
Normal file
1
gradle_plugin_demo/settings.gradle
Normal file
@ -0,0 +1 @@
|
|||||||
|
rootProject.name = 'gradle_demo'
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<depends>com.intellij.modules.lang</depends>
|
<depends>com.intellij.modules.lang</depends>
|
||||||
|
|
||||||
<idea-version since-build="131" until-build="193.*"/>
|
<idea-version since-build="191"/>
|
||||||
<extensions defaultExtensionNs="com.intellij">
|
<extensions defaultExtensionNs="com.intellij">
|
||||||
</extensions>
|
</extensions>
|
||||||
|
|
||||||
|
@ -18,7 +18,7 @@ dependencies {
|
|||||||
|
|
||||||
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||||
intellij {
|
intellij {
|
||||||
version '2017.1'
|
version '2019.1'
|
||||||
updateSinceUntilBuild = false
|
updateSinceUntilBuild = false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
rootProject.name = 'inspection_basics'
|
rootProject.name = 'inspection'
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<version>2.0.0</version>
|
<version>2.0.0</version>
|
||||||
|
|
||||||
<!-- Compatible with the following versions of IntelliJ Platform -->
|
<!-- Compatible with the following versions of IntelliJ Platform -->
|
||||||
<idea-version since-build="171"/>
|
<idea-version since-build="191"/>
|
||||||
|
|
||||||
<!-- Product and plugin compatibility requirements -->
|
<!-- Product and plugin compatibility requirements -->
|
||||||
<depends>com.intellij.modules.lang</depends>
|
<depends>com.intellij.modules.lang</depends>
|
||||||
|
@ -20,9 +20,13 @@ dependencies {
|
|||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sourceSets {
|
||||||
|
main.kotlin.srcDirs += 'src/main/kotlin'
|
||||||
|
}
|
||||||
|
|
||||||
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||||
intellij {
|
intellij {
|
||||||
version '2019.1.3'
|
version '2019.1'
|
||||||
updateSinceUntilBuild = false
|
updateSinceUntilBuild = false
|
||||||
}
|
}
|
||||||
compileKotlin {
|
compileKotlin {
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
rootProject.name = 'kotlin_demo'
|
rootProject.name = 'kotlin'
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
<version>2.0.0</version>
|
<version>2.0.0</version>
|
||||||
|
|
||||||
<!-- Minimum and maximum build numbers of IDEA compatible with the plugin. -->
|
<!-- Minimum and maximum build numbers of IDEA compatible with the plugin. -->
|
||||||
<idea-version since-build="171.0"/>
|
<idea-version since-build="191.0"/>
|
||||||
|
|
||||||
<!-- Product and plugin compatibility requirements -->
|
<!-- Product and plugin compatibility requirements -->
|
||||||
<depends>com.intellij.modules.lang</depends>
|
<depends>com.intellij.modules.lang</depends>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user