Search in sources :

Example 11 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)

Example 12 with UndoEdit

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

the class MultiStateTextFileChange method perform.

/*
	 * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
	 */
public final Change perform(final IProgressMonitor monitor) throws CoreException {
    //$NON-NLS-1$
    monitor.beginTask("", 3);
    IDocument document = null;
    try {
        document = acquireDocument(new SubProgressMonitor(monitor, 1));
        final LinkedList undoList = new LinkedList();
        performChanges(document, undoList, false);
        if (needsSaving())
            fBuffer.commit(new SubProgressMonitor(monitor, 1), false);
        return new MultiStateUndoChange(getName(), fFile, (UndoEdit[]) undoList.toArray(new UndoEdit[undoList.size()]), fContentStamp, fSaveMode);
    } catch (BadLocationException exception) {
        throw Changes.asCoreException(exception);
    } finally {
        if (document != null) {
            releaseDocument(document, new SubProgressMonitor(monitor, 1));
        }
        monitor.done();
    }
}
Also used : MultiStateUndoChange(org.eclipse.ltk.internal.core.refactoring.MultiStateUndoChange) UndoEdit(org.eclipse.text.edits.UndoEdit) IDocument(org.eclipse.jface.text.IDocument) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) LinkedList(java.util.LinkedList) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

UndoEdit (org.eclipse.text.edits.UndoEdit)12 BadLocationException (org.eclipse.jface.text.BadLocationException)10 ITextFileBufferManager (org.eclipse.core.filebuffers.ITextFileBufferManager)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 CoreException (org.eclipse.core.runtime.CoreException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 Iterator (java.util.Iterator)1 ASTNode (org.eclipse.jdt.core.dom.ASTNode)1 ASTRewrite (org.eclipse.jdt.core.dom.rewrite.ASTRewrite)1 DocumentRewriteSession (org.eclipse.jface.text.DocumentRewriteSession)1 IDocumentExtension4 (org.eclipse.jface.text.IDocumentExtension4)1 IRegion (org.eclipse.jface.text.IRegion)1 Change (org.eclipse.ltk.core.refactoring.Change)1 ContentStamp (org.eclipse.ltk.core.refactoring.ContentStamp)1 NullChange (org.eclipse.ltk.core.refactoring.NullChange)1