下面列出了org.eclipse.jface.text.IDocument#removeDocumentListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* 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);
}
}
/**
* @see com.mulgasoft.emacsplus.commands.IConsoleDispatch#consoleDispatch(org.eclipse.ui.console.TextConsoleViewer, IConsoleView, ExecutionEvent)
*/
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
IDocument doc = viewer.getDocument();
int action = -1;
try {
StyledText st = viewer.getTextWidget();
action = getDispatchId(getId(event, viewer));
if (action > -1) {
// set up for kill ring
doc.addDocumentListener(KillRing.getInstance());
// setUpUndo(viewer);
st.invokeAction(action);
}
} finally {
// remove kill ring behavior
if (action > -1) {
doc.removeDocumentListener(KillRing.getInstance());
}
KillRing.getInstance().setKill(null, false);
}
return null;
}
/**
* Executes the document command on the specified document.
*
* @param document the document on which to execute the command.
* @throws BadLocationException in case this commands cannot be executed
*/
public void execute(IDocument document) throws BadLocationException {
if (fLength == 0 && fText == null) {
return;
}
if (fOwner != null) {
document.removeDocumentListener(fOwner);
}
document.replace(fOffset, fLength, fText);
if (fOwner != null) {
document.addDocumentListener(fOwner);
}
}
/**
* Stop managing the given document.
*
* @param document
* The document
*/
private void releaseDocument(IDocument document) {
if (document != null) {
document.removeDocumentListener(this);
document.removePositionUpdater(fPositionUpdater);
try {
document.removePositionCategory(getPositionCategory());
} catch (BadPositionCategoryException e) {
// Should not happen
log.debug(e.getMessage(), e);
}
}
}
@Override
public void inputDocumentAboutToBeChanged(IDocument oldInput,
IDocument newInput) {
if (oldInput != null) {
oldInput.removeDocumentListener(documentListener);
}
if (newInput != null) {
newInput.addDocumentListener(documentListener);
}
modificationStamp = ModificationStamp.OLDEST;
}
public void setDocument(IDocument document) {
IDocument oldDocument= getDocument();
super.setDocument(document);
if (oldDocument != null) {
oldDocument.removeDocumentListener(getDocumentListener());
}
if (document != null) {
document.addDocumentListener(getDocumentListener());
}
}
public void uninstall() {
ISourceViewer sourceViewer = getSourceViewer();
if (sourceViewer != null)
sourceViewer.removeTextInputListener(this);
IDocumentProvider documentProvider = getDocumentProvider();
if (documentProvider != null) {
IDocument document = documentProvider.getDocument(getEditorInput());
if (document != null)
document.removeDocumentListener(this);
}
}
/**
* Unregister this completion proposal popup.
*
* @since 3.0
*/
private void unregister()
{
if (fDocumentListener != null)
{
IDocument document = fContentAssistSubjectControlAdapter.getDocument();
if (document != null)
{
document.removeDocumentListener(fDocumentListener);
}
fDocumentListener = null;
}
fDocumentEvents.clear();
if (fKeyListener != null && Helper.okToUse(fContentAssistSubjectControlAdapter.getControl()))
{
fContentAssistSubjectControlAdapter.removeKeyListener(fKeyListener);
fKeyListener = null;
}
if (fLastProposal != null)
{
if (fLastProposal instanceof ICompletionProposalExtension2 && fViewer != null)
{
ICompletionProposalExtension2 extension = (ICompletionProposalExtension2) fLastProposal;
extension.unselected(fViewer);
}
fLastProposal = null;
}
fFilteredProposals = null;
fComputedProposals = null;
fContentAssistant.possibleCompletionsClosed();
}
/**
* @see org.eclipse.ui.part.Page#dispose()
*/
public void dispose()
{
if (this._documentListener != null)
{
IDocument document = getDocument();
if (document != null)
{
document.removeDocumentListener(this._documentListener);
}
this._documentListener = null;
}
if (this._delayedRefreshJob != null)
{
this._delayedRefreshJob.cancel();
this._delayedRefreshJob = null;
}
if (this._filterRefreshJob != null)
{
this._filterRefreshJob.cancel();
this._filterRefreshJob = null;
}
if (this._toolbarManager != null)
{
this._toolbarManager.dispose();
this._toolbarManager = null;
}
super.dispose();
}
/**
* uninstall
*/
public void uninstall() {
ISourceViewer sourceViewer = getSourceViewer();
IDocument document = getDocument();
if (sourceViewer != null) {
sourceViewer.removeTextInputListener(this);
}
if (document != null) {
document.removeDocumentListener(this);
}
}
public void uninstall() {
ISourceViewer sourceViewer= getSourceViewer();
if (sourceViewer != null)
sourceViewer.removeTextInputListener(this);
IDocumentProvider documentProvider= getDocumentProvider();
if (documentProvider != null) {
IDocument document= documentProvider.getDocument(getEditorInput());
if (document != null)
document.removeDocumentListener(this);
}
}
/**
* Stop managing the given document.
*
* @param document The document
*/
private void releaseDocument(IDocument document) {
if (document != null) {
document.removeDocumentListener(this);
document.removePositionUpdater(fPositionUpdater);
try {
document.removePositionCategory(getPositionCategory());
} catch (BadPositionCategoryException e) {
// Should not happen
JavaPlugin.log(e);
}
}
}
private static void removeDocumentListeners(ITextEditor editor) {
if (docListener != null) {
IDocumentProvider idp = editor.getDocumentProvider();
IDocument document;
// add null check for document, due to an unreproducible NPE reported by a clojure user
if (idp != null && (document = idp.getDocument(editor.getEditorInput())) != null) {
document.removeDocumentListener(docListener);
}
}
docListener = null;
}
/**
* @see com.mulgasoft.emacsplus.commands.ConsoleCmdHandler#consoleDispatch(TextConsoleViewer, IConsoleView, ExecutionEvent)
*/
@Override
public Object consoleDispatch(TextConsoleViewer viewer, IConsoleView activePart, ExecutionEvent event) {
Object result = null;
IDocument doc = viewer.getDocument();
try {
IWorkbenchPartSite site = activePart.getSite();
if (site != null) {
IHandlerService service = (IHandlerService) site.getService(IHandlerService.class);
if (doc != null && service != null) {
doc.addDocumentListener(KillRing.getInstance());
String cmdId = getId(event, viewer);
if (cmdId != null) {
result = service.executeCommand(cmdId, null);
}
}
}
} catch (CommandException e) {
// Shouldn't happen as the Command id will be null or valid
e.printStackTrace();
} finally {
if (doc != null) {
doc.removeDocumentListener(KillRing.getInstance());
}
// clear kill command flag
KillRing.getInstance().setKill(null, false);
}
MarkUtils.clearConsoleMark(viewer);
return result;
}
/**
* Stops listening changes in one document and starts listening another one.
*
* @param oldDoc may be null (if not null, this class will stop listening changes in it).
* @param newDoc the document that should be listened from now on.
*/
protected synchronized void reconnect(IDocument oldDoc, IDocument newDoc) {
Assert.isTrue(disconnectionLevel == 0);
if (oldDoc != null) {
oldDoc.removeDocumentListener(this);
}
newDoc.addDocumentListener(this);
this.doc = newDoc;
}
@Override
public void setDocument(IDocument document) {
IDocument oldDocument= getDocument();
super.setDocument(document);
if (oldDocument != null) {
oldDocument.removeDocumentListener(getDocumentListener());
}
if (document != null) {
document.addDocumentListener(getDocumentListener());
}
}
public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
if (oldInput == null)
return;
oldInput.removeDocumentListener(this);
}
public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
if (oldInput != null) {
oldInput.removeDocumentListener(this);
}
}
public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
if (oldInput == null)
return;
oldInput.removeDocumentListener(this);
}
/**
* Removes an {@link IEditorPart} from the pool and makes the editor editable again.
*
* <p>This Method also disconnects the editorPart from its data source (identified by associated
* {@link IFile}) and removes registered listeners:
*
* <ul>
* <li>{@link IElementStateListener} from {@link IDocumentProvider}
* <li>{@link IDocumentListener} from {@link IDocument}
* <li>{@link EditorListener} from {@link IEditorPart}
* </ul>
*
* @param editorPart editorPart to be removed
*/
public void remove(final IEditorPart editorPart) {
log.trace("removing editor part " + editorPart + " [" + editorPart.getTitle() + "]");
if (!isManaged(editorPart)) {
log.error("editor part is not managed: " + editorPart);
return;
}
final EditorPartInputReferences inputRefs = editorInputMap.remove(editorPart);
final IEditorInput input = inputRefs.input;
final IFile file = inputRefs.file;
// Unregister and unhook
setEditable(editorPart, true);
editorListeners.remove(editorPart).unbind();
final IDocumentProvider documentProvider = EditorAPI.getDocumentProvider(input);
dirtyStateListener.unregister(documentProvider, input);
final IDocument document = documentProvider.getDocument(input);
if (document == null) {
log.warn("could not disconnect from document: " + file);
} else {
document.removeDocumentListener(documentListener);
}
editorManager.disconnect(file);
final saros.filesystem.IFile wrappedFile = ResourceAdapterFactory.create(file);
editorParts.get(wrappedFile).remove(editorPart);
}