Search in sources :

Example 31 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class XDebuggerInlayUtil method clearInlays.

public static void clearInlays(@NotNull Project project) {
    UIUtil.invokeLaterIfNeeded(() -> {
        FileEditor[] editors = FileEditorManager.getInstance(project).getAllEditors();
        for (FileEditor editor : editors) {
            if (editor instanceof TextEditor) {
                Editor e = ((TextEditor) editor).getEditor();
                List<Inlay> existing = e.getInlayModel().getInlineElementsInRange(0, e.getDocument().getTextLength());
                for (Inlay inlay : existing) {
                    if (inlay.getRenderer() instanceof MyRenderer) {
                        Disposer.dispose(inlay);
                    }
                }
            }
        }
    });
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Inlay(com.intellij.openapi.editor.Inlay) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor)

Example 32 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class ExecutionPointHighlighter method doShow.

private void doShow(boolean navigate) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    if (ApplicationManager.getApplication().isUnitTestMode())
        return;
    removeHighlighter();
    OpenFileDescriptor fileDescriptor = myOpenFileDescriptor;
    if (!navigate && myOpenFileDescriptor != null) {
        fileDescriptor = new OpenFileDescriptor(myProject, myOpenFileDescriptor.getFile());
    }
    myEditor = null;
    if (fileDescriptor != null) {
        if (!navigate) {
            FileEditor editor = FileEditorManager.getInstance(fileDescriptor.getProject()).getSelectedEditor(fileDescriptor.getFile());
            if (editor instanceof TextEditor) {
                myEditor = ((TextEditor) editor).getEditor();
            }
        }
        if (myEditor == null) {
            myEditor = XDebuggerUtilImpl.createEditor(fileDescriptor);
        }
    }
    if (myEditor != null) {
        addHighlighter();
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 33 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class TransferableFileEditorStateSupport method processContextHints.

public void processContextHints(@NotNull DiffRequest request, @NotNull DiffContext context) {
    if (!isEnabled())
        return;
    for (BinaryEditorHolder holder : myHolders) {
        FileEditor editor = holder.getEditor();
        TransferableFileEditorState state = getEditorState(holder.getEditor());
        if (state != null) {
            readContextData(context, editor, state);
        }
    }
}
Also used : BinaryEditorHolder(com.intellij.diff.tools.holders.BinaryEditorHolder) FileEditor(com.intellij.openapi.fileEditor.FileEditor) TransferableFileEditorState(com.intellij.openapi.fileEditor.TransferableFileEditorState)

Example 34 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class InheritorChooser method runMethodInAbstractClass.

public boolean runMethodInAbstractClass(final ConfigurationContext context, final Runnable performRunnable, final PsiMethod psiMethod, final PsiClass containingClass, final Condition<PsiClass> acceptAbstractCondition) {
    if (containingClass != null && acceptAbstractCondition.value(containingClass)) {
        final Location location = context.getLocation();
        if (location instanceof MethodLocation) {
            final PsiClass aClass = ((MethodLocation) location).getContainingClass();
            if (aClass != null && !aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
                return false;
            }
        } else if (location instanceof PsiMemberParameterizedLocation) {
            return false;
        }
        final List<PsiClass> classes = new ArrayList<>();
        if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
            final boolean isJUnit5 = ReadAction.compute(() -> JUnitUtil.isJUnit5(containingClass));
            ClassInheritorsSearch.search(containingClass).forEach(aClass -> {
                if (isJUnit5 && JUnitUtil.isJUnit5TestClass(aClass, true) || PsiClassUtil.isRunnableClass(aClass, true, true)) {
                    classes.add(aClass);
                }
                return true;
            });
        }, "Search for " + containingClass.getQualifiedName() + " inheritors", true, containingClass.getProject())) {
            return true;
        }
        if (classes.size() == 1) {
            runForClass(classes.get(0), psiMethod, context, performRunnable);
            return true;
        }
        if (classes.isEmpty())
            return false;
        final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(context.getDataContext());
        if (fileEditor instanceof TextEditor) {
            final Document document = ((TextEditor) fileEditor).getEditor().getDocument();
            final PsiFile containingFile = PsiDocumentManager.getInstance(context.getProject()).getPsiFile(document);
            if (containingFile instanceof PsiClassOwner) {
                final List<PsiClass> psiClasses = new ArrayList<>(Arrays.asList(((PsiClassOwner) containingFile).getClasses()));
                psiClasses.retainAll(classes);
                if (psiClasses.size() == 1) {
                    runForClass(psiClasses.get(0), psiMethod, context, performRunnable);
                    return true;
                }
            }
        }
        final int numberOfInheritors = classes.size();
        final PsiClassListCellRenderer renderer = new PsiClassListCellRenderer() {

            @Override
            protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
                if (value == null) {
                    renderer.append("All (" + numberOfInheritors + ")");
                    return true;
                }
                return super.customizeNonPsiElementLeftRenderer(renderer, list, value, index, selected, hasFocus);
            }
        };
        Collections.sort(classes, renderer.getComparator());
        //suggest to run all inherited tests 
        classes.add(0, null);
        final JBList list = new JBList(classes);
        list.setCellRenderer(renderer);
        JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose executable classes to run " + (psiMethod != null ? psiMethod.getName() : containingClass.getName())).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
            final Object[] values = list.getSelectedValues();
            if (values == null)
                return;
            chooseAndPerform(values, psiMethod, context, performRunnable, classes);
        }).createPopup().showInBestPositionFor(context.getDataContext());
        return true;
    }
    return false;
}
Also used : ProgressManager(com.intellij.openapi.progress.ProgressManager) JBList(com.intellij.ui.components.JBList) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) Arrays(java.util.Arrays) ArrayUtil(com.intellij.util.ArrayUtil) ConfigurationContext(com.intellij.execution.actions.ConfigurationContext) Document(com.intellij.openapi.editor.Document) FileEditor(com.intellij.openapi.fileEditor.FileEditor) ReadAction(com.intellij.openapi.application.ReadAction) ArrayList(java.util.ArrayList) List(java.util.List) PlatformDataKeys(com.intellij.openapi.actionSystem.PlatformDataKeys) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) PsiClassListCellRenderer(com.intellij.ide.util.PsiClassListCellRenderer) PsiClassUtil(com.intellij.psi.util.PsiClassUtil) JBPopupFactory(com.intellij.openapi.ui.popup.JBPopupFactory) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) com.intellij.psi(com.intellij.psi) ClassInheritorsSearch(com.intellij.psi.search.searches.ClassInheritorsSearch) Location(com.intellij.execution.Location) Collections(java.util.Collections) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) FileEditor(com.intellij.openapi.fileEditor.FileEditor) ArrayList(java.util.ArrayList) ColoredListCellRenderer(com.intellij.ui.ColoredListCellRenderer) Document(com.intellij.openapi.editor.Document) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) TextEditor(com.intellij.openapi.fileEditor.TextEditor) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) PsiClassListCellRenderer(com.intellij.ide.util.PsiClassListCellRenderer) JBList(com.intellij.ui.components.JBList) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) Location(com.intellij.execution.Location)

Example 35 with FileEditor

use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.

the class EditorWindow method syncCaretIfPossible.

/**
   * Tries to setup caret and viewport for the given editor from the selected one.
   *
   * @param toSync    editor to setup caret and viewport for
   */
private void syncCaretIfPossible(@Nullable FileEditor[] toSync) {
    if (toSync == null) {
        return;
    }
    final EditorWithProviderComposite from = getSelectedEditor();
    if (from == null) {
        return;
    }
    final FileEditor caretSource = from.getSelectedEditor();
    if (!(caretSource instanceof TextEditor)) {
        return;
    }
    final Editor editorFrom = ((TextEditor) caretSource).getEditor();
    final int offset = editorFrom.getCaretModel().getOffset();
    if (offset <= 0) {
        return;
    }
    final int scrollOffset = editorFrom.getScrollingModel().getVerticalScrollOffset();
    for (FileEditor fileEditor : toSync) {
        if (!(fileEditor instanceof TextEditor)) {
            continue;
        }
        final Editor editor = ((TextEditor) fileEditor).getEditor();
        if (editorFrom.getDocument() == editor.getDocument()) {
            editor.getCaretModel().moveToOffset(offset);
            final ScrollingModel scrollingModel = editor.getScrollingModel();
            scrollingModel.scrollVertically(scrollOffset);
            SwingUtilities.invokeLater(() -> {
                if (!editor.isDisposed()) {
                    scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
                }
            });
        }
    }
}
Also used : FileEditor(com.intellij.openapi.fileEditor.FileEditor) TextEditor(com.intellij.openapi.fileEditor.TextEditor) ScrollingModel(com.intellij.openapi.editor.ScrollingModel) TextEditor(com.intellij.openapi.fileEditor.TextEditor) Editor(com.intellij.openapi.editor.Editor) FileEditor(com.intellij.openapi.fileEditor.FileEditor)

Aggregations

FileEditor (com.intellij.openapi.fileEditor.FileEditor)157 VirtualFile (com.intellij.openapi.vfs.VirtualFile)62 TextEditor (com.intellij.openapi.fileEditor.TextEditor)59 Editor (com.intellij.openapi.editor.Editor)43 Project (com.intellij.openapi.project.Project)40 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)37 Nullable (org.jetbrains.annotations.Nullable)21 DataContext (com.intellij.openapi.actionSystem.DataContext)20 PsiFile (com.intellij.psi.PsiFile)19 Document (com.intellij.openapi.editor.Document)15 NotNull (org.jetbrains.annotations.NotNull)14 IpnbFileEditor (org.jetbrains.plugins.ipnb.editor.IpnbFileEditor)14 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)10 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)9 IpnbFilePanel (org.jetbrains.plugins.ipnb.editor.panels.IpnbFilePanel)8 StructureViewBuilder (com.intellij.ide.structureView.StructureViewBuilder)7 StructureViewComponent (com.intellij.ide.structureView.newStructureView.StructureViewComponent)6 BlobExplorerFileEditor (com.microsoft.intellij.helpers.storage.BlobExplorerFileEditor)6 QueueFileEditor (com.microsoft.intellij.helpers.storage.QueueFileEditor)6 TableFileEditor (com.microsoft.intellij.helpers.storage.TableFileEditor)6