本文整理汇总了Java中org.eclipse.text.undo.DocumentUndoManagerRegistry类的典型用法代码示例。如果您正苦于以下问题:Java DocumentUndoManagerRegistry类的具体用法?Java DocumentUndoManagerRegistry怎么用?Java DocumentUndoManagerRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DocumentUndoManagerRegistry类属于org.eclipse.text.undo包,在下文中一共展示了DocumentUndoManagerRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyEdits
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
/**
* Method will apply all edits to document as single modification. Needs to
* be executed in UI thread.
*
* @param document
* document to modify
* @param edits
* list of LSP TextEdits
*/
public static void applyEdits(IDocument document, TextEdit edit) {
if (document == null) {
return;
}
IDocumentUndoManager manager = DocumentUndoManagerRegistry.getDocumentUndoManager(document);
if (manager != null) {
manager.beginCompoundChange();
}
try {
RewriteSessionEditProcessor editProcessor = new RewriteSessionEditProcessor(document, edit,
org.eclipse.text.edits.TextEdit.NONE);
editProcessor.performEdits();
} catch (MalformedTreeException | BadLocationException e) {
EditorConfigPlugin.logError(e);
}
if (manager != null) {
manager.endCompoundChange();
}
}
示例2: removeComment
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
private void removeComment(IDocument doc, int offset) {
try {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
ITypedRegion par = TextUtilities.getPartition(doc, Partitions.MK_PARTITIONING, offset, false);
int beg = par.getOffset();
int len = par.getLength();
String comment = doc.get(beg, len);
int eLen = markerLen(comment);
int bLen = eLen + 1;
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new DeleteEdit(beg, bLen));
edit.addChild(new DeleteEdit(beg + len - eLen, eLen));
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure removing comment " + e.getMessage());
}
}
示例3: applyEdits
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
/**
* Method will apply all edits to document as single modification. Needs to
* be executed in UI thread.
*
* @param document
* document to modify
* @param edits
* list of TypeScript {@link CodeEdit}.
* @throws TypeScriptException
* @throws BadLocationException
* @throws MalformedTreeException
*/
public static void applyEdits(IDocument document, List<CodeEdit> codeEdits)
throws TypeScriptException, MalformedTreeException, BadLocationException {
if (document == null || codeEdits.isEmpty()) {
return;
}
IDocumentUndoManager manager = DocumentUndoManagerRegistry.getDocumentUndoManager(document);
if (manager != null) {
manager.beginCompoundChange();
}
try {
TextEdit edit = toTextEdit(codeEdits, document);
// RewriteSessionEditProcessor editProcessor = new
// RewriteSessionEditProcessor(document, edit,
// org.eclipse.text.edits.TextEdit.NONE);
// editProcessor.performEdits();
edit.apply(document);
} finally {
if (manager != null) {
manager.endCompoundChange();
}
}
}
示例4: installUndoRedoSupport
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
protected OperationHistoryListener installUndoRedoSupport(SourceViewer viewer, IDocument document, final EmbeddedEditorActions actions) {
IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(document);
final IUndoContext context = undoManager.getUndoContext();
// XXX cp uncommented
// IOperationHistory operationHistory = PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
OperationHistoryListener operationHistoryListener = new OperationHistoryListener(context, new IUpdate() {
public void update() {
actions.updateAction(ITextEditorActionConstants.REDO);
actions.updateAction(ITextEditorActionConstants.UNDO);
}
});
viewer.addTextListener(new ITextListener() {
public void textChanged(TextEvent event) {
actions.updateAction(ITextEditorActionConstants.REDO);
actions.updateAction(ITextEditorActionConstants.UNDO);
}
});
//
// operationHistory.addOperationHistoryListener(operationHistoryListener);
return operationHistoryListener;
}
示例5: replaceAll
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
/**
* Replace all occurrences
*/
private void replaceAll() {
boolean allState = isReplaceAll();
IDocumentUndoManager undoer = DocumentUndoManagerRegistry.getDocumentUndoManager(getDocument());
try {
paused = false;
setReplaceAll(true); // force flag so we don't re-enter the undoer during case replacement
if (undoer != null) {
undoer.beginCompoundChange();
}
replaceIt();
while (findNext(getSearchStr())){
replaceIt();
}
} finally {
setReplaceAll(allState);
if (undoer != null) {
undoer.endCompoundChange();
}
}
finish();
}
示例6: register
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
/**
* Registers a document manager with an editor.
* @param doc the document to be managed
* @param st the styled text of the editor
* @param dm the document manager
*/
public static void register(IDocument doc, StyledText st, DocumentManager dm) {
if (doc != null) {
doc.addDocumentListener(dm);
DocumentUndoManagerRegistry.connect(doc);
IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
if (undoManager != null) {
undoManager.addDocumentUndoListener(dm);
}
}
if (st != null) {
st.addListener(SWT.KeyDown, dm);
st.addListener(SWT.MouseDown, dm);
st.addListener(SWT.MouseDoubleClick, dm);
}
}
示例7: unregister
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
/**
* Unregisters a document manager with an editor.
* @param doc the document to be managed
* @param st the styled text of the editor
* @param dm the document manager
*/
public static void unregister(IDocument doc, StyledText st, DocumentManager dm) {
if (doc != null) {
doc.removeDocumentListener(dm);
IDocumentUndoManager undoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
DocumentUndoManagerRegistry.disconnect(doc);
if (undoManager != null) {
undoManager.removeDocumentUndoListener(dm);
}
}
if (st != null) {
st.removeListener(SWT.KeyDown, dm);
st.removeListener(SWT.MouseDown, dm);
st.removeListener(SWT.MouseDoubleClick, dm);
}
}
示例8: format
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
public static void format(FluentMkEditor editor, ITextSelection sel) {
IDocument doc = editor.getDocument();
if (doc == null || doc.getLength() == 0) return;
docLength = doc.getLength();
IPreferenceStore store = editor.getPrefsStore();
cols = store.getInt(Prefs.EDITOR_FORMATTING_COLUMN);
tabWidth = store.getInt(Prefs.EDITOR_TAB_WIDTH);
try {
PageRoot model = editor.getPageModel();
List<PagePart> parts = model.getPageParts();
if (sel != null && sel.getLength() > 0) {
parts = selectedParts(model, sel);
}
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
TextEdit edit = new MultiTextEdit();
for (PagePart part : parts) {
formatPagePart(part, edit);
}
edit.apply(editor.getDocument());
undoMgr.endCompoundChange();
} catch (Exception ex) {
Log.error("Bad location error occurred during formatting", ex);
}
}
示例9: remove
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
private void remove(int beg, int len, int markLen) {
try {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new DeleteEdit(beg - markLen, markLen));
edit.addChild(new DeleteEdit(beg + len, markLen));
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure removing mark" + e.getMessage());
}
}
示例10: addComment
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
private void addComment(IDocument doc, int beg, int len) {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
undoMgr.beginCompoundChange();
MultiTextEdit edit = new MultiTextEdit();
edit.addChild(new InsertEdit(beg, getCommentBeg()));
edit.addChild(new InsertEdit(beg + len, getCommentEnd()));
try {
edit.apply(doc);
undoMgr.endCompoundChange();
} catch (MalformedTreeException | BadLocationException e) {
Log.error("Failure creating comment " + e.getMessage());
}
}
示例11: doSave
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
@Override
public void doSave(IProgressMonitor progressMonitor) {
IDocument doc = getDocumentProvider().getDocument(getEditorInput());
if (doc != null) {
IDocumentUndoManager undoMgr = DocumentUndoManagerRegistry.getDocumentUndoManager(doc);
if (undoMgr != null) undoMgr.commit();
}
super.doSave(progressMonitor);
}
示例12: setUpUndo
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
protected void setUpUndo(TextConsoleViewer viewer) {
IDocumentUndoManager undoer = DocumentUndoManagerRegistry.getDocumentUndoManager(viewer.getDocument());
if (undoer == null) {
DocumentUndoManagerRegistry.connect(viewer.getDocument());
// undoer = DocumentUndoManagerRegistry.getDocumentUndoManager(viewer.getDocument());
// viewer.setUndoManager((IUndoManager) undoer);
}
}
示例13: caseReplace
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
/**
* Case-based replacement - after the initial find has already happened
*
* @param replacer - the replacement string (may be regexp)
* @param index - offset of find
* @param all - all if true, else initial
* @return - the replacement region
*
* @throws BadLocationException
*/
private IRegion caseReplace(String replacer, int index, boolean all) throws BadLocationException {
IRegion result = null;
IDocumentUndoManager undoer = DocumentUndoManagerRegistry.getDocumentUndoManager(getDocument());
try {
if (!isReplaceAll() && undoer != null) {
undoer.beginCompoundChange();
}
IFindReplaceTarget target = getTarget();
// first replace with (possible regexp) string
((IFindReplaceTargetExtension3)target).replaceSelection(replacer, isRegexp());
// adjust case of actual replacement string
replacer = target.getSelectionText();
String caseReplacer = replacer;
if (all) {
caseReplacer = caseReplacer.toUpperCase();
} else {
caseReplacer = caseReplacer.trim();
caseReplacer = Character.toUpperCase(caseReplacer.charAt(0)) +
caseReplacer.substring(1,caseReplacer.length()).toString();
// now update the replacement string with the re-cased part
caseReplacer = replacer.replaceFirst(replacer.trim(), caseReplacer);
}
int ind = target.findAndSelect(index, replacer, true, false, false);
if (ind > -1) {
target.replaceSelection(caseReplacer);
}
} finally {
if (!isReplaceAll() && undoer != null) {
undoer.endCompoundChange();
}
}
return result;
}
示例14: elementMoved
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
@Override
public void elementMoved(final Object originalElement, final Object movedElement) {
if (originalElement != null && originalElement.equals(editorPart.getEditorInput())) {
final boolean doValidationAsync = Display.getCurrent() != null;
final Runnable r = new Runnable() {
@Override
public void run() {
if (movedElement == null || movedElement instanceof IEditorInput) {
final String previousContent;
IDocumentUndoManager previousUndoManager = null;
IDocument changed = null;
final boolean wasDirty = editorPart.isDirty();
changed = documentProvider.getDocument(editorPart.getEditorInput());
if (changed != null) {
if (wasDirty)
previousContent = changed.get();
else
previousContent = null;
previousUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(changed);
if (previousUndoManager != null)
previousUndoManager.connect(this);
} else
previousContent = null;
editorPart.setInputWithNotify((IEditorInput) movedElement);
if (previousUndoManager != null) {
final IDocument newDocument = documentProvider.getDocument(movedElement);
if (newDocument != null) {
final IDocumentUndoManager newUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(newDocument);
if (newUndoManager != null)
newUndoManager.transferUndoHistory(previousUndoManager);
}
previousUndoManager.disconnect(this);
}
if (wasDirty && changed != null) {
final Runnable r2 = new Runnable() {
@Override
public void run() {
documentProvider.getDocument(editorPart.getEditorInput()).set(previousContent);
}
};
execute(r2, doValidationAsync);
}
}
}
};
execute(r, false);
}
}
示例15: elementMoved
import org.eclipse.text.undo.DocumentUndoManagerRegistry; //导入依赖的package包/类
@Override
public void elementMoved(final Object originalElement, final Object movedElement) {
if (originalElement != null && originalElement.equals(getEditorInput())) {
final boolean doValidationAsync = Display.getCurrent() != null;
final Runnable r = new Runnable() {
@Override
public void run() {
enableSanityChecking(true);
if (fSourceViewer == null)
return;
if (movedElement == null || movedElement instanceof IEditorInput) {
final IDocumentProvider d = getDocumentProvider();
final String previousContent;
IDocumentUndoManager previousUndoManager = null;
IDocument changed = null;
final boolean wasDirty = isDirty();
changed = d.getDocument(getEditorInput());
if (changed != null) {
if (wasDirty)
previousContent = changed.get();
else
previousContent = null;
previousUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(changed);
if (previousUndoManager != null)
previousUndoManager.connect(this);
} else
previousContent = null;
setInput((IEditorInput) movedElement);
// The undo manager needs to be replaced with one
// for the new document.
// Transfer the undo history and then disconnect
// from the old undo manager.
if (previousUndoManager != null) {
final IDocument newDocument = getDocumentProvider().getDocument(movedElement);
if (newDocument != null) {
final IDocumentUndoManager newUndoManager = DocumentUndoManagerRegistry.getDocumentUndoManager(newDocument);
if (newUndoManager != null)
newUndoManager.transferUndoHistory(previousUndoManager);
}
previousUndoManager.disconnect(this);
}
if (wasDirty && changed != null) {
final Runnable r2 = new Runnable() {
@Override
public void run() {
validateState(getEditorInput());
d.getDocument(getEditorInput()).set(previousContent);
}
};
execute(r2, doValidationAsync);
}
}
}
};
execute(r, false);
}
}