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;
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 {
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.
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;
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();
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) {
//
}
fContent.clear();
+ fVariables.clear();
if (newInput != null) {
IDocument document = fDocumentProvider.getDocument(newInput);
fContent.clear();
fContent = null;
}
+ if (fVariables != null) {
+ fVariables.clear();
+ fVariables = null;
+ }
}
/*
return fContent.toArray();
}
+ /**
+ * returns all PHP variables
+ */
+ public Object[] getVariables() {
+ return fVariables.toArray();
+ }
/*
* @see ITreeContentProvider#hasChildren(Object)
*/