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
54f82832e4
commit
7da2f4783a
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -85,8 +85,11 @@ Parameter e carries information on the invocation place and data available
|
||||
|
||||
@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);
|
||||
}
|
||||
}
|
||||
[Link to source code] (https://github.com/JetBrains/intellij-sdk/blob/master/code_samples/plugin_sample/src/org/jetbrains/plugins/sample/SimpleAction.java)
|
||||
|
Loading…
x
Reference in New Issue
Block a user