Search in sources :

Example 26 with UndoEdit

use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testMoveWithTargetDelete.

@Test
public void testMoveWithTargetDelete() throws Exception {
    MoveSourceEdit s1 = new MoveSourceEdit(2, 3);
    MoveTargetEdit t1 = new MoveTargetEdit(7, s1);
    TextEdit e2 = new DeleteEdit(6, 2);
    e2.addChild(t1);
    fRoot.addChild(s1);
    fRoot.addChild(e2);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "01589", fDocument.get());
    assertEquals(s1, 2, 0);
    assertTrue(t1.isDeleted());
    assertEquals(e2, 3, 0);
    doUndoRedo(undo, "01589");
}
Also used : MoveTargetEdit(org.eclipse.text.edits.MoveTargetEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) MoveSourceEdit(org.eclipse.text.edits.MoveSourceEdit) DeleteEdit(org.eclipse.text.edits.DeleteEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) Test(org.junit.Test)

Example 27 with UndoEdit

use of org.eclipse.text.edits.UndoEdit in project eclipse.platform.text by eclipse.

the class TextEditTests method testTreeUpdate1.

@Test
public void testTreeUpdate1() throws Exception {
    MultiTextEdit m1 = new MultiTextEdit();
    TextEdit e1 = new InsertEdit(2, "aa");
    TextEdit e2 = new InsertEdit(4, "bb");
    m1.addChild(e1);
    m1.addChild(e2);
    MultiTextEdit m2 = new MultiTextEdit();
    TextEdit e3 = new InsertEdit(6, "cc");
    TextEdit e4 = new InsertEdit(8, "dd");
    m2.addChild(e3);
    m2.addChild(e4);
    fRoot.addChild(m1);
    fRoot.addChild(m2);
    assertEquals(m1, 2, 2);
    assertEquals(m2, 6, 2);
    UndoEdit undo = fRoot.apply(fDocument);
    Assert.assertEquals("Buffer content", "01aa23bb45cc67dd89", fDocument.get());
    assertEquals(e1, 2, 2);
    assertEquals(e2, 6, 2);
    assertEquals(e3, 10, 2);
    assertEquals(e4, 14, 2);
    assertEquals(m1, 2, 6);
    assertEquals(m2, 10, 6);
    assertEquals(fRoot, 2, 14);
    doUndoRedo(undo, "01aa23bb45cc67dd89");
}
Also used : InsertEdit(org.eclipse.text.edits.InsertEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) TextEdit(org.eclipse.text.edits.TextEdit) UndoEdit(org.eclipse.text.edits.UndoEdit) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) Test(org.junit.Test)

Example 28 with UndoEdit

use of org.eclipse.text.edits.UndoEdit in project che by eclipse.

the class TextChange method perform.

/**
	 * {@inheritDoc}
	 */
public Change perform(IProgressMonitor pm) throws CoreException {
    //$NON-NLS-1$
    pm.beginTask("", 3);
    IDocument document = null;
    try {
        document = acquireDocument(new SubProgressMonitor(pm, 1));
        UndoEdit undo = performEdits(document);
        commit(document, new SubProgressMonitor(pm, 1));
        return createUndoChange(undo);
    } catch (BadLocationException e) {
        throw Changes.asCoreException(e);
    } catch (MalformedTreeException e) {
        throw Changes.asCoreException(e);
    } finally {
        releaseDocument(document, new SubProgressMonitor(pm, 1));
        pm.done();
    }
}
Also used : MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) UndoEdit(org.eclipse.text.edits.UndoEdit) IDocument(org.eclipse.jface.text.IDocument) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 29 with UndoEdit

use of org.eclipse.text.edits.UndoEdit in project che by eclipse.

the class UndoTextFileChange method perform.

/**
	 * {@inheritDoc}
	 */
