use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class FormatterTestCase method checkDocument.
protected void checkDocument(final PsiFile file, final String text, String textAfter) {
final Document document = PsiDocumentManager.getInstance(getProject()).getDocument(file);
final EditorImpl editor;
if (doCheckDocumentUpdate()) {
editor = (EditorImpl) FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), file.getVirtualFile(), 0), false);
editor.putUserData(EditorImpl.DO_DOCUMENT_UPDATE_TEST, Boolean.TRUE);
if (myFile != null) {
FileEditorManager.getInstance(getProject()).closeFile(myFile.getVirtualFile());
}
myEditor = editor;
myFile = file;
} else {
editor = null;
}
WriteCommandAction.runWriteCommandAction(getProject(), () -> {
document.replaceString(0, document.getTextLength(), text);
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
assertEquals(file.getText(), document.getText());
try {
if (doReformatRangeTest) {
CodeStyleManager.getInstance(getProject()).reformatRange(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset());
} else if (myTextRange != null) {
CodeStyleManager.getInstance(getProject()).reformatText(file, myTextRange.getStartOffset(), myTextRange.getEndOffset());
} else {
CodeStyleManager.getInstance(getProject()).reformatText(file, file.getTextRange().getStartOffset(), file.getTextRange().getEndOffset());
}
} catch (IncorrectOperationException e) {
fail();
}
});
assertEquals(textAfter, document.getText());
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
assertEquals(textAfter, file.getText());
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class AnnotateRevisionActionBase method annotate.
public static void annotate(@NotNull VirtualFile file, @NotNull VcsFileRevision fileRevision, @NotNull AbstractVcs vcs, @Nullable Editor editor, int annotatedLine) {
final CharSequence oldContent = editor == null ? null : editor.getDocument().getImmutableCharSequence();
final AnnotationProvider annotationProvider = vcs.getAnnotationProvider();
assert annotationProvider != null;
final Ref<FileAnnotation> fileAnnotationRef = new Ref<>();
final Ref<Integer> newLineRef = new Ref<>();
final Ref<VcsException> exceptionRef = new Ref<>();
VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).lock();
Semaphore semaphore = new Semaphore(0);
AtomicBoolean shouldOpenEditorInSync = new AtomicBoolean(true);
ProgressManager.getInstance().run(new Task.Backgroundable(vcs.getProject(), VcsBundle.message("retrieving.annotations"), true) {
public void run(@NotNull ProgressIndicator indicator) {
try {
FileAnnotation fileAnnotation = annotationProvider.annotate(file, fileRevision);
int newLine = translateLine(oldContent, fileAnnotation.getAnnotatedContent(), annotatedLine);
fileAnnotationRef.set(fileAnnotation);
newLineRef.set(newLine);
shouldOpenEditorInSync.set(false);
semaphore.release();
} catch (VcsException e) {
exceptionRef.set(e);
}
}
@Override
public void onFinished() {
VcsAnnotateUtil.getBackgroundableLock(vcs.getProject(), file).unlock();
}
@Override
public void onSuccess() {
if (!exceptionRef.isNull()) {
AbstractVcsHelper.getInstance(myProject).showError(exceptionRef.get(), VcsBundle.message("operation.name.annotate"));
}
if (fileAnnotationRef.isNull())
return;
AbstractVcsHelper.getInstance(myProject).showAnnotation(fileAnnotationRef.get(), file, vcs, newLineRef.get());
}
});
try {
semaphore.tryAcquire(ProgressWindow.DEFAULT_PROGRESS_DIALOG_POSTPONE_TIME_MILLIS, TimeUnit.MILLISECONDS);
// This will remove blinking on editor opening (step 1 - editor opens, step 2 - annotations are shown).
if (shouldOpenEditorInSync.get()) {
CharSequence content = LoadTextUtil.loadText(file);
int newLine = translateLine(oldContent, content, annotatedLine);
OpenFileDescriptor openFileDescriptor = new OpenFileDescriptor(vcs.getProject(), file, newLine, 0);
FileEditorManager.getInstance(vcs.getProject()).openTextEditor(openFileDescriptor, true);
}
} catch (InterruptedException ignore) {
}
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class LoadProjectTest method testLoadProject.
public void testLoadProject() throws Exception {
VirtualFile src = ProjectRootManager.getInstance(getProject()).getContentSourceRoots()[0];
VirtualFile a = src.findFileByRelativePath("/x/AClass.java");
assertNotNull(a);
PsiFile fileA = getPsiManager().findFile(a);
assertNotNull(fileA);
fileA.navigate(true);
Editor editorA = FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), a), true);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
assertNotNull(editorA);
CodeInsightTestFixtureImpl.instantiateAndRun(fileA, editorA, new int[] { Pass.EXTERNAL_TOOLS }, false);
VirtualFile b = src.findFileByRelativePath("/x/BClass.java");
assertNotNull(b);
PsiFile fileB = getPsiManager().findFile(b);
assertNotNull(fileB);
fileB.navigate(true);
Editor editorB = FileEditorManager.getInstance(getProject()).openTextEditor(new OpenFileDescriptor(getProject(), b), true);
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
assertNotNull(editorB);
CodeInsightTestFixtureImpl.instantiateAndRun(fileB, editorB, new int[] { Pass.EXTERNAL_TOOLS }, false);
FileEditor[] allEditors = FileEditorManager.getInstance(getProject()).getAllEditors();
assertEquals(2, allEditors.length);
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class ExternalSystemNotificationManager method addMessage.
private void addMessage(@NotNull final Notification notification, @NotNull final ProjectSystemId externalSystemId, @NotNull final NotificationData notificationData) {
final VirtualFile virtualFile = notificationData.getFilePath() != null ? ExternalSystemUtil.findLocalFileByPath(notificationData.getFilePath()) : null;
final String groupName = virtualFile != null ? virtualFile.getPresentableUrl() : notificationData.getTitle();
myMessageCounter.increment(groupName, notificationData.getNotificationSource(), notificationData.getNotificationCategory(), externalSystemId);
int line = notificationData.getLine() - 1;
int column = notificationData.getColumn() - 1;
if (virtualFile == null)
line = column = -1;
final int guiLine = line < 0 ? -1 : line + 1;
final int guiColumn = column < 0 ? 0 : column + 1;
final Navigatable navigatable = notificationData.getNavigatable() != null ? notificationData.getNavigatable() : virtualFile != null ? new OpenFileDescriptor(myProject, virtualFile, line, column) : NonNavigatable.INSTANCE;
final ErrorTreeElementKind kind = ErrorTreeElementKind.convertMessageFromCompilerErrorType(notificationData.getNotificationCategory().getMessageCategory());
final String[] message = notificationData.getMessage().split("\n");
final String exportPrefix = NewErrorTreeViewPanel.createExportPrefix(guiLine);
final String rendererPrefix = NewErrorTreeViewPanel.createRendererPrefix(guiLine, guiColumn);
UIUtil.invokeLaterIfNeeded(() -> {
boolean activate = notificationData.getNotificationCategory() == NotificationCategory.ERROR || notificationData.getNotificationCategory() == NotificationCategory.WARNING;
final NewErrorTreeViewPanel errorTreeView = prepareMessagesView(externalSystemId, notificationData.getNotificationSource(), activate);
final GroupingElement groupingElement = errorTreeView.getErrorViewStructure().getGroupingElement(groupName, null, virtualFile);
final NavigatableMessageElement navigatableMessageElement;
if (notificationData.hasLinks()) {
navigatableMessageElement = new EditableNotificationMessageElement(notification, kind, groupingElement, message, navigatable, exportPrefix, rendererPrefix);
} else {
navigatableMessageElement = new NotificationMessageElement(kind, groupingElement, message, navigatable, exportPrefix, rendererPrefix);
}
errorTreeView.getErrorViewStructure().addNavigatableMessage(groupName, navigatableMessageElement);
errorTreeView.updateTree();
});
}
use of com.intellij.openapi.fileEditor.OpenFileDescriptor in project intellij-community by JetBrains.
the class TreeView method createPanel.
private JPanel createPanel() {
createModel();
myTree = new MyTree();
myTree.setLineStyleAngled();
myTree.setRootVisible(false);
myTree.setShowsRootHandles(true);
myTree.updateUI();
myTree.setLargeModel(true);
myTree.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
OpenSourceUtil.openSourcesFrom(DataManager.getInstance().getDataContext(myTree), false);
}
}
});
myTree.addMouseListener(new PopupHandler() {
public void invokePopup(Component comp, int x, int y) {
popupInvoked(comp, x, y);
}
});
EditSourceOnDoubleClickHandler.install(myTree);
myAutoScrollToSourceHandler.install(myTree);
myOccurenceNavigatorSupport = new OccurenceNavigatorSupport(myTree) {
protected Navigatable createDescriptorForNode(DefaultMutableTreeNode node) {
if (!(node instanceof MessageNode)) {
return null;
}
MessageNode messageNode = (MessageNode) node;
AntBuildMessageView.MessageType type = messageNode.getType();
if (type != AntBuildMessageView.MessageType.MESSAGE && type != AntBuildMessageView.MessageType.ERROR) {
return null;
}
if (!isValid(messageNode.getFile())) {
return null;
}
return new OpenFileDescriptor(myProject, messageNode.getFile(), messageNode.getOffset());
}
@Nullable
public String getNextOccurenceActionName() {
return AntBundle.message("ant.execution.next.error.warning.action.name");
}
@Nullable
public String getPreviousOccurenceActionName() {
return AntBundle.message("ant.execution.previous.error.warning.action.name");
}
};
return JBUI.Panels.simplePanel(MessageTreeRenderer.install(myTree));
}
Aggregations