e.getPresentation().setEnabledAndVisible(enabled);
}
@Override
public void actionPerformed(AnActionEvent e) {
final Editor editor = PlatformDataKeys.EDITOR.getData(e.getDataContext());
PsiFile psiFile = LangDataKeys.PSI_FILE.getData(e.getDataContext());
Language language = psiFile == null ? null : psiFile.getLanguage();
final LivePreviewLanguage livePreviewLanguage = language instanceof LivePreviewLanguage ? (LivePreviewLanguage)language : null;
final Editor grammarEditor = livePreviewLanguage == null ? null : getGrammarEditor(psiFile.getProject(), livePreviewLanguage);
if (editor == null || grammarEditor == null) return;
final Project project = psiFile.getProject();
CaretListener caretListener = editor.getUserData(GRAMMAR_UPDATE_RUNNING);
if (caretListener != null) {
editor.putUserData(GRAMMAR_UPDATE_RUNNING, null);
editor.getCaretModel().removeCaretListener(caretListener);
HighlightManagerImpl highlightManager = (HighlightManagerImpl)HighlightManager.getInstance(project);
highlightManager.hideHighlights(grammarEditor, HighlightManager.HIDE_BY_ESCAPE | HighlightManager.HIDE_BY_ANY_KEY);
}
else {
updateGrammarHighlighters(project, editor, livePreviewLanguage, grammarEditor);
caretListener = new CaretAdapter() {
@Override
public void caretPositionChanged(final CaretEvent e) {
final CaretListener caretListener = this;
LivePreviewHelper.getUpdateQueue(project).queue(new Update(e.getEditor()) {
@Override
public void run() {
if (grammarEditor.isDisposed()) {
e.getEditor().getCaretModel().removeCaretListener(caretListener);
e.getEditor().putUserData(GRAMMAR_UPDATE_RUNNING, null);
return;
}
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {