Search in sources :

Example 46 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.

the class ImplementationViewComponent method update.

public void update(@NotNull final PsiElement[] elements, final int index) {
    update(elements, (psiElements, fileDescriptors) -> {
        if (myEditor.isDisposed())
            return false;
        if (psiElements.length == 0)
            return false;
        final Project project = psiElements[0].getProject();
        myElements = psiElements;
        myIndex = index < myElements.length ? index : 0;
        PsiFile psiFile = getContainingFile(myElements[myIndex]);
        VirtualFile virtualFile = psiFile.getVirtualFile();
        EditorHighlighter highlighter;
        if (virtualFile != null)
            highlighter = HighlighterFactory.createHighlighter(project, virtualFile);
        else {
            // some artificial psi file, lets do best we can
            String fileName = psiFile.getName();
            highlighter = HighlighterFactory.createHighlighter(project, fileName);
        }
        ((EditorEx) myEditor).setHighlighter(highlighter);
        if (myElements.length > 1) {
            myFileChooser.setVisible(true);
            myCountLabel.setVisible(true);
            myLabel.setVisible(false);
            myFileChooser.setModel(new DefaultComboBoxModel(fileDescriptors.toArray(new FileDescriptor[fileDescriptors.size()])));
            updateRenderer(project);
        } else {
            myFileChooser.setVisible(false);
            myCountLabel.setVisible(false);
            VirtualFile file = psiFile.getVirtualFile();
            if (file != null) {
                myLabel.setIcon(getIconForFile(psiFile));
                myLabel.setForeground(FileStatusManager.getInstance(project).getStatus(file).getColor());
                myLabel.setText(file.getPresentableName());
                myLabel.setBorder(new CompoundBorder(IdeBorderFactory.createRoundedBorder(), IdeBorderFactory.createEmptyBorder(0, 0, 0, 5)));
                myLabel.setVisible(true);
            }
        }
        updateControls();
        revalidate();
        repaint();
        return true;
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) EditorEx(com.intellij.openapi.editor.ex.EditorEx) CompoundBorder(javax.swing.border.CompoundBorder) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 47 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.

the class InspectionResultsView method showInRightPanel.

private void showInRightPanel(@Nullable final RefEntity refEntity) {
    Cursor currentCursor = getCursor();
    try {
        setCursor(new Cursor(Cursor.WAIT_CURSOR));
        final JPanel editorPanel = new JPanel();
        editorPanel.setLayout(new BorderLayout());
        final int problemCount = myTree.getSelectedProblemCount(true);
        JComponent previewPanel = null;
        final InspectionToolWrapper tool = myTree.getSelectedToolWrapper(true);
        if (tool != null && refEntity != null && refEntity.isValid()) {
            final TreePath path = myTree.getSelectionPath();
            if (path == null || !(path.getLastPathComponent() instanceof ProblemDescriptionNode)) {
                final InspectionToolPresentation presentation = myGlobalInspectionContext.getPresentation(tool);
                previewPanel = presentation.getCustomPreviewPanel(refEntity);
            }
        }
        EditorEx previewEditor = null;
        if (previewPanel == null) {
            final Pair<JComponent, EditorEx> panelAndEditor = createBaseRightComponentFor(problemCount, refEntity);
            previewPanel = panelAndEditor.getFirst();
            previewEditor = panelAndEditor.getSecond();
        }
        editorPanel.add(previewPanel, BorderLayout.CENTER);
        if (problemCount > 0) {
            final JComponent fixToolbar = QuickFixPreviewPanelFactory.create(this);
            if (fixToolbar != null) {
                if (fixToolbar instanceof InspectionTreeLoadingProgressAware) {
                    myLoadingProgressPreview = (InspectionTreeLoadingProgressAware) fixToolbar;
                }
                if (previewEditor != null) {
                    previewPanel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
                }
                editorPanel.add(fixToolbar, BorderLayout.NORTH);
            }
        }
        if (previewEditor != null) {
            new ProblemPreviewEditorPresentation(previewEditor, this);
        }
        mySplitter.setSecondComponent(editorPanel);
    } finally {
        setCursor(currentCursor);
    }
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) TreePath(javax.swing.tree.TreePath)

Example 48 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.

the class MethodSignatureComponent method setSignature.

public void setSignature(String signature) {
    setText(signature);
    final EditorEx editor = (EditorEx) getEditor();
    if (editor != null) {
        editor.getScrollingModel().scrollVertically(0);
        editor.getScrollingModel().scrollHorizontally(0);
    }
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx)

Example 49 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.

the class EnterAfterUnmatchedBraceHandler method getUnmatchedLBracesNumberBefore.

/**
   * Calculates number of unmatched left braces before the given offset.
   *
   * @param editor   target editor
   * @param offset   target offset
   * @param fileType target file type
   * @return number of unmatched braces before the given offset;
   * negative value if it's not possible to perform the calculation or if there are no unmatched left braces before
   * the given offset
   */
protected static int getUnmatchedLBracesNumberBefore(Editor editor, int offset, FileType fileType) {
    if (offset == 0) {
        return -1;
    }
    CharSequence chars = editor.getDocument().getCharsSequence();
    if (chars.charAt(offset - 1) != '{') {
        return -1;
    }
    EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
    HighlighterIterator iterator = highlighter.createIterator(offset - 1);
    BraceMatcher braceMatcher = BraceMatchingUtil.getBraceMatcher(fileType, iterator);
    if (!braceMatcher.isLBraceToken(iterator, chars, fileType) || !braceMatcher.isStructuralBrace(iterator, chars, fileType)) {
        return -1;
    }
    Language language = iterator.getTokenType().getLanguage();
    iterator = highlighter.createIterator(0);
    int lBracesBeforeOffset = 0;
    int lBracesAfterOffset = 0;
    int rBracesBeforeOffset = 0;
    int rBracesAfterOffset = 0;
    for (; !iterator.atEnd(); iterator.advance()) {
        IElementType tokenType = iterator.getTokenType();
        if (!tokenType.getLanguage().equals(language) || !braceMatcher.isStructuralBrace(iterator, chars, fileType)) {
            continue;
        }
        boolean beforeOffset = iterator.getStart() < offset;
        if (braceMatcher.isLBraceToken(iterator, chars, fileType)) {
            if (beforeOffset) {
                lBracesBeforeOffset++;
            } else {
                lBracesAfterOffset++;
            }
        } else if (braceMatcher.isRBraceToken(iterator, chars, fileType)) {
            if (beforeOffset) {
                rBracesBeforeOffset++;
            } else {
                rBracesAfterOffset++;
            }
        }
    }
    return lBracesBeforeOffset - rBracesBeforeOffset - (rBracesAfterOffset - lBracesAfterOffset);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) EditorEx(com.intellij.openapi.editor.ex.EditorEx) BraceMatcher(com.intellij.codeInsight.highlighting.BraceMatcher) Language(com.intellij.lang.Language) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Example 50 with EditorEx

use of com.intellij.openapi.editor.ex.EditorEx in project intellij-community by JetBrains.

the class EnterInLineCommentHandler method isInLineComment.

private static boolean isInLineComment(@NotNull Editor editor, int offset, IElementType lineCommentType) {
    if (offset < 1)
        return false;
    EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
    HighlighterIterator iterator = highlighter.createIterator(offset - 1);
    return iterator.getTokenType() == lineCommentType;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

Aggregations

EditorEx (com.intellij.openapi.editor.ex.EditorEx)153 Editor (com.intellij.openapi.editor.Editor)32 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)32 HighlighterIterator (com.intellij.openapi.editor.highlighter.HighlighterIterator)28 NotNull (org.jetbrains.annotations.NotNull)23 Document (com.intellij.openapi.editor.Document)22 EditorFactory (com.intellij.openapi.editor.EditorFactory)11 Nullable (org.jetbrains.annotations.Nullable)11 TextRange (com.intellij.openapi.util.TextRange)10 Project (com.intellij.openapi.project.Project)9 IElementType (com.intellij.psi.tree.IElementType)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 LogicalPosition (com.intellij.openapi.editor.LogicalPosition)7 EditorColorsScheme (com.intellij.openapi.editor.colors.EditorColorsScheme)7 PsiFile (com.intellij.psi.PsiFile)7 BraceMatcher (com.intellij.codeInsight.highlighting.BraceMatcher)6 EditorGutterComponentEx (com.intellij.openapi.editor.ex.EditorGutterComponentEx)6 RangeHighlighter (com.intellij.openapi.editor.markup.RangeHighlighter)6 FileType (com.intellij.openapi.fileTypes.FileType)6 Language (com.intellij.lang.Language)5