Search in sources :

Example 36 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class EncodingPanel method getContext.

@NotNull
private DataContext getContext() {
    Editor editor = getEditor();
    DataContext parent = DataManager.getInstance().getDataContext((Component) myStatusBar);
    return SimpleDataContext.getSimpleContext(CommonDataKeys.VIRTUAL_FILE.getName(), getSelectedFile(), SimpleDataContext.getSimpleContext(CommonDataKeys.PROJECT.getName(), getProject(), SimpleDataContext.getSimpleContext(PlatformDataKeys.CONTEXT_COMPONENT.getName(), editor == null ? null : editor.getComponent(), parent)));
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) com.intellij.openapi.fileEditor(com.intellij.openapi.fileEditor) Editor(com.intellij.openapi.editor.Editor) NotNull(org.jetbrains.annotations.NotNull)

Example 37 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class FocusTrackback method restoreFocus.

public void restoreFocus() {
    if (isHeadlessOrWrongOS() || myConsumed || isScheduledForRestore())
        return;
    Project project = null;
    DataManager dataManager = DataManager.getInstance();
    if (dataManager != null) {
        DataContext context = myParentWindow == null ? dataManager.getDataContext() : dataManager.getDataContext(myParentWindow);
        if (context != null) {
            project = CommonDataKeys.PROJECT.getData(context);
        }
    }
    myScheduledForRestore = true;
    final List<FocusTrackback> stack = getCleanStackForRoot();
    final int index = stack.indexOf(this);
    for (int i = index - 1; i >= 0; i--) {
        if (stack.get(i).isScheduledForRestore()) {
            dispose();
            return;
        }
    }
    if (project != null && !project.isDisposed()) {
        final IdeFocusManager focusManager = IdeFocusManager.getInstance(project);
        cleanParentWindow();
        final Project finalProject = project;
        focusManager.requestFocus(new MyFocusCommand(), myForcedRestore).doWhenProcessed(() -> dispose()).doWhenRejected(() -> focusManager.revalidateFocus(new ExpirableRunnable.ForProject(finalProject) {

            @Override
            public void run() {
                if (UIUtil.isMeaninglessFocusOwner(focusManager.getFocusOwner())) {
                    focusManager.requestDefaultFocus(false);
                }
            }
        }));
    } else {
        // no ide focus manager, so no way -- do just later
        //noinspection SSBasedInspection
        SwingUtilities.invokeLater(() -> {
            _restoreFocus();
            dispose();
        });
    }
}
Also used : Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) DataManager(com.intellij.ide.DataManager)

Example 38 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class JarRootsRefreshTest method checkMove.

private void checkMove(File jar, VirtualFile vFile, PsiFile file) {
    VirtualFile jarRoot;
    File libDir = new File(jar.getParent(), "lib");
    assertTrue(libDir.mkdir());
    VirtualFile vLibDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libDir);
    assertNotNull(vLibDir);
    jarRoot = JarFileSystem.getInstance().getRootByLocal(vFile);
    assertNotNull(jarRoot);
    assertTrue(jarRoot.isValid());
    PsiDirectory directory = getPsiManager().findDirectory(vLibDir);
    DataContext psiDataContext = SimpleDataContext.getSimpleContext(LangDataKeys.TARGET_PSI_ELEMENT.getName(), directory);
    new MoveHandler().invoke(myProject, new PsiElement[] { file }, psiDataContext);
    assertFalse(jarRoot.isValid());
    jarRoot = JarFileSystem.getInstance().getRootByLocal(vFile);
    assertNotNull(jarRoot);
    assertTrue(jarRoot.isValid());
    rename(directory, "lib2");
    assertFalse(jarRoot.isValid());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) DataContext(com.intellij.openapi.actionSystem.DataContext) SimpleDataContext(com.intellij.openapi.actionSystem.impl.SimpleDataContext) PsiDirectory(com.intellij.psi.PsiDirectory) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) MoveHandler(com.intellij.refactoring.move.MoveHandler)

Example 39 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class LightPlatformCodeInsightTestCase method type.

