mirror of
https://github.com/JetBrains/intellij-sdk-code-samples.git
synced 2025-07-27 16:57:49 +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.AnAction;
|
||||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -14,7 +15,10 @@ public class SimpleAction extends AnAction {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(@NotNull AnActionEvent e) {
|
public void update(@NotNull AnActionEvent e) {
|
||||||
e.getPresentation().setVisible(true);
|
//Make action visible and available only when project is defined
|
||||||
e.getPresentation().setEnabled(true);
|
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