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;
}
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());
}
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();
}
});
}
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();
});
}
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;
}
};
}
Aggregations