use of org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager in project webtools.sourceediting by eclipse.
the class StructuredTextViewer method endRecording.
private void endRecording(int cursorPosition, int selectionLength) {
IDocument doc = getDocument();
if (doc instanceof IStructuredDocument) {
IStructuredDocument structuredDocument = (IStructuredDocument) doc;
IStructuredTextUndoManager undoManager = structuredDocument.getUndoManager();
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=198617
// undo after paste in document with folds - wrong behavior
IRegion widgetSelection = new Region(cursorPosition, selectionLength);
IRegion documentSelection = widgetRange2ModelRange(widgetSelection);
if (documentSelection == null)
documentSelection = widgetSelection;
undoManager.endRecording(this, documentSelection.getOffset(), documentSelection.getLength());
} else {
// TODO: how to handle other document types?
}
}
use of org.eclipse.wst.sse.core.internal.undo.IStructuredTextUndoManager in project liferay-ide by liferay.
the class KaleoEdits method performOnDOMDocument.
/**
* performs an modifying operation on top the
*
* @param file
* @param operation
* @throws IOException
* @throws CoreException
*/
public static void performOnDOMDocument(KaleoEdits.OperationTuple... fileOperations) throws CoreException, IOException {
for (OperationTuple tuple : fileOperations) {
IDOMModel domModel = null;
/*
* TODO we might want to attempt iterating opened editors and
* somehow initialize those that were not yet initialized. Then we
* could avoid saving a file that is actually opened, but was never
* used so far (after restart)
*/
try {
DocumentRewriteSession session = null;
IStructuredTextUndoManager undo = null;
if (tuple.isReadOnly()) {
IModelManager modelManager = StructuredModelManager.getModelManager();
domModel = (IDOMModel) modelManager.getExistingModelForRead(tuple.getDocument());
if (domModel == null) {
domModel = (IDOMModel) modelManager.getModelForRead((IStructuredDocument) tuple.getDocument());
}
} else {
if (tuple.getModel() != null) {
domModel = tuple.getModel();
} else {
if (tuple.getFile() != null) {
domModel = (IDOMModel) StructuredModelManager.getModelManager().getModelForEdit(tuple.getFile());
} else {
IModelManager modelManager = StructuredModelManager.getModelManager();
domModel = (IDOMModel) modelManager.getExistingModelForEdit(tuple.getDocument());
}
}
// shall be ok here..let the model know we make changes
domModel.aboutToChangeModel();
undo = domModel.getStructuredDocument().getUndoManager();
if (domModel.getStructuredDocument() instanceof IDocumentExtension4) {
IDocumentExtension4 ext4 = (IDocumentExtension4) domModel.getStructuredDocument();
session = ext4.startRewriteSession(DocumentRewriteSessionType.UNRESTRICTED_SMALL);
}
undo.beginRecording(domModel);
}
try {
tuple.getOperation().process(domModel.getDocument());
} finally {
if (!tuple.isReadOnly()) {
undo.endRecording(domModel);
if ((session != null) && domModel.getStructuredDocument() instanceof IDocumentExtension4) {
IDocumentExtension4 ext4 = (IDocumentExtension4) domModel.getStructuredDocument();
ext4.stopRewriteSession(session);
}
domModel.changedModel();
}
}
} finally {
if (domModel != null) {
if (tuple.isReadOnly()) {
domModel.releaseFromRead();
} else {
/*
* for ducuments saving shall generally only happen when
* the model is not held elsewhere (eg. in opened view)
* for files, save always
*/
if (tuple.isForceSave() || (domModel.getReferenceCountForEdit() == 1)) {
domModel.save();
}
domModel.releaseFromEdit();
}
}
}
}
}
Aggregations