Search in sources :

Example 26 with Editor

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

the class InputExpressionDialog method setModeImpl.

protected void setModeImpl(Mode mode) {
    //        mySettingsPanel.setVisible(mode == Mode.ADVANCED);
    myForm.getEditContextButton().setVisible(mode == Mode.ADVANCED);
    if (mode == Mode.ADVANCED) {
        setEditor(myEditor, GridConstraints.SIZEPOLICY_WANT_GROW);
        myEditor.getField().selectAll();
    } else {
        setEditor(myComboBox, GridConstraints.SIZEPOLICY_FIXED);
        myComboBox.setModel(myModel);
        myComboBox.getEditor().selectAll();
    }
    SwingUtilities.invokeLater(() -> {
        final Editor editor = getEditor();
        if (editor != null) {
            editor.getContentComponent().grabFocus();
        }
    });
}
Also used : Editor(com.intellij.openapi.editor.Editor)

Example 27 with Editor

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

the class MultilineEditor method refocus.

private void refocus() {
    SwingUtilities.invokeLater(() -> {
        final Editor editor = myEditorTextField.getEditor();
        if (editor != null) {
            IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> {
                IdeFocusManager.getGlobalInstance().requestFocus(editor.getContentComponent(), true);
            });
        }
        myEditorTextField.selectAll();
    });
}
Also used : Editor(com.intellij.openapi.editor.Editor)

Example 28 with Editor

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

the class PyMainPostfixTemplate method getSurrounder.

@NotNull
@Override
protected Surrounder getSurrounder() {
    return new PyStatementSurrounder() {

        @Nullable
        @Override
        protected TextRange surroundStatement(@NotNull Project project, @NotNull Editor editor, @NotNull PsiElement[] elements) throws IncorrectOperationException {
            PyIfStatement ifStatement = PyElementGenerator.getInstance(project).createFromText(LanguageLevel.forElement(elements[0]), PyIfStatement.class, "if __name__ == '__main__':\n expr");
            ifStatement = (PyIfStatement) CodeStyleManager.getInstance(project).reformat(ifStatement);
            final PsiElement parent = elements[0].getParent();
            ifStatement = (PyIfStatement) parent.addBefore(ifStatement, elements[0]);
            final PyStatementList statementList = ifStatement.getIfPart().getStatementList();
            statementList.addRange(elements[0], elements[elements.length - 1]);
            statementList.getFirstChild().delete();
            parent.deleteChildRange(elements[0], elements[elements.length - 1]);
            return TextRange.from(statementList.getTextRange().getEndOffset(), 0);
        }

        @Override
        public String getTemplateDescription() {
            return DESCR;
        }
    };
}
Also used : PyStatementSurrounder(com.jetbrains.python.refactoring.surround.surrounders.statements.PyStatementSurrounder) Project(com.intellij.openapi.project.Project) PyIfStatement(com.jetbrains.python.psi.PyIfStatement) PyStatementList(com.jetbrains.python.psi.PyStatementList) Editor(com.intellij.openapi.editor.Editor) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 29 with Editor

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

the class PyBaseConvertCollectionLiteralIntention method findCollectionLiteralUnderCaret.

@Nullable
private static PySequenceExpression findCollectionLiteralUnderCaret(@NotNull Editor editor, @NotNull PsiFile psiFile) {
    final int caretOffset = editor.getCaretModel().getOffset();
    final PsiElement curElem = psiFile.findElementAt(caretOffset);
    final PySequenceExpression seqExpr = PsiTreeUtil.getParentOfType(curElem, PySequenceExpression.class);
    if (seqExpr != null) {
        return seqExpr;
    }
    final PyParenthesizedExpression paren = (PyParenthesizedExpression) PsiTreeUtil.findFirstParent(curElem, element -> {
        final PyParenthesizedExpression parenthesizedExpr = as(element, PyParenthesizedExpression.class);
        return parenthesizedExpr != null && parenthesizedExpr.getContainedExpression() instanceof PyTupleExpression;
    });
    return paren != null ? ((PyTupleExpression) paren.getContainedExpression()) : null;
}
Also used : PyBundle(com.jetbrains.python.PyBundle) IncorrectOperationException(com.intellij.util.IncorrectOperationException) PyTokenTypes(com.jetbrains.python.PyTokenTypes) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) PyUtil.as(com.jetbrains.python.psi.PyUtil.as) PyPsiUtils(com.jetbrains.python.psi.impl.PyPsiUtils) Nullable(org.jetbrains.annotations.Nullable) PsiTreeUtil(com.intellij.psi.util.PsiTreeUtil) Nls(org.jetbrains.annotations.Nls) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) com.jetbrains.python.psi(com.jetbrains.python.psi) NotNull(org.jetbrains.annotations.NotNull) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 30 with Editor

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

the class XmlVcsSelectionProvider method getSelection.

@Override
public VcsSelection getSelection(VcsContext context) {
    final Editor editor = context.getEditor();
    if (editor == null)
        return null;
    PsiElement psiElement = TargetElementUtil.findTargetElement(editor, TargetElementUtil.ELEMENT_NAME_ACCEPTED);
    if (psiElement == null || !psiElement.isValid()) {
        return null;
    }
    final String actionName;
    if (psiElement instanceof XmlTag) {
        actionName = VcsBundle.message("action.name.show.history.for.tag");
    } else if (psiElement instanceof XmlText) {
        actionName = VcsBundle.message("action.name.show.history.for.text");
    } else {
        return null;
    }
    TextRange textRange = psiElement.getTextRange();
    if (textRange == null) {
        return null;
    }
    VirtualFile virtualFile = psiElement.getContainingFile().getVirtualFile();
    if (virtualFile == null) {
        return null;
    }
    if (!virtualFile.isValid()) {
        return null;
    }
    Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    return new VcsSelection(document, textRange, actionName);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlText(com.intellij.psi.xml.XmlText) TextRange(com.intellij.openapi.util.TextRange) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

Editor (com.intellij.openapi.editor.Editor)745 Project (com.intellij.openapi.project.Project)280 PsiFile (com.intellij.psi.PsiFile)169 VirtualFile (com.intellij.openapi.vfs.VirtualFile)121 NotNull (org.jetbrains.annotations.NotNull)110 Document (com.intellij.openapi.editor.Document)108 PsiElement (com.intellij.psi.PsiElement)106 Nullable (org.jetbrains.annotations.Nullable)103 TextRange (com.intellij.openapi.util.TextRange)76 FileEditor (com.intellij.openapi.fileEditor.FileEditor)67 TextEditor (com.intellij.openapi.fileEditor.TextEditor)48 ArrayList (java.util.ArrayList)39 IncorrectOperationException (com.intellij.util.IncorrectOperationException)36 List (java.util.List)36 EditorEx (com.intellij.openapi.editor.ex.EditorEx)35 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)28 DataContext (com.intellij.openapi.actionSystem.DataContext)26 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)25 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)22