Search in sources :

Example 61 with Editor

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

the class IntroduceVariableValidatorTest method processFile.

private String processFile(String fileText) throws IncorrectOperationException, InvalidDataException, IOException {
    String result = "";
    int startOffset = fileText.indexOf(TestUtils.BEGIN_MARKER);
    if (startOffset < 0) {
        startOffset = fileText.indexOf(ALL_MARKER);
        replaceAllOccurences = true;
        fileText = IntroduceVariableTest.removeAllMarker(fileText);
    } else {
        replaceAllOccurences = false;
        fileText = TestUtils.removeBeginMarker(fileText);
    }
    int endOffset = fileText.indexOf(TestUtils.END_MARKER);
    fileText = TestUtils.removeEndMarker(fileText);
    myFixture.configureByText(GroovyFileType.GROOVY_FILE_TYPE, fileText);
    Editor myEditor = myFixture.getEditor();
    myEditor.getSelectionModel().setSelection(startOffset, endOffset);
    GrExpression selectedExpr = PsiImplUtil.findElementInRange(myFixture.getFile(), startOffset, endOffset, GrExpression.class);
    Assert.assertNotNull("Selected expression reference points to null", selectedExpr);
    final PsiElement tempContainer = GrIntroduceHandlerBase.getEnclosingContainer(selectedExpr);
    Assert.assertTrue(tempContainer instanceof GroovyPsiElement);
    PsiElement[] occurences = GroovyRefactoringUtil.getExpressionOccurrences(PsiUtil.skipParentheses(selectedExpr, false), tempContainer);
    String varName = "preved";
    GroovyVariableValidator validator = new GroovyVariableValidator(new GrIntroduceContextImpl(getProject(), myEditor, selectedExpr, null, null, occurences, tempContainer));
    result = validator.isOKTest(varName, replaceAllOccurences);
    return result;
}
Also used : GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) Editor(com.intellij.openapi.editor.Editor) GroovyVariableValidator(org.jetbrains.plugins.groovy.refactoring.introduce.variable.GroovyVariableValidator) GrIntroduceContextImpl(org.jetbrains.plugins.groovy.refactoring.introduce.GrIntroduceContextImpl) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)

Example 62 with Editor

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

the class XPathAction method isEnabled.

protected boolean isEnabled(AnActionEvent event, boolean checkAvailable) {
    final Project project = event.getProject();
    if (project == null) {
        // no active project
        return false;
    }
    Editor editor = CommonDataKeys.EDITOR.getData(event.getDataContext());
    if (editor == null) {
        FileEditorManager fem = FileEditorManager.getInstance(project);
        editor = fem.getSelectedTextEditor();
    }
    if (editor == null) {
        return false;
    }
    // do we have an xml file?
    final PsiDocumentManager cem = PsiDocumentManager.getInstance(project);
    final PsiFile psiFile = cem.getPsiFile(editor.getDocument());
    // this is also true for DTD documents...
    if (!(psiFile instanceof XmlFile) || psiFile.getLanguage() == StdFileTypes.DTD.getLanguage()) {
        return false;
    }
    return !checkAvailable || isEnabledAt((XmlFile) psiFile, editor.getCaretModel().getOffset());
}
Also used : Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) XmlFile(com.intellij.psi.xml.XmlFile) PsiFile(com.intellij.psi.PsiFile) Editor(com.intellij.openapi.editor.Editor) PsiDocumentManager(com.intellij.psi.PsiDocumentManager)

Example 63 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 64 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 65 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)

Aggregations

Editor (com.intellij.openapi.editor.Editor)748 Project (com.intellij.openapi.project.Project)281 PsiFile (com.intellij.psi.PsiFile)171 VirtualFile (com.intellij.openapi.vfs.VirtualFile)122 NotNull (org.jetbrains.annotations.NotNull)110 Document (com.intellij.openapi.editor.Document)108 PsiElement (com.intellij.psi.PsiElement)107 Nullable (org.jetbrains.annotations.Nullable)103 TextRange (com.intellij.openapi.util.TextRange)77 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)29 DataContext (com.intellij.openapi.actionSystem.DataContext)27 ApplicationManager (com.intellij.openapi.application.ApplicationManager)25 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)25 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)22