mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +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 {
|
||||
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
|
||||
|
||||
repositories {
|
||||
@ -15,15 +20,11 @@ dependencies {
|
||||
|
||||
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||
intellij {
|
||||
|
||||
// Define IntelliJ Platform API version to use for building this plugin
|
||||
version '2019.1'
|
||||
|
||||
// Prevents patching <idea-version> attributes in plugin.xml
|
||||
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
|
||||
|
@ -1,2 +1 @@
|
||||
rootProject.name = 'action_basics'
|
||||
|
||||
rootProject.name = 'action'
|
||||
|
@ -12,7 +12,7 @@
|
||||
|
||||
<!-- Compatible with the following versions of IntelliJ Platform:
|
||||
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. -->
|
||||
<depends>com.intellij.modules.lang</depends>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
plugins {
|
||||
id 'java'
|
||||
id 'org.jetbrains.intellij' version '0.4.9'
|
||||
id 'org.jetbrains.intellij' version '0.4.10'
|
||||
}
|
||||
|
||||
group 'org.intellij.sdk'
|
||||
@ -20,7 +20,7 @@ dependencies {
|
||||
|
||||
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||
intellij {
|
||||
version '2019.2'
|
||||
version '2019.1'
|
||||
updateSinceUntilBuild = false
|
||||
}
|
||||
patchPluginXml {
|
||||
|
@ -6,13 +6,14 @@ import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* If conditions support it, makes a menu visible to display information
|
||||
* about the caret.
|
||||
* @author Anna Bulenkova
|
||||
*
|
||||
* @see com.intellij.openapi.actionSystem.AnAction
|
||||
*/
|
||||
public class EditorAreaIllustration extends AnAction {
|
||||
@ -22,32 +23,35 @@ public class EditorAreaIllustration extends AnAction {
|
||||
* @param e Event related to this action
|
||||
*/
|
||||
@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.
|
||||
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
||||
CaretModel caretModel = editor.getCaretModel();
|
||||
// Getting the primary caret ensures we get the right one of a possible many.
|
||||
Caret primaryCaret = caretModel.getPrimaryCaret();
|
||||
final CaretModel caretModel = editor.getCaretModel();
|
||||
// Getting the primary caret ensures we get the correct one of a possible many.
|
||||
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.
|
||||
StringBuilder report = new StringBuilder();
|
||||
report.append(primaryCaret.getLogicalPosition().toString() + "\n");
|
||||
report.append(primaryCaret.getVisualPosition().toString() + "\n");
|
||||
report.append("Offset: " + primaryCaret.getOffset());
|
||||
StringBuilder report = new StringBuilder(logicalPos.toString() + "\n");
|
||||
report.append(visualPos.toString() + "\n");
|
||||
report.append("Offset: " + caretOffset);
|
||||
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,
|
||||
* An editor is active,
|
||||
* @param e Event related to this action
|
||||
*/
|
||||
@Override
|
||||
public void update(AnActionEvent e) {
|
||||
//Get required data keys
|
||||
public void update(@NotNull final AnActionEvent e) {
|
||||
// Get required data keys
|
||||
final Project project = e.getProject();
|
||||
final Editor editor = e.getData(CommonDataKeys.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.
|
||||
* @author Anna Bulenkova
|
||||
*
|
||||
* @see com.intellij.openapi.actionSystem.AnAction
|
||||
*/
|
||||
public class EditorHandlerIllustration extends AnAction {
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* This registration code just needs to appear in a class (like AnAction class)
|
||||
* that gets instantiated as part of IntelliJ startup.
|
||||
@ -33,19 +33,19 @@ public class EditorHandlerIllustration extends AnAction {
|
||||
* @param e Event related to this action
|
||||
*/
|
||||
@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
|
||||
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
||||
// 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
|
||||
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
|
||||
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,
|
||||
* An editor is active,
|
||||
* At least one caret exists
|
||||
@ -53,15 +53,15 @@ public class EditorHandlerIllustration extends AnAction {
|
||||
*/
|
||||
@Override
|
||||
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 Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||
// Make sure at least one caret is available
|
||||
boolean menuAllowed = false;
|
||||
if (editor != null && project != null) {
|
||||
// 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,21 +7,22 @@ import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.actionSystem.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Menu action to replace a selection of characters with a fixed string.
|
||||
* @author Anna Bulenkova
|
||||
*
|
||||
* @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.
|
||||
* @param e Event related to this action
|
||||
*/
|
||||
@Override
|
||||
public void actionPerformed(final AnActionEvent e) {
|
||||
//Get all the required data from data keys
|
||||
public void actionPerformed(@NotNull final AnActionEvent e) {
|
||||
// Get all the required data from data keys
|
||||
// Editor and Project were verified in update(), so they are not null.
|
||||
final Editor editor = e.getRequiredData(CommonDataKeys.EDITOR);
|
||||
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
|
||||
@ -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,
|
||||
* An editor is active,
|
||||
* Some characters are selected
|
||||
* @param e Event related to this action
|
||||
*/
|
||||
@Override
|
||||
public void update(final AnActionEvent e) {
|
||||
//Get required data keys
|
||||
public void update(@NotNull final AnActionEvent e) {
|
||||
// Get required data keys
|
||||
final Project project = e.getProject();
|
||||
final Editor editor = e.getData(CommonDataKeys.EDITOR);
|
||||
//Set visibility only in case of existing project and editor and if a selection exists
|
||||
e.getPresentation().setVisible((project != null && editor != null && editor.getSelectionModel().hasSelection()));
|
||||
// Set visibility and enable only in case of existing project and editor and if a selection exists
|
||||
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.
|
||||
* Document changes are made in the context of a write action.
|
||||
* MyTypedHandler is registered by static code in the EditorHandlerIllustration class.
|
||||
* @author Anna Bulenkova
|
||||
*
|
||||
* @see com.intellij.openapi.editor.actionSystem.TypedActionHandler
|
||||
*/
|
||||
class MyTypedHandler implements TypedActionHandler {
|
||||
@ -23,7 +23,7 @@ class MyTypedHandler implements TypedActionHandler {
|
||||
public void execute(@NotNull Editor editor, char c, @NotNull DataContext dataContext) {
|
||||
// Get the document and project
|
||||
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
|
||||
Runnable runnable = () -> document.insertString(0, "editor_basics\n");
|
||||
// Make the document change in the context of a write action.
|
||||
|
@ -12,7 +12,7 @@
|
||||
<version>2.0.0</version>
|
||||
|
||||
<!-- Compatible with the following versions of IntelliJ Platform -->
|
||||
<idea-version since-build="171"/>
|
||||
<idea-version since-build="191"/>
|
||||
|
||||
<!-- Product and plugin compatibility requirements -->
|
||||
<depends>com.intellij.modules.lang</depends>
|
||||
@ -36,8 +36,8 @@
|
||||
<vendor url="https://plugins.jetbrains.com">IntelliJ Platform SDK</vendor>
|
||||
|
||||
<actions>
|
||||
<action id="EditorBasics.EditorIllustration"
|
||||
class="org.intellij.sdk.editor.EditorIllustration"
|
||||
<action id="EditorBasics.EditorIllustrationAction"
|
||||
class="org.intellij.sdk.editor.EditorIllustrationAction"
|
||||
text="Editor Replace Text"
|
||||
description="Replaces selected text with 'Replacement'."
|
||||
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>
|
||||
|
||||
<idea-version since-build="131" until-build="193.*"/>
|
||||
<idea-version since-build="191"/>
|
||||
<extensions defaultExtensionNs="com.intellij">
|
||||
</extensions>
|
||||
|
||||
|
@ -18,7 +18,7 @@ dependencies {
|
||||
|
||||
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||
intellij {
|
||||
version '2017.1'
|
||||
version '2019.1'
|
||||
updateSinceUntilBuild = false
|
||||
}
|
||||
|
||||
|
@ -1,2 +1,2 @@
|
||||
rootProject.name = 'inspection_basics'
|
||||
rootProject.name = 'inspection'
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
<version>2.0.0</version>
|
||||
|
||||
<!-- Compatible with the following versions of IntelliJ Platform -->
|
||||
<idea-version since-build="171"/>
|
||||
<idea-version since-build="191"/>
|
||||
|
||||
<!-- Product and plugin compatibility requirements -->
|
||||
<depends>com.intellij.modules.lang</depends>
|
||||
|
@ -20,9 +20,13 @@ dependencies {
|
||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main.kotlin.srcDirs += 'src/main/kotlin'
|
||||
}
|
||||
|
||||
// See https://github.com/JetBrains/gradle-intellij-plugin/
|
||||
intellij {
|
||||
version '2019.1.3'
|
||||
version '2019.1'
|
||||
updateSinceUntilBuild = false
|
||||
}
|
||||
compileKotlin {
|
||||
|
@ -1,2 +1,2 @@
|
||||
rootProject.name = 'kotlin_demo'
|
||||
rootProject.name = 'kotlin'
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
<version>2.0.0</version>
|
||||
|
||||
<!-- 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 -->
|
||||
<depends>com.intellij.modules.lang</depends>
|
||||
|
Loading…
x
Reference in New Issue
Block a user