use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method testGetBufferForDocument.
@Test
public void testGetBufferForDocument() throws Exception {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer buffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
assertNotNull(buffer);
IDocument document = buffer.getDocument();
assertNotNull(document);
assertSame(buffer, fManager.getTextFileBuffer(document));
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class FileBufferFunctions method test6.
/*
* Test revert.
*/
@Test
public void test6() throws Exception {
fManager.connect(fPath, LocationKind.NORMALIZE, null);
try {
ITextFileBuffer fileBuffer = fManager.getTextFileBuffer(fPath, LocationKind.NORMALIZE);
// set dirty bit
IDocument document = fileBuffer.getDocument();
String originalContent = document.get();
document.replace(document.getLength(), 0, "appendix");
// invalidate synchronization state
IFileStore fileStore = FileBuffers.getFileStoreAtLocation(fPath);
IFileInfo fileInfo = fileStore.fetchInfo();
fileInfo.setLastModified(1000);
if (fileInfo.exists())
fileStore.putInfo(fileInfo, EFS.SET_LAST_MODIFIED, null);
// revert
fileBuffer.revert(null);
// check assertions
assertEquals(originalContent, document.get());
assertFalse(fileBuffer.isDirty());
assertTrue(fileBuffer.isSynchronized());
} finally {
fManager.disconnect(fPath, LocationKind.NORMALIZE, null);
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class TextFileDocumentProvider method createFileFromDocument.
/**
* Creates the given file with the given document content.
*
* @param monitor the progress monitor
* @param file the file to be created
* @param document the document to be written to the file
* @throws CoreException if the creation of the file fails
*/
protected void createFileFromDocument(IProgressMonitor monitor, IFile file, IDocument document) throws CoreException {
try {
monitor.beginTask(TextEditorMessages.TextFileDocumentProvider_beginTask_saving, 2000);
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
manager.connect(file.getFullPath(), LocationKind.IFILE, monitor);
ITextFileBuffer buffer = ITextFileBufferManager.DEFAULT.getTextFileBuffer(file.getFullPath(), LocationKind.IFILE);
buffer.getDocument().set(document.get());
buffer.commit(monitor, true);
manager.disconnect(file.getFullPath(), LocationKind.IFILE, monitor);
} finally {
monitor.done();
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class EncodingChangeTests method testAInvalidEncoding.
@Test
public void testAInvalidEncoding() {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
try {
fFile.setCharset("nonexistent", null);
} catch (CoreException e2) {
fail();
}
try {
fEditor = IDE.openEditor(page, fFile);
if (fEditor instanceof TextEditor) {
TextEditor editor = (TextEditor) fEditor;
Accessor accessor = new Accessor(editor, StatusTextEditor.class);
while (editor.getSite().getShell().getDisplay().readAndDispatch()) {
}
ITextFileBuffer fileBuffer = FileBuffers.getTextFileBufferManager().getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
DefaultEncodingSupport encodingSupport = (DefaultEncodingSupport) editor.getAdapter(IEncodingSupport.class);
String expected = encodingSupport.getStatusMessage(fileBuffer.getStatus());
Composite composite = (Composite) accessor.get("fStatusControl");
ScrolledComposite scrolledComposite = (ScrolledComposite) composite.getChildren()[0];
StyledText statusText = (StyledText) ((Composite) scrolledComposite.getContent()).getChildren()[5];
String actual = statusText.getText();
assertEquals(expected, actual);
} else
fail();
} catch (PartInitException e) {
fail();
}
}
use of org.eclipse.core.filebuffers.ITextFileBuffer in project eclipse.platform.text by eclipse.
the class AnnotationHighlighter method handleContentReplaced.
@Override
protected void handleContentReplaced(IFileBuffer buffer) {
if (!(buffer instanceof ITextFileBuffer))
return;
ITextFileBuffer textBuffer = (ITextFileBuffer) buffer;
if (fDocument != null && fDocument.equals(textBuffer.getDocument())) {
Set<Match> allMatches = fMatchesToAnnotations.keySet();
Match[] matchesCopy = allMatches.toArray(new Match[allMatches.size()]);
removeAll();
addHighlights(matchesCopy);
}
}
Aggregations