Search in sources :

Example 46 with ITextFileBuffer

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);
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 47 with ITextFileBuffer

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);
    }
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IFileStore(org.eclipse.core.filesystem.IFileStore) IDocument(org.eclipse.jface.text.IDocument) Test(org.junit.Test)

Example 48 with ITextFileBuffer

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();
    }
}
Also used : ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer)

Example 49 with ITextFileBuffer

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();
    }
}
Also used : DefaultEncodingSupport(org.eclipse.ui.editors.text.DefaultEncodingSupport) StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) IEncodingSupport(org.eclipse.ui.editors.text.IEncodingSupport) Accessor(org.eclipse.text.tests.Accessor) IWorkbench(org.eclipse.ui.IWorkbench) StatusTextEditor(org.eclipse.ui.texteditor.StatusTextEditor) TextEditor(org.eclipse.ui.editors.text.TextEditor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) PartInitException(org.eclipse.ui.PartInitException) Test(org.junit.Test)

Example 50 with ITextFileBuffer

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);
    }
}
Also used : ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) Match(org.eclipse.search.ui.text.Match)

Aggregations

ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)133 Test (org.junit.Test)85 IDocument (org.eclipse.jface.text.IDocument)54 IFileBuffer (org.eclipse.core.filebuffers.IFileBuffer)37 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)35 IPath (org.eclipse.core.runtime.IPath)31 IFile (org.eclipse.core.resources.IFile)18 BadLocationException (org.eclipse.jface.text.BadLocationException)15 IFileStore (org.eclipse.core.filesystem.IFileStore)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 CoreException (org.eclipse.core.runtime.CoreException)8 Position (org.eclipse.jface.text.Position)8 IFileInfo (org.eclipse.core.filesystem.IFileInfo)7 IAnnotationModel (org.eclipse.jface.text.source.IAnnotationModel)7 Match (org.eclipse.search.ui.text.Match)7 IFolder (org.eclipse.core.resources.IFolder)5 IStatus (org.eclipse.core.runtime.IStatus)5 Path (org.eclipse.core.runtime.Path)5 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)5 Status (org.eclipse.core.runtime.Status)4