use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class EncodingProjectManagerImpl method reload.
private static void reload(@NotNull final VirtualFile virtualFile) {
ApplicationManager.getApplication().runWriteAction(() -> {
FileDocumentManager documentManager = FileDocumentManager.getInstance();
((VirtualFileListener) documentManager).contentsChanged(new VirtualFileEvent(null, virtualFile, virtualFile.getName(), virtualFile.getParent()));
});
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class EncodingUtil method reloadIn.
static void reloadIn(@NotNull final VirtualFile virtualFile, @NotNull final Charset charset) {
final FileDocumentManager documentManager = FileDocumentManager.getInstance();
if (documentManager.getCachedDocument(virtualFile) == null) {
// no need to reload document
EncodingManager.getInstance().setEncoding(virtualFile, charset);
return;
}
final Disposable disposable = Disposer.newDisposable();
MessageBusConnection connection = ApplicationManager.getApplication().getMessageBus().connect(disposable);
connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {
@Override
public void beforeFileContentReload(VirtualFile file, @NotNull Document document) {
if (!file.equals(virtualFile))
return;
// disconnect
Disposer.dispose(disposable);
EncodingManager.getInstance().setEncoding(file, charset);
LoadTextUtil.setCharsetWasDetectedFromBytes(file, null);
}
});
// if file was modified, the user will be asked here
try {
EncodingProjectManagerImpl.suppressReloadDuring(() -> ((VirtualFileListener) documentManager).contentsChanged(new VirtualFileEvent(null, virtualFile, virtualFile.getName(), virtualFile.getParent())));
} finally {
Disposer.dispose(disposable);
}
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class EncodingUtil method checkCanReload.
@NotNull
public static // returns pair (existing charset (null means N/A); failReason: null means enabled, notnull means disabled and contains error message)
Pair<Charset, String> checkCanReload(@NotNull VirtualFile virtualFile) {
if (virtualFile.isDirectory()) {
return Pair.create(null, REASON_FILE_IS_A_DIRECTORY);
}
FileDocumentManager documentManager = FileDocumentManager.getInstance();
Document document = documentManager.getDocument(virtualFile);
if (document == null)
return Pair.create(null, REASON_BINARY_FILE);
Charset charsetFromContent = ((EncodingManagerImpl) EncodingManager.getInstance()).computeCharsetFromContent(virtualFile);
Charset existing = virtualFile.getCharset();
String autoDetectedFrom = LoadTextUtil.wasCharsetDetectedFromBytes(virtualFile);
String failReason;
if (autoDetectedFrom != null) {
// no point changing encoding if it was auto-detected
failReason = "the encoding was " + autoDetectedFrom;
} else if (charsetFromContent != null) {
failReason = REASON_HARDCODED_IN_TEXT;
existing = charsetFromContent;
} else {
failReason = fileTypeDescriptionError(virtualFile);
}
return Pair.create(existing, failReason);
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class KillToWordEndActionTest method testSubsequentKillsInterruptedBySave.
public void testSubsequentKillsInterruptedBySave() throws Exception {
String text = "public class ParentCopy {\n" + " public Insets getBorderInsets(<caret>Component c) {\n" + " }\n" + " }";
configureFromFileText(getTestName(false) + ".java", text);
cutToLineEnd();
cutToLineEnd();
final FileDocumentManager manager = FileDocumentManager.getInstance();
manager.saveAllDocuments();
cutToLineEnd();
cutToLineEnd();
checkResultByText("public class ParentCopy {\n" + " public Insets getBorderInsets( }");
Object string = getContents();
assertEquals("Component c) {\n }\n", string);
}
use of com.intellij.openapi.fileEditor.FileDocumentManager in project intellij-community by JetBrains.
the class FileDocumentManagerImplTest method testFileTypeModificationDocumentPreservation.
public void testFileTypeModificationDocumentPreservation() throws Exception {
File ioFile = IoTestUtil.createTestFile("test.html", "<html>some text</html>");
VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile);
assertNotNull(ioFile.getPath(), file);
FileDocumentManager documentManager = FileDocumentManager.getInstance();
Document original = documentManager.getDocument(file);
assertNotNull(file.getPath(), original);
renameFile(file, "test.wtf");
Document afterRename = documentManager.getDocument(file);
assertTrue(afterRename + " != " + original, afterRename == original);
}
Aggregations