public Change perform(IProgressMonitor pm) throws CoreException {
    if (pm == null)
        pm = new NullProgressMonitor();
    ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
    //$NON-NLS-1$
    pm.beginTask("", 2);
    ITextFileBuffer buffer = null;
    try {
        manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
        buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
        IDocument document = buffer.getDocument();
        ContentStamp currentStamp = ContentStamps.get(fFile, document);
        boolean[] setContentStampSuccess = { false };
        UndoEdit redo = performEdits(buffer, document, setContentStampSuccess);
        if (needsSaving()) {
            buffer.commit(pm, false);
            if (!setContentStampSuccess[0]) {
                // We weren't able to restore document stamp.
                // Since we save restore the file stamp instead
                ContentStamps.set(fFile, fContentStampToRestore);
            }
        }
        return createUndoChange(redo, currentStamp);
    } catch (BadLocationException e) {
        if (fValidationState == null || !fValidationState.wasDerived())
            throw Changes.asCoreException(e);
        else
            return new NullChange();
    } catch (MalformedTreeException e) {
        if (fValidationState == null || !fValidationState.wasDerived())
            throw Changes.asCoreException(e);
        else
            return new NullChange();
    } catch (CoreException e) {
        if (fValidationState == null || !fValidationState.wasDerived())
            throw e;
        else
            return new NullChange();
    } finally {
        if (buffer != null)
            manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) ITextFileBufferManager(org.eclipse.core.filebuffers.ITextFileBufferManager) ITextFileBuffer(org.eclipse.core.filebuffers.ITextFileBuffer) MalformedTreeException(org.eclipse.text.edits.MalformedTreeException) UndoEdit(org.eclipse.text.edits.UndoEdit) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) IDocument(org.eclipse.jface.text.IDocument) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 30 with UndoEdit

use of org.eclipse.text.edits.UndoEdit in project che by eclipse.

the class MultiStateTextFileChange method performChangesInSynchronizationContext.

private void performChangesInSynchronizationContext(final IDocument document, final LinkedList undoList, final boolean preview) throws BadLocationException {
    DocumentRewriteSession session = null;
    try {
        if (document instanceof IDocumentExtension4)
            session = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED);
        for (final Iterator iterator = fChanges.iterator(); iterator.hasNext(); ) {
            final ComposableBufferChange change = (ComposableBufferChange) iterator.next();
            final UndoEdit edit = createTextEditProcessor(change, document, undoList != null ? TextEdit.CREATE_UNDO : TextEdit.NONE, preview).performEdits();
            if (undoList != null)
                undoList.addFirst(edit);
        }
    } finally {
        if (session != null)
            ((IDocumentExtension4) document).stopRewriteSession(session);
    }
}
Also used : DocumentRewriteSession(org.eclipse.jface.text.DocumentRewriteSession) IDocumentExtension4(org.eclipse.jface.text.IDocumentExtension4) Iterator(java.util.Iterator) UndoEdit(org.eclipse.text.edits.UndoEdit)

Aggregations

UndoEdit (org.eclipse.text.edits.UndoEdit)53 Test (org.junit.Test)40 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)25 TextEdit (org.eclipse.text.edits.TextEdit)25 MoveSourceEdit (org.eclipse.text.edits.MoveSourceEdit)23 MoveTargetEdit (org.eclipse.text.edits.MoveTargetEdit)23 InsertEdit (org.eclipse.text.edits.InsertEdit)12 ReplaceEdit (org.eclipse.text.edits.ReplaceEdit)12 BadLocationException (org.eclipse.jface.text.BadLocationException)10 DeleteEdit (org.eclipse.text.edits.DeleteEdit)9 RangeMarker (org.eclipse.text.edits.RangeMarker)8 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)6 CopySourceEdit (org.eclipse.text.edits.CopySourceEdit)6 CopyTargetEdit (org.eclipse.text.edits.CopyTargetEdit)6 MalformedTreeException (org.eclipse.text.edits.MalformedTreeException)5 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)4 SubProgressMonitor (org.eclipse.core.runtime.SubProgressMonitor)4 IDocument (org.eclipse.jface.text.IDocument)4 Lock (org.eclipse.ltk.internal.core.refactoring.Lock)3 LinkedList (java.util.LinkedList)2