X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java index dfc01fb..1bf4dbe 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java @@ -12,13 +12,11 @@ Contributors: Klaus Hartlage - www.eclipseproject.de **********************************************************************/ -import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; import java.util.List; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; - import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadPositionCategoryException; import org.eclipse.jface.text.DefaultPositionUpdater; @@ -32,14 +30,15 @@ import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.viewers.SelectionChangedEvent; import org.eclipse.jface.viewers.TreeViewer; import org.eclipse.jface.viewers.Viewer; - +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.views.contentoutline.ContentOutlinePage; /** - * A content outline page which always represents the content of the - * connected editor in 10 segments. + * A content outline page which always represents the functions of the + * connected PHPEditor. */ public class PHPContentOutlinePage extends ContentOutlinePage { @@ -59,6 +58,12 @@ public class PHPContentOutlinePage extends ContentOutlinePage { return name; } }; + + protected static class SegmentComparator implements Comparator { + public int compare(Object o1, Object o2) { + return ((Segment)o1).name.compareToIgnoreCase(((Segment)o2).name); + } + } /** * Divides the editor's document into ten segments and provides elements for them. @@ -68,6 +73,7 @@ public class PHPContentOutlinePage extends ContentOutlinePage { protected final static String SEGMENTS = "__php_segments"; //$NON-NLS-1$ protected IPositionUpdater fPositionUpdater = new DefaultPositionUpdater(SEGMENTS); protected List fContent = new ArrayList(10); + protected List fVariables = new ArrayList(100); private String getIdentifier(String text, int firstIndex) { int i = firstIndex; @@ -76,7 +82,9 @@ public class PHPContentOutlinePage extends ContentOutlinePage { StringBuffer identifier = new StringBuffer(); while (i < textLength) { c = text.charAt(i++); - if (Character.isJavaIdentifierPart(c)) { + if (Character.isJavaIdentifierPart(c) || (c=='$')) { + identifier.append(c); + } else if ( (i==firstIndex+1) && (c=='$')) { identifier.append(c); } else { return identifier.toString(); @@ -189,9 +197,15 @@ public class PHPContentOutlinePage extends ContentOutlinePage { functionMode = true; i+=8; } + } else if (c == '$') { + // get the variable name + identifier = getIdentifier(text, i - 1); + fVariables.add( identifier ); } } + Collections.sort(fContent, new SegmentComparator()); + Collections.sort(fVariables); // for (int line = 0; line < lines; line += increment) { // @@ -230,6 +244,7 @@ public class PHPContentOutlinePage extends ContentOutlinePage { } fContent.clear(); + fVariables.clear(); if (newInput != null) { IDocument document = fDocumentProvider.getDocument(newInput); @@ -250,6 +265,10 @@ public class PHPContentOutlinePage extends ContentOutlinePage { fContent.clear(); fContent = null; } + if (fVariables != null) { + fVariables.clear(); + fVariables = null; + } } /* @@ -266,6 +285,12 @@ public class PHPContentOutlinePage extends ContentOutlinePage { return fContent.toArray(); } + /** + * returns all PHP variables + */ + public Object[] getVariables() { + return fVariables.toArray(); + } /* * @see ITreeContentProvider#hasChildren(Object) */