public static void type(char c, @NotNull Editor editor, Project project) {
    if (c == '\n') {
        executeAction(IdeActions.ACTION_EDITOR_ENTER, editor, project);
    } else {
        EditorActionManager actionManager = EditorActionManager.getInstance();
        final DataContext dataContext = DataManager.getInstance().getDataContext();
        TypedAction action = actionManager.getTypedAction();
        action.actionPerformed(editor, c, dataContext);
    }
}
Also used : EditorActionManager(com.intellij.openapi.editor.actionSystem.EditorActionManager) DataContext(com.intellij.openapi.actionSystem.DataContext) TypedAction(com.intellij.openapi.editor.actionSystem.TypedAction)

Example 40 with DataContext

use of com.intellij.openapi.actionSystem.DataContext in project intellij-community by JetBrains.

the class XEvaluateInConsoleFromEditorActionHandler method perform.

@Override
protected void perform(@NotNull XDebugSession session, DataContext dataContext) {
    Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    if (editor == null || !(editor instanceof EditorEx)) {
        return;
    }
    int selectionStart = editor.getSelectionModel().getSelectionStart();
    int selectionEnd = editor.getSelectionModel().getSelectionEnd();
    Promise<Pair<TextRange, String>> rangeAndText = null;
    if (selectionStart != selectionEnd) {
        TextRange textRange = new TextRange(selectionStart, selectionEnd);
        rangeAndText = Promise.resolve(Pair.create(textRange, editor.getDocument().getText(textRange)));
    } else {
        XDebuggerEvaluator evaluator = session.getDebugProcess().getEvaluator();
        if (evaluator != null) {
            Promise<ExpressionInfo> expressionInfoPromise = evaluator.getExpressionInfoAtOffsetAsync(session.getProject(), editor.getDocument(), selectionStart, true);
            rangeAndText = expressionInfoPromise.then(expressionInfo -> {
                if (expressionInfo == null) {
                    return null;
                }
                return Pair.create(expressionInfo.getTextRange(), XDebuggerEvaluateActionHandler.getExpressionText(expressionInfo, editor.getDocument()));
            });
        } else {
            return;
        }
    }
    rangeAndText.done(textRangeStringPair -> {
        ApplicationManager.getApplication().invokeLater(() -> {
            TextRange range = textRangeStringPair.getFirst();
            String text = textRangeStringPair.getSecond();
            if (text == null)
                return;
            ConsoleExecuteAction action = getConsoleExecuteAction(session);
            if (action != null) {
                action.execute(range, text, (EditorEx) editor);
            }
        });
    });
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) ActionUtil(com.intellij.openapi.actionSystem.ex.ActionUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) TextRange(com.intellij.openapi.util.TextRange) ContainerUtil(com.intellij.util.containers.ContainerUtil) Editor(com.intellij.openapi.editor.Editor) ExpressionInfo(com.intellij.xdebugger.evaluation.ExpressionInfo) Nullable(org.jetbrains.annotations.Nullable) Promise(org.jetbrains.concurrency.Promise) List(java.util.List) ConsoleView(com.intellij.execution.ui.ConsoleView) Pair(com.intellij.openapi.util.Pair) ApplicationManager(com.intellij.openapi.application.ApplicationManager) EditorEx(com.intellij.openapi.editor.ex.EditorEx) CommonDataKeys(com.intellij.openapi.actionSystem.CommonDataKeys) ConsoleExecuteAction(com.intellij.execution.console.ConsoleExecuteAction) LanguageConsoleView(com.intellij.execution.console.LanguageConsoleView) NotNull(org.jetbrains.annotations.NotNull) XDebugSession(com.intellij.xdebugger.XDebugSession) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) EditorEx(com.intellij.openapi.editor.ex.EditorEx) XDebuggerEvaluator(com.intellij.xdebugger.evaluation.XDebuggerEvaluator) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) ExpressionInfo(com.intellij.xdebugger.evaluation.ExpressionInfo) ConsoleExecuteAction(com.intellij.execution.console.ConsoleExecuteAction) Pair(com.intellij.openapi.util.Pair)

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