use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class BaseCodeCompletionAction method update.
@Override
public void update(AnActionEvent e) {
DataContext dataContext = e.getDataContext();
e.getPresentation().setEnabled(false);
Project project = CommonDataKeys.PROJECT.getData(dataContext);
if (project == null)
return;
Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
if (editor == null)
return;
final PsiFile psiFile = PsiUtilBase.getPsiFileInEditor(editor, project);
if (psiFile == null)
return;
if (!ApplicationManager.getApplication().isUnitTestMode() && !editor.getContentComponent().isShowing())
return;
e.getPresentation().setEnabled(true);
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class SeverityEditorDialog method editColorsAndFonts.
private void editColorsAndFonts() {
final String toConfigure = getSelectedType().getSeverity(null).myName;
if (myCloseDialogWhenSettingsShown) {
doOKAction();
}
myOptionsList.clearSelection();
final DataContext dataContext = DataManager.getInstance().getDataContext(myPanel);
Settings settings = Settings.KEY.getData(dataContext);
if (settings != null) {
ColorAndFontOptions colorAndFontOptions = settings.find(ColorAndFontOptions.class);
assert colorAndFontOptions != null;
final SearchableConfigurable javaPage = colorAndFontOptions.findSubConfigurable(InspectionColorSettingsPage.class);
LOG.assertTrue(javaPage != null);
settings.select(javaPage).doWhenDone(() -> {
final Runnable runnable = javaPage.enableSearch(toConfigure);
if (runnable != null) {
SwingUtilities.invokeLater(runnable);
}
});
} else {
ColorAndFontOptions colorAndFontOptions = new ColorAndFontOptions();
final Configurable[] configurables = colorAndFontOptions.buildConfigurables();
try {
final SearchableConfigurable javaPage = colorAndFontOptions.findSubConfigurable(InspectionColorSettingsPage.class);
LOG.assertTrue(javaPage != null);
ShowSettingsUtil.getInstance().editConfigurable(CommonDataKeys.PROJECT.getData(dataContext), javaPage);
} finally {
for (Configurable configurable : configurables) {
configurable.disposeUIResources();
}
colorAndFontOptions.disposeUIResources();
}
}
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class SaveAsAction method update.
@Override
public void update(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
e.getPresentation().setEnabled(project != null && virtualFile != null);
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class SaveAsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(dataContext);
@SuppressWarnings({ "ConstantConditions" }) final PsiElement element = PsiManager.getInstance(project).findFile(virtualFile);
if (element == null)
return;
CopyHandler.doCopy(new PsiElement[] { element.getContainingFile() }, PlatformPackageUtil.getDirectory(element));
}
use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.
the class EditorActionHandler method doIfEnabled.
private void doIfEnabled(@NotNull Caret hostCaret, @Nullable DataContext context, @NotNull CaretTask task) {
DataContext caretContext = context == null ? null : new CaretSpecificDataContext(context, hostCaret);
if (myWorksInInjected && caretContext != null) {
DataContext injectedCaretContext = AnActionEvent.getInjectedDataContext(caretContext);
Caret injectedCaret = CommonDataKeys.CARET.getData(injectedCaretContext);
if (injectedCaret != null && injectedCaret != hostCaret && isEnabledForCaret(injectedCaret.getEditor(), injectedCaret, injectedCaretContext)) {
task.perform(injectedCaret, injectedCaretContext);
return;
}
}
if (isEnabledForCaret(hostCaret.getEditor(), hostCaret, caretContext)) {
task.perform(hostCaret, caretContext);
}
}
Aggregations