Update action system tutorial

Clean up structure, link from necessary places, update sample plugin
code to demonstrate best practices, fix some English
This commit is contained in:
Dmitry Jemerov 2018-03-11 21:36:42 +01:00
parent f0c2d8a50c
commit 0caaec2817
3 changed files with 11 additions and 19 deletions

View File

@ -2,9 +2,6 @@ package org.jetbrains.tutorials.actions;
import com.intellij.openapi.actionSystem.*;
/**
* @author Anna Bulenkova
*/
public class CustomGroupedAction extends AnAction {
@Override
public void actionPerformed(AnActionEvent anActionEvent) {

View File

@ -2,13 +2,9 @@ package org.jetbrains.tutorials.actions;
import com.intellij.openapi.actionSystem.*;
/**
* @author Anna Bulenkova
*/
public class GroupedAction extends AnAction {
@Override
public void update(AnActionEvent event) {
event.getPresentation().setEnabledAndVisible(true);
}
@Override

View File

@ -1,27 +1,26 @@
package org.jetbrains.tutorials.actions;
import com.intellij.openapi.actionSystem.*;
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;
/**
* @author Anna Bulenkova
*/
public class SimpleAction extends AnAction {
@Override
public void actionPerformed(AnActionEvent anActionEvent) {
Object navigatable = anActionEvent.getData(CommonDataKeys.NAVIGATABLE);
if (navigatable != null) {
Messages.showDialog(navigatable.toString(), "Selected Element:", new String[]{"OK"}, -1, null);
Project project = anActionEvent.getProject();
Navigatable navigatable = anActionEvent.getData(CommonDataKeys.NAVIGATABLE);
if (project != null && navigatable != null) {
Messages.showMessageDialog(project, navigatable.toString(), "Selected Element", Messages.getInformationIcon());
}
}
@Override
public void update(AnActionEvent anActionEvent) {
final Project project = anActionEvent.getData(CommonDataKeys.PROJECT);
if (project != null)
return;
Object navigatable = anActionEvent.getData(CommonDataKeys.NAVIGATABLE);
anActionEvent.getPresentation().setVisible(navigatable != null);
Project project = anActionEvent.getProject();
Navigatable navigatable = anActionEvent.getData(CommonDataKeys.NAVIGATABLE);
anActionEvent.getPresentation().setEnabledAndVisible(project != null && navigatable != null);
}
}