mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-30 02:07:50 +08:00
Added display of Psi element to dialog
This commit is contained in:
parent
8346970945
commit
b2b2bd1480
13
register_actions/src/org/jetbrains/tutorials/actions/SimplePopDialogAction.java
Normal file → Executable file
13
register_actions/src/org/jetbrains/tutorials/actions/SimplePopDialogAction.java
Normal file → Executable file
@ -6,8 +6,10 @@ package org.jetbrains.tutorials.actions;
|
|||||||
|
|
||||||
import com.intellij.openapi.actionSystem.AnAction;
|
import com.intellij.openapi.actionSystem.AnAction;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
|
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||||
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 com.intellij.pom.Navigatable;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
@ -49,16 +51,21 @@ public class SimplePopDialogAction extends AnAction {
|
|||||||
/**
|
/**
|
||||||
* Gives the user feedback when the dynamic action menu is chosen.
|
* Gives the user feedback when the dynamic action menu is chosen.
|
||||||
* Pops a simple message dialog. See the psi_demo plugin for an
|
* Pops a simple message dialog. See the psi_demo plugin for an
|
||||||
* example of how to use AnActionEvent to access Psi data.
|
* example of how to use AnActionEvent to access data.
|
||||||
* @param anActionEvent Event received when the associated menu item is chosen.
|
* @param anActionEvent Event received when the associated menu item is chosen.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
|
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
|
||||||
// Using the event, create and show a dialog
|
// Using the event, create and show a dialog
|
||||||
Project currentProject = anActionEvent.getProject();
|
Project currentProject = anActionEvent.getProject();
|
||||||
|
StringBuffer dlgMsg = new StringBuffer(anActionEvent.getPresentation().getText() + " Selected!");
|
||||||
String dlgTitle = anActionEvent.getPresentation().getDescription();
|
String dlgTitle = anActionEvent.getPresentation().getDescription();
|
||||||
String dlgMessage = anActionEvent.getPresentation().getText() + " Selected!";
|
// If an element is selected in the editor, add info about it.
|
||||||
Messages.showMessageDialog(currentProject, dlgMessage, dlgTitle, Messages.getInformationIcon());
|
Navigatable nav = anActionEvent.getData(CommonDataKeys.NAVIGATABLE);
|
||||||
|
if (nav != null) {
|
||||||
|
dlgMsg.append(String.format("\nSelected Element: %s", nav.toString()));
|
||||||
|
}
|
||||||
|
Messages.showMessageDialog(currentProject, dlgMsg.toString(), dlgTitle, Messages.getInformationIcon());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user