Search in sources :

Example 66 with DataContext

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);
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor)

Example 67 with DataContext

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();
        }
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) ColorAndFontOptions(com.intellij.application.options.colors.ColorAndFontOptions) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) Configurable(com.intellij.openapi.options.Configurable) SearchableConfigurable(com.intellij.openapi.options.SearchableConfigurable) Settings(com.intellij.openapi.options.ex.Settings)

Example 68 with DataContext

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);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext)

Example 69 with DataContext

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));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) PsiElement(com.intellij.psi.PsiElement)

Example 70 with DataContext

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);
    }
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) Caret(com.intellij.openapi.editor.Caret)

Aggregations

DataContext (com.intellij.openapi.actionSystem.DataContext)204 Project (com.intellij.openapi.project.Project)73 VirtualFile (com.intellij.openapi.vfs.VirtualFile)29 NotNull (org.jetbrains.annotations.NotNull)23 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)23 Editor (com.intellij.openapi.editor.Editor)22 Nullable (org.jetbrains.annotations.Nullable)21 FileEditor (com.intellij.openapi.fileEditor.FileEditor)20 PsiFile (com.intellij.psi.PsiFile)17 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)16 Module (com.intellij.openapi.module.Module)13 PsiElement (com.intellij.psi.PsiElement)13 SimpleDataContext (com.intellij.openapi.actionSystem.impl.SimpleDataContext)11 Presentation (com.intellij.openapi.actionSystem.Presentation)10 DataManager (com.intellij.ide.DataManager)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)9 List (java.util.List)9 Consumer (com.intellij.util.Consumer)7 AnAction (com.intellij.openapi.actionSystem.AnAction)6 Transferable (java.awt.datatransfer.Transferable)6