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 {
-
+ private static final String ERROR = "error"; //$NON-NLS-1$
+ private static final String WARNING = "warning"; //$NON-NLS-1$
/**
* A segment element.
*/
}
};
+ 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();
if (functionMode && Character.isJavaIdentifierPart((char) c)) {
functionMode = false;
- lastIndex = i-1;
+ lastIndex = i - 1;
identifier = getIdentifier(text, lastIndex);
try {
- i += identifier.length()-1;
+ i += identifier.length() - 1;
Position p = new Position(lastIndex, i - lastIndex);
document.addPosition(SEGMENTS, p);
fContent.add(new Segment(text.substring(lastIndex, i), p));
identifier = getIdentifier(text, i - 1);
if (identifier.equals("function")) {
functionMode = true;
- i+=8;
+ 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)
*/