use of com.intellij.openapi.editor.Editor in project Main by SpartanRefactoring.
the class SpartanizerAction method getPsiElementFromContext.
/**
* @param e the action event
* @return the psiElement extracted from the event's context
**/
@Nullable
private PsiElement getPsiElementFromContext(AnActionEvent e) {
PsiFile psiFile = e.getData(LangDataKeys.PSI_FILE);
Editor editor = e.getData(PlatformDataKeys.EDITOR);
return psiFile == null || editor == null ? null : psiFile.findElementAt(editor.getCaretModel().getOffset());
}
use of com.intellij.openapi.editor.Editor in project Main by SpartanRefactoring.
the class SpartanizerAnnotator method annotate.
@Override
public void annotate(@NotNull final PsiElement e, @NotNull AnnotationHolder h) {
try {
if (!Spartanizer.canTip(e) || e.getContainingFile().getName().contains("Spartanizer"))
return;
Annotation annotation = h.createInfoAnnotation(e, "Spartanize This!");
annotation.registerFix(new IntentionAction() {
@SuppressWarnings("unchecked")
@Nls
@NotNull
@Override
public String getText() {
return Toolbox.getInstance().getTipper(e).description(e);
}
@Nls
@NotNull
@Override
public String getFamilyName() {
return "SpartanizerAction";
}
@Override
public boolean isAvailable(@NotNull Project __, Editor e, PsiFile f) {
return true;
}
@Override
public void invoke(@NotNull Project p, Editor ed, PsiFile f) throws IncorrectOperationException {
Spartanizer.spartanizeElement(e);
}
@Override
public boolean startInWriteAction() {
return false;
}
});
TextAttributesKey.createTextAttributesKey("");
annotation.setEnforcedTextAttributes((new TextAttributes(null, null, JBColor.BLUE, EffectType.WAVE_UNDERSCORE, 0)));
} catch (Throwable t) {
Logger l = new Logger(this.getClass());
l.error("", t);
}
}
use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class CreateFieldFix method doFix.
protected void doFix(@NotNull Project project, @NotNull @GrModifier.ModifierConstant String[] modifiers, @NotNull @NonNls String fieldName, @NotNull TypeConstraint[] typeConstraints, @NotNull PsiElement context) throws IncorrectOperationException {
JVMElementFactory factory = JVMElementFactories.getFactory(myTargetClass.getLanguage(), project);
if (factory == null)
return;
PsiField field = factory.createField(fieldName, PsiType.INT);
if (myTargetClass instanceof GroovyScriptClass) {
field.getModifierList().addAnnotation(GroovyCommonClassNames.GROOVY_TRANSFORM_FIELD);
}
for (@GrModifier.ModifierConstant String modifier : modifiers) {
PsiUtil.setModifierProperty(field, modifier, true);
}
field = CreateFieldFromUsageHelper.insertField(myTargetClass, field, context);
JavaCodeStyleManager.getInstance(project).shortenClassReferences(field.getParent());
Editor newEditor = IntentionUtils.positionCursor(project, myTargetClass.getContainingFile(), field);
Template template = CreateFieldFromUsageHelper.setupTemplate(field, typeConstraints, myTargetClass, newEditor, context, false);
TemplateManager manager = TemplateManager.getInstance(project);
manager.startTemplate(newEditor, template);
}
use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class GrExecuteCommandAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getProject();
final Editor editor = CommonDataKeys.EDITOR.getData(e.getDataContext());
final VirtualFile virtualFile = CommonDataKeys.VIRTUAL_FILE.getData(e.getDataContext());
if (project == null || editor == null || virtualFile == null)
return;
FileDocumentManager.getInstance().saveAllDocuments();
final Document document = editor.getDocument();
final TextRange selectedRange = EditorUtil.getSelectionInAnyMode(editor);
final String command = (selectedRange.isEmpty() ? document.getText() : document.getText(selectedRange));
final GroovyConsole existingConsole = virtualFile.getUserData(GroovyConsole.GROOVY_CONSOLE);
if (existingConsole == null) {
GroovyConsole.getOrCreateConsole(project, virtualFile, console -> console.execute(command));
} else {
existingConsole.execute(command);
}
}
use of com.intellij.openapi.editor.Editor in project intellij-community by JetBrains.
the class CCSubtaskChangeListener method subtaskChanged.
@Override
public void subtaskChanged(@NotNull Project project, @NotNull Task task, int oldSubtaskNumber, int newSubtaskNumber) {
VirtualFile taskDir = task.getTaskDir(project);
if (taskDir == null) {
return;
}
Course course = StudyTaskManager.getInstance(project).getCourse();
if (course == null) {
return;
}
StudyLanguageManager manager = StudyUtils.getLanguageManager(course);
if (manager == null) {
return;
}
String testFileName = manager.getTestFileName();
if (newSubtaskNumber != 0) {
String nameWithoutExtension = FileUtil.getNameWithoutExtension(testFileName);
String extension = FileUtilRt.getExtension(testFileName);
testFileName = nameWithoutExtension + EduNames.SUBTASK_MARKER + newSubtaskNumber + "." + extension;
}
VirtualFile newTestFile = taskDir.findChild(testFileName);
if (newTestFile == null) {
return;
}
FileEditorManager editorManager = FileEditorManager.getInstance(project);
List<VirtualFile> testFiles = ContainerUtil.filter(taskDir.getChildren(), file -> CCUtils.isTestsFile(project, file) && editorManager.isFileOpen(file));
if (testFiles.isEmpty()) {
return;
}
Editor selectedTextEditor = editorManager.getSelectedTextEditor();
for (VirtualFile testFile : testFiles) {
editorManager.closeFile(testFile);
}
editorManager.openFile(newTestFile, true);
if (selectedTextEditor != null) {
reopenSelectedEditor(editorManager, selectedTextEditor);
}
}
Aggregations