use of com.intellij.openapi.fileEditor.FileDocumentManagerAdapter in project intellij-community by JetBrains.
the class ConsoleHistoryController method install.
public void install() {
class Listener extends FileDocumentManagerAdapter implements ProjectEx.ProjectSaved {
@Override
public void beforeDocumentSaving(@NotNull Document document) {
if (document == myConsole.getEditorDocument()) {
saveHistory();
}
}
@Override
public void saved(@NotNull Project project) {
saveHistory();
}
}
Listener listener = new Listener();
ApplicationManager.getApplication().getMessageBus().connect(myConsole).subscribe(ProjectEx.ProjectSaved.TOPIC, listener);
myConsole.getProject().getMessageBus().connect(myConsole).subscribe(AppTopics.FILE_DOCUMENT_SYNC, listener);
myConsole.getVirtualFile().putUserData(CONTROLLER_KEY, this);
Disposer.register(myConsole, new Disposable() {
@Override
public void dispose() {
myConsole.getVirtualFile().putUserData(CONTROLLER_KEY, null);
saveHistory();
}
});
if (myHelper.getModel().getHistorySize() == 0) {
loadHistory(myHelper.getId());
}
configureActions();
myLastSaveStamp = getCurrentTimeStamp();
}
use of com.intellij.openapi.fileEditor.FileDocumentManagerAdapter in project intellij-community by JetBrains.
the class FileDocumentManagerImplTest method testReplaceDocumentTextWithTheSameText.
public void testReplaceDocumentTextWithTheSameText() throws Exception {
final VirtualFile file = createFile();
final DocumentEx document = (DocumentEx) myDocumentManager.getDocument(file);
assertNotNull(file.toString(), document);
WriteCommandAction.runWriteCommandAction(myProject, () -> {
final String newText = "test text";
document.replaceString(0, document.getTextLength(), newText);
assertTrue(myDocumentManager.isDocumentUnsaved(document));
myDocumentManager.saveDocument(document);
getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {
@Override
public void beforeDocumentSaving(@NotNull Document documentToSave) {
assertNotSame(document, documentToSave);
}
});
final long modificationStamp = document.getModificationStamp();
document.replaceString(0, document.getTextLength(), newText);
if (myDocumentManager.isDocumentUnsaved(document)) {
assertTrue(document.getModificationStamp() > modificationStamp);
} else {
assertEquals(modificationStamp, document.getModificationStamp());
}
});
}
use of com.intellij.openapi.fileEditor.FileDocumentManagerAdapter in project intellij-community by JetBrains.
the class FileDocumentManagerImplTest method testSaveDocument_DoNotSaveIfModStampEqualsToFile.
public void testSaveDocument_DoNotSaveIfModStampEqualsToFile() throws Exception {
final VirtualFile file = createFile();
final DocumentEx document = (DocumentEx) myDocumentManager.getDocument(file);
assertNotNull(file.toString(), document);
WriteCommandAction.runWriteCommandAction(myProject, () -> {
document.insertString(0, "zzz");
document.setModificationStamp(file.getModificationStamp());
});
getProject().getMessageBus().connect(getTestRootDisposable()).subscribe(AppTopics.FILE_DOCUMENT_SYNC, new FileDocumentManagerAdapter() {
@Override
public void beforeDocumentSaving(@NotNull Document documentToSave) {
assertNotSame(document, documentToSave);
}
});
myDocumentManager.saveDocument(document);
}
Aggregations