X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionManager.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionManager.java index 425891b..4fb0216 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionManager.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionManager.java @@ -1,7 +1,14 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + package net.sourceforge.phpdt.internal.ui.text.link; import java.util.Arrays; @@ -11,18 +18,20 @@ import java.util.Map; import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import org.eclipse.jface.text.Assert; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadPositionCategoryException; +import org.eclipse.jface.text.DocumentCommand; import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IAutoEditStrategy; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IDocumentExtension; import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.IPositionUpdater; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.TypedPosition; -import org.eclipse.jface.util.Assert; +import org.eclipse.jface.text.contentassist.ICompletionProposal; -//import org.eclipse.jdt.internal.ui.JavaPlugin; /** * This class manages linked positions in a document. Positions are linked @@ -42,20 +51,17 @@ import org.eclipse.jface.util.Assert; * gain control of the same document. * */ -public class LinkedPositionManager implements IDocumentListener, IPositionUpdater { - - private static class PositionComparator implements Comparator { - /* - * @see Comparator#compare(Object, Object) - */ - public int compare(Object object0, Object object1) { - Position position0= (Position) object0; - Position position1= (Position) object1; - - return position0.getOffset() - position1.getOffset(); - } - } - +public class LinkedPositionManager implements IDocumentListener, IPositionUpdater, IAutoEditStrategy { + + // This class still exists to properly handle code assist. + // This is due to the fact that it cannot be distinguished betweeen document changes which are + // issued by code assist and document changes which origin from another text viewer. + // There is a conflict in interest since in the latter case the linked mode should be left, but in the former case + // the linked mode should remain. + // To support content assist, document changes have to be propagated to connected positions + // by registering replace commands using IDocumentExtension. + // if it wasn't for the support of content assist, the documentChanged() method could be reduced to + // a simple call to leave(true) private class Replace implements IDocumentExtension.IReplace { private Position fReplacePosition; @@ -81,36 +87,68 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate document.addDocumentListener(owner); } } + + private static class PositionComparator implements Comparator { + /* + * @see Comparator#compare(Object, Object) + */ + public int compare(Object object0, Object object1) { + Position position0= (Position) object0; + Position position1= (Position) object1; + + return position0.getOffset() - position1.getOffset(); + } + } - private static final String LINKED_POSITION= "LinkedPositionManager.linked.position"; //$NON-NLS-1$ + private static final String LINKED_POSITION_PREFIX= "LinkedPositionManager.linked.position"; //$NON-NLS-1$ private static final Comparator fgPositionComparator= new PositionComparator(); private static final Map fgActiveManagers= new HashMap(); + private static int fgCounter= 0; private IDocument fDocument; - - private LinkedPositionListener fListener; + private ILinkedPositionListener fListener; + private String fPositionCategoryName; + private boolean fMustLeave; + /** + * Flag that records the state of this manager. As there are many different entities that may + * call leave or exit, these cannot always be sure whether the linked position infrastructure is + * still active. This is especially true for multithreaded situations. + */ + private boolean fIsActive= false; + /** * Creates a LinkedPositionManager for a IDocument. * * @param document the document to use with linked positions. + * @param canCoexist true if this manager can coexist with an already existing one */ - public LinkedPositionManager(IDocument document) { + public LinkedPositionManager(IDocument document, boolean canCoexist) { Assert.isNotNull(document); - - fDocument= document; - install(); + fDocument= document; + fPositionCategoryName= LINKED_POSITION_PREFIX + (fgCounter++); + install(canCoexist); } - + + /** + * Creates a LinkedPositionManager for a IDocument. + * + * @param document the document to use with linked positions. + */ + public LinkedPositionManager(IDocument document) { + this(document, false); + } + /** * Sets a listener to notify changes of current linked position. */ - public void setLinkedPositionListener(LinkedPositionListener listener) { + public void setLinkedPositionListener(ILinkedPositionListener listener) { fListener= listener; } /** - * Adds a linked position to the manager. + * Adds a linked position to the manager with the type being the content of + * the document at the specified range. * There are the following constraints for linked positions: * *