Added display of Psi element to dialog

This commit is contained in:
JohnHake 2018-08-20 09:28:30 -07:00
parent 8346970945
commit b2b2bd1480

View File

@ -6,8 +6,10 @@ package org.jetbrains.tutorials.actions;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.pom.Navigatable;
import org.jetbrains.annotations.NotNull;
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.
* 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.
*/
@Override
public void actionPerformed(@NotNull AnActionEvent anActionEvent) {
// Using the event, create and show a dialog
Project currentProject = anActionEvent.getProject();
StringBuffer dlgMsg = new StringBuffer(anActionEvent.getPresentation().getText() + " Selected!");
String dlgTitle = anActionEvent.getPresentation().getDescription();
String dlgMessage = anActionEvent.getPresentation().getText() + " Selected!";
Messages.showMessageDialog(currentProject, dlgMessage, dlgTitle, Messages.getInformationIcon());
// If an element is selected in the editor, add info about it.
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());
}
/**