use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class XDebuggerInlayUtil method clearInlays.
public static void clearInlays(@NotNull Project project) {
UIUtil.invokeLaterIfNeeded(() -> {
FileEditor[] editors = FileEditorManager.getInstance(project).getAllEditors();
for (FileEditor editor : editors) {
if (editor instanceof TextEditor) {
Editor e = ((TextEditor) editor).getEditor();
List<Inlay> existing = e.getInlayModel().getInlineElementsInRange(0, e.getDocument().getTextLength());
for (Inlay inlay : existing) {
if (inlay.getRenderer() instanceof MyRenderer) {
Disposer.dispose(inlay);
}
}
}
}
});
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class ExecutionPointHighlighter method doShow.
private void doShow(boolean navigate) {
ApplicationManager.getApplication().assertIsDispatchThread();
if (ApplicationManager.getApplication().isUnitTestMode())
return;
removeHighlighter();
OpenFileDescriptor fileDescriptor = myOpenFileDescriptor;
if (!navigate && myOpenFileDescriptor != null) {
fileDescriptor = new OpenFileDescriptor(myProject, myOpenFileDescriptor.getFile());
}
myEditor = null;
if (fileDescriptor != null) {
if (!navigate) {
FileEditor editor = FileEditorManager.getInstance(fileDescriptor.getProject()).getSelectedEditor(fileDescriptor.getFile());
if (editor instanceof TextEditor) {
myEditor = ((TextEditor) editor).getEditor();
}
}
if (myEditor == null) {
myEditor = XDebuggerUtilImpl.createEditor(fileDescriptor);
}
}
if (myEditor != null) {
addHighlighter();
}
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class TransferableFileEditorStateSupport method processContextHints.
public void processContextHints(@NotNull DiffRequest request, @NotNull DiffContext context) {
if (!isEnabled())
return;
for (BinaryEditorHolder holder : myHolders) {
FileEditor editor = holder.getEditor();
TransferableFileEditorState state = getEditorState(holder.getEditor());
if (state != null) {
readContextData(context, editor, state);
}
}
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class InheritorChooser method runMethodInAbstractClass.
public boolean runMethodInAbstractClass(final ConfigurationContext context, final Runnable performRunnable, final PsiMethod psiMethod, final PsiClass containingClass, final Condition<PsiClass> acceptAbstractCondition) {
if (containingClass != null && acceptAbstractCondition.value(containingClass)) {
final Location location = context.getLocation();
if (location instanceof MethodLocation) {
final PsiClass aClass = ((MethodLocation) location).getContainingClass();
if (aClass != null && !aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
return false;
}
} else if (location instanceof PsiMemberParameterizedLocation) {
return false;
}
final List<PsiClass> classes = new ArrayList<>();
if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
final boolean isJUnit5 = ReadAction.compute(() -> JUnitUtil.isJUnit5(containingClass));
ClassInheritorsSearch.search(containingClass).forEach(aClass -> {
if (isJUnit5 && JUnitUtil.isJUnit5TestClass(aClass, true) || PsiClassUtil.isRunnableClass(aClass, true, true)) {
classes.add(aClass);
}
return true;
});
}, "Search for " + containingClass.getQualifiedName() + " inheritors", true, containingClass.getProject())) {
return true;
}
if (classes.size() == 1) {
runForClass(classes.get(0), psiMethod, context, performRunnable);
return true;
}
if (classes.isEmpty())
return false;
final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(context.getDataContext());
if (fileEditor instanceof TextEditor) {
final Document document = ((TextEditor) fileEditor).getEditor().getDocument();
final PsiFile containingFile = PsiDocumentManager.getInstance(context.getProject()).getPsiFile(document);
if (containingFile instanceof PsiClassOwner) {
final List<PsiClass> psiClasses = new ArrayList<>(Arrays.asList(((PsiClassOwner) containingFile).getClasses()));
psiClasses.retainAll(classes);
if (psiClasses.size() == 1) {
runForClass(psiClasses.get(0), psiMethod, context, performRunnable);
return true;
}
}
}
final int numberOfInheritors = classes.size();
final PsiClassListCellRenderer renderer = new PsiClassListCellRenderer() {
@Override
protected boolean customizeNonPsiElementLeftRenderer(ColoredListCellRenderer renderer, JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value == null) {
renderer.append("All (" + numberOfInheritors + ")");
return true;
}
return super.customizeNonPsiElementLeftRenderer(renderer, list, value, index, selected, hasFocus);
}
};
Collections.sort(classes, renderer.getComparator());
//suggest to run all inherited tests
classes.add(0, null);
final JBList list = new JBList(classes);
list.setCellRenderer(renderer);
JBPopupFactory.getInstance().createListPopupBuilder(list).setTitle("Choose executable classes to run " + (psiMethod != null ? psiMethod.getName() : containingClass.getName())).setMovable(false).setResizable(false).setRequestFocus(true).setItemChoosenCallback(() -> {
final Object[] values = list.getSelectedValues();
if (values == null)
return;
chooseAndPerform(values, psiMethod, context, performRunnable, classes);
}).createPopup().showInBestPositionFor(context.getDataContext());
return true;
}
return false;
}
use of com.intellij.openapi.fileEditor.FileEditor in project intellij-community by JetBrains.
the class EditorWindow method syncCaretIfPossible.
/**
* Tries to setup caret and viewport for the given editor from the selected one.
*
* @param toSync editor to setup caret and viewport for
*/
private void syncCaretIfPossible(@Nullable FileEditor[] toSync) {
if (toSync == null) {
return;
}
final EditorWithProviderComposite from = getSelectedEditor();
if (from == null) {
return;
}
final FileEditor caretSource = from.getSelectedEditor();
if (!(caretSource instanceof TextEditor)) {
return;
}
final Editor editorFrom = ((TextEditor) caretSource).getEditor();
final int offset = editorFrom.getCaretModel().getOffset();
if (offset <= 0) {
return;
}
final int scrollOffset = editorFrom.getScrollingModel().getVerticalScrollOffset();
for (FileEditor fileEditor : toSync) {
if (!(fileEditor instanceof TextEditor)) {
continue;
}
final Editor editor = ((TextEditor) fileEditor).getEditor();
if (editorFrom.getDocument() == editor.getDocument()) {
editor.getCaretModel().moveToOffset(offset);
final ScrollingModel scrollingModel = editor.getScrollingModel();
scrollingModel.scrollVertically(scrollOffset);
SwingUtilities.invokeLater(() -> {
if (!editor.isDisposed()) {
scrollingModel.scrollToCaret(ScrollType.MAKE_VISIBLE);
}
});
}
}
}
Aggregations