use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class CodeSmellDetectorImpl method showCodeSmellErrors.
@Override
public void showCodeSmellErrors(@NotNull final List<CodeSmellInfo> smellList) {
Collections.sort(smellList, new Comparator<CodeSmellInfo>() {
@Override
public int compare(final CodeSmellInfo o1, final CodeSmellInfo o2) {
return o1.getTextRange().getStartOffset() - o2.getTextRange().getStartOffset();
}
});
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
if (myProject.isDisposed())
return;
if (smellList.isEmpty()) {
return;
}
final VcsErrorViewPanel errorTreeView = new VcsErrorViewPanel(myProject);
AbstractVcsHelperImpl helper = (AbstractVcsHelperImpl) AbstractVcsHelper.getInstance(myProject);
helper.openMessagesView(errorTreeView, VcsBundle.message("code.smells.error.messages.tab.name"));
FileDocumentManager fileManager = FileDocumentManager.getInstance();
for (CodeSmellInfo smellInfo : smellList) {
final VirtualFile file = fileManager.getFile(smellInfo.getDocument());
final OpenFileDescriptor navigatable = new OpenFileDescriptor(myProject, file, smellInfo.getStartLine(), smellInfo.getStartColumn());
final String exportPrefix = NewErrorTreeViewPanel.createExportPrefix(smellInfo.getStartLine() + 1);
final String rendererPrefix = NewErrorTreeViewPanel.createRendererPrefix(smellInfo.getStartLine() + 1, smellInfo.getStartColumn() + 1);
if (smellInfo.getSeverity() == HighlightSeverity.ERROR) {
errorTreeView.addMessage(MessageCategory.ERROR, new String[] { smellInfo.getDescription() }, file.getPresentableUrl(), navigatable, exportPrefix, rendererPrefix, null);
} else {
//if (smellInfo.getSeverity() == HighlightSeverity.WARNING) {
errorTreeView.addMessage(MessageCategory.WARNING, new String[] { smellInfo.getDescription() }, file.getPresentableUrl(), navigatable, exportPrefix, rendererPrefix, null);
}
}
}
});
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class ActionsTest method saveDocument.
private static void saveDocument(VirtualFile f) {
FileDocumentManager dm = FileDocumentManager.getInstance();
Document document = dm.getDocument(f);
assertNotNull(f.getPath(), document);
dm.saveDocument(document);
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class FileEncodingTest method testUndoChangeEncoding.
public void testUndoChangeEncoding() throws IOException {
VirtualFile file = createTempFile("txt", null, "xxx", CharsetToolkit.UTF8_CHARSET);
file.setCharset(CharsetToolkit.UTF8_CHARSET);
UIUtil.dispatchAllInvocationEvents();
assertEquals(CharsetToolkit.UTF8_CHARSET, file.getCharset());
FileDocumentManager documentManager = FileDocumentManager.getInstance();
assertNull(documentManager.getCachedDocument(file));
change(file, WINDOWS_1251);
assertEquals(WINDOWS_1251, file.getCharset());
Document document = documentManager.getDocument(file);
change(file, CharsetToolkit.UTF8_CHARSET);
assertEquals(CharsetToolkit.UTF8_CHARSET, file.getCharset());
globalUndo();
UIUtil.dispatchAllInvocationEvents();
assertEquals(WINDOWS_1251, file.getCharset());
document.getText();
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class EditorImpl method processKeyTyped.
private boolean processKeyTyped(char c) {
// [vova] This is patch for Mac OS X. Under Mac "input methods"
// is handled before our EventQueue consume upcoming KeyEvents.
IdeEventQueue queue = IdeEventQueue.getInstance();
if (queue.shouldNotTypeInEditor() || ProgressManager.getInstance().hasModalProgressIndicator()) {
return false;
}
FileDocumentManager manager = FileDocumentManager.getInstance();
final VirtualFile file = manager.getFile(myDocument);
if (file != null && !file.isValid()) {
return false;
}
DataContext context = getDataContext();
Graphics graphics = GraphicsUtil.safelyGetGraphics(myEditorComponent);
if (graphics != null) {
// editor component is not showing
processKeyTypedImmediately(c, graphics, context);
graphics.dispose();
}
ActionManagerEx.getInstanceEx().fireBeforeEditorTyping(c, context);
EditorUIUtil.hideCursorInEditor(this);
processKeyTypedNormally(c, context);
return true;
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class TrailingSpacesStripper method strip.
private void strip(@NotNull final Document document) {
if (!document.isWritable())
return;
FileDocumentManager fileDocumentManager = FileDocumentManager.getInstance();
VirtualFile file = fileDocumentManager.getFile(document);
if (file == null || !file.isValid() || Boolean.TRUE.equals(DISABLE_FOR_FILE_KEY.get(file)))
return;
final EditorSettingsExternalizable settings = EditorSettingsExternalizable.getInstance();
if (settings == null)
return;
final String overrideStripTrailingSpacesData = file.getUserData(OVERRIDE_STRIP_TRAILING_SPACES_KEY);
final Boolean overrideEnsureNewlineData = file.getUserData(OVERRIDE_ENSURE_NEWLINE_KEY);
@EditorSettingsExternalizable.StripTrailingSpaces String stripTrailingSpaces = overrideStripTrailingSpacesData != null ? overrideStripTrailingSpacesData : settings.getStripTrailingSpaces();
final boolean doStrip = !stripTrailingSpaces.equals(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_NONE);
final boolean ensureEOL = overrideEnsureNewlineData != null ? overrideEnsureNewlineData.booleanValue() : settings.isEnsureNewLineAtEOF();
if (doStrip) {
final boolean inChangedLinesOnly = !stripTrailingSpaces.equals(EditorSettingsExternalizable.STRIP_TRAILING_SPACES_WHOLE);
boolean success = strip(document, inChangedLinesOnly, settings.isKeepTrailingSpacesOnCaretLine());
if (!success) {
myDocumentsToStripLater.add(document);
}
}
final int lines = document.getLineCount();
if (ensureEOL && lines > 0) {
final int start = document.getLineStartOffset(lines - 1);
final int end = document.getLineEndOffset(lines - 1);
if (start != end) {
final CharSequence content = document.getCharsSequence();
ApplicationManager.getApplication().runWriteAction(new DocumentRunnable(document, null) {
@Override
public void run() {
CommandProcessor.getInstance().runUndoTransparentAction(() -> {
if (CharArrayUtil.containsOnlyWhiteSpaces(content.subSequence(start, end)) && doStrip) {
document.deleteString(start, end);
} else {
document.insertString(end, "\n");
}
});
}
});
}
}
}
Aggregations