mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 08:47:50 +08:00
better action.update
This commit is contained in:
parent
79f8efc5a6
commit
9963948763
@ -2,6 +2,7 @@ package org.jetbrains.plugins.sample;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
@ -14,7 +15,10 @@ public class SimpleAction extends AnAction {
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
e.getPresentation().setVisible(true);
|
||||
e.getPresentation().setEnabled(true);
|
||||
//Make action visible and available only when project is defined
|
||||
final Project project = e.getProject();
|
||||
boolean isAvailable = project != null;
|
||||
e.getPresentation().setVisible(isAvailable);
|
||||
e.getPresentation().setEnabled(isAvailable);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user