public Position position;
public Segment(String name, Position position) {
- this.name= name;
- this.position= position;
+ this.name = name;
+ this.position = position;
}
public String toString() {
*/
protected class ContentProvider implements ITreeContentProvider {
- protected final static String SEGMENTS= "__java_segments"; //$NON-NLS-1$
- protected IPositionUpdater fPositionUpdater= new DefaultPositionUpdater(SEGMENTS);
- protected List fContent= new ArrayList(10);
+ protected final static String SEGMENTS = "__php_segments"; //$NON-NLS-1$
+ protected IPositionUpdater fPositionUpdater = new DefaultPositionUpdater(SEGMENTS);
+ protected List fContent = new ArrayList(10);
protected void parse(IDocument document) {
- int lines= document.getNumberOfLines();
- int increment= Math.max(Math.round((float) (lines / 10)), 10);
-
- for (int line= 0; line < lines; line += increment) {
-
- int length= increment;
- if (line + increment > lines)
- length= lines - line;
+ int lines = document.getNumberOfLines();
+ int increment = Math.max(Math.round((float) (lines / 10)), 10);
+
+ String text = document.get();
+ int lastIndex = 0;
+ int i=0;
+ lastIndex = text.indexOf("function ", lastIndex);
+ while (lastIndex > 0) {
try {
-
- int offset= document.getLineOffset(line);
- int end= document.getLineOffset(line + length);
- length= end - offset;
- Position p= new Position(offset, length);
+ i = lastIndex+9;
+ while ((i<text.length())&&Character.isJavaIdentifierPart(text.charAt(i))) {
+ i++;
+ }
+ Position p = new Position(lastIndex, i-lastIndex);
document.addPosition(SEGMENTS, p);
- fContent.add(new Segment(MessageFormat.format(PHPEditorMessages.getString("OutlinePage.segment.title_pattern"), new Object[] { new Integer(offset) }), p)); //$NON-NLS-1$
-
- } catch (BadPositionCategoryException x) {
- } catch (BadLocationException x) {
+ fContent.add(new Segment(text.substring(lastIndex,i), p));
+ // MessageFormat.format("function", new Object[] { new Integer(lastIndex)}), p)); //$NON-NLS-1$
+ lastIndex = text.indexOf("function", lastIndex+1);
+ } catch (BadLocationException e) {
+ } catch (BadPositionCategoryException e) {
}
+
}
+
+ // for (int line = 0; line < lines; line += increment) {
+ //
+ // int length = increment;
+ // if (line + increment > lines)
+ // length = lines - line;
+ //
+ // try {
+ //
+ // int offset = document.getLineOffset(line);
+ // int end = document.getLineOffset(line + length);
+ // length = end - offset;
+ // Position p = new Position(offset, length);
+ // document.addPosition(SEGMENTS, p);
+ // fContent.add(new Segment(MessageFormat.format(PHPEditorMessages.getString("OutlinePage.segment.title_pattern"), new Object[] { new Integer(offset)}), p)); //$NON-NLS-1$
+ //
+ // } catch (BadPositionCategoryException x) {
+ // } catch (BadLocationException x) {
+ // }
+ // }
}
/*
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (oldInput != null) {
- IDocument document= fDocumentProvider.getDocument(oldInput);
+ IDocument document = fDocumentProvider.getDocument(oldInput);
if (document != null) {
try {
document.removePositionCategory(SEGMENTS);
fContent.clear();
if (newInput != null) {
- IDocument document= fDocumentProvider.getDocument(newInput);
+ IDocument document = fDocumentProvider.getDocument(newInput);
if (document != null) {
document.addPositionCategory(SEGMENTS);
document.addPositionUpdater(fPositionUpdater);
public void dispose() {
if (fContent != null) {
fContent.clear();
- fContent= null;
+ fContent = null;
}
}
*/
public PHPContentOutlinePage(IDocumentProvider provider, ITextEditor editor) {
super();
- fDocumentProvider= provider;
- fTextEditor= editor;
+ fDocumentProvider = provider;
+ fTextEditor = editor;
}
-
+
/* (non-Javadoc)
* Method declared on ContentOutlinePage
*/
super.createControl(parent);
- TreeViewer viewer= getTreeViewer();
+ TreeViewer viewer = getTreeViewer();
viewer.setContentProvider(new ContentProvider());
viewer.setLabelProvider(new LabelProvider());
viewer.addSelectionChangedListener(this);
if (fInput != null)
viewer.setInput(fInput);
}
-
+
/* (non-Javadoc)
* Method declared on ContentOutlinePage
*/
super.selectionChanged(event);
- ISelection selection= event.getSelection();
+ ISelection selection = event.getSelection();
if (selection.isEmpty())
fTextEditor.resetHighlightRange();
else {
- Segment segment= (Segment) ((IStructuredSelection) selection).getFirstElement();
- int start= segment.position.getOffset();
- int length= segment.position.getLength();
+ Segment segment = (Segment) ((IStructuredSelection) selection).getFirstElement();
+ int start = segment.position.getOffset();
+ int length = segment.position.getLength();
try {
fTextEditor.setHighlightRange(start, length, true);
} catch (IllegalArgumentException x) {
}
}
}
-
+
/**
* Sets the input of the outline page
*/
public void setInput(Object input) {
- fInput= input;
+ fInput = input;
update();
}
-
+
/**
* Updates the outline page.
*/
public void update() {
- TreeViewer viewer= getTreeViewer();
+ TreeViewer viewer = getTreeViewer();
if (viewer != null) {
- Control control= viewer.getControl();
+ Control control = viewer.getControl();
if (control != null && !control.isDisposed()) {
control.setRedraw(false);
viewer.setInput(fInput);