[Pydev-cvs] org.python.pydev/src/org/python/pydev/outline SelectionPosition.java,NONE,1.1 ParsedMode
Brought to you by:
fabioz
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/outline In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11341/src/org/python/pydev/outline Modified Files: ParsedModel.java PyOutlinePage.java IOutlineModel.java RawPartitionModel.java ParsedItem.java Added Files: SelectionPosition.java Log Message: Refactoring of the fabioz changes --- NEW FILE: SelectionPosition.java --- /* * Author: fabioz, refactored by atotic * Created on Mar 5, 2004 * License: Common Public License v1.0 */ package org.python.pydev.outline; import org.eclipse.jface.text.IRegion; /** * Simple struct class that describes what to select * */ public final class SelectionPosition { public IRegion r; public int line; public int column; // use WHOLE_LINE to select the whole line public int length; public static final int WHOLE_LINE=999; SelectionPosition(IRegion r) { this.r = r; } SelectionPosition(int line, int column, int length) { this.line = line; this.column = column; this.length = length; this.r = null; } }; Index: ParsedModel.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/outline/ParsedModel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ParsedModel.java 5 Mar 2004 14:39:34 -0000 1.2 --- ParsedModel.java 5 Mar 2004 22:04:43 -0000 1.3 *************** *** 26,33 **** --- 26,39 ---- ParsedItem root = null; // A list of top nodes in this document. Used as a tree root + /** + * @param outline - If not null, view to notify when parser changes + * @param parser + */ public ParsedModel(PyOutlinePage outline, PyParser parser) { this.parser = parser; this.outline = outline; + // The notifications are only propagated to the outline page + // // Tell parser that we want to know about all the changes // make sure that the changes are propagated on the main thread *************** *** 53,61 **** }; parser.addParseListener(parserListener); ! root = new ParsedItem(null, parser.getRoot()); } ! public void dispose() { parser.removeParseListener(parserListener); } --- 59,67 ---- }; parser.addParseListener(parserListener); ! root = new ParsedItem(null, parser.getRoot()); } ! public void dispose() { parser.removeParseListener(parserListener); } *************** *** 104,109 **** ArrayList itemsToUpdate = new ArrayList(); patchRootHelper(root, newRoot, itemsToRefresh, itemsToUpdate, true); ! outline.updateItems(itemsToUpdate.toArray()); ! outline.refreshItems(itemsToRefresh.toArray()); } else --- 110,117 ---- ArrayList itemsToUpdate = new ArrayList(); patchRootHelper(root, newRoot, itemsToRefresh, itemsToUpdate, true); ! if (outline != null) { ! outline.updateItems(itemsToUpdate.toArray()); ! outline.refreshItems(itemsToRefresh.toArray()); ! } } else *************** *** 119,124 **** /* */ ! public IOutlineModel.SelectThis selectionChanged(StructuredSelection sel) { ! IOutlineModel.SelectThis position = null; if(sel.size() == 1) { // only sync the editing view if it is a single-selection ParsedItem p = (ParsedItem)sel.getFirstElement(); --- 127,132 ---- /* */ ! public SelectionPosition getSelectionPosition(StructuredSelection sel) { ! SelectionPosition position = null; if(sel.size() == 1) { // only sync the editing view if it is a single-selection ParsedItem p = (ParsedItem)sel.getFirstElement(); Index: PyOutlinePage.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/outline/PyOutlinePage.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PyOutlinePage.java 5 Mar 2004 14:41:34 -0000 1.4 --- PyOutlinePage.java 5 Mar 2004 22:04:44 -0000 1.5 *************** *** 11,17 **** import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IToolBarManager; - import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; - import org.eclipse.jface.text.IRegion; import org.eclipse.jface.viewers.AbstractTreeViewer; import org.eclipse.jface.viewers.ISelectionChangedListener; --- 11,15 ---- *************** *** 207,214 **** public void selectionChanged(SelectionChangedEvent event) { StructuredSelection sel = (StructuredSelection)tree.getSelection(); ! IOutlineModel.SelectThis newSel = model.selectionChanged(sel); if (newSel == null) return; ! selectSelectionInEditor(newSel,editorView); } }; --- 205,212 ---- public void selectionChanged(SelectionChangedEvent event) { StructuredSelection sel = (StructuredSelection)tree.getSelection(); ! SelectionPosition newSel = model.getSelectionPosition(sel); if (newSel == null) return; ! editorView.selectSelectionInEditor(newSel); } }; *************** *** 216,240 **** createActions(); } - - public static void selectSelectionInEditor(IOutlineModel.SelectThis newSel, PyEdit editorView) { - if (newSel.r != null) { - editorView.setSelection(newSel.r.getOffset(), newSel.r.getLength()); - } - else { - IDocumentProvider provider = editorView.getDocumentProvider(); - IDocument document = provider.getDocument(editorView.getEditorInput()); - try { - IRegion r = document.getLineInformation(newSel.line - 1); - // if selecting the whole line, just use the information - if (newSel.column == IOutlineModel.SelectThis.WHOLE_LINE) { - newSel.column = 0; - newSel.length = r.getLength(); - } - editorView.setSelection(r.getOffset() + newSel.column, newSel.length); - } catch (BadLocationException e) { - e.printStackTrace(); - } - } - } } --- 214,217 ---- Index: IOutlineModel.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/outline/IOutlineModel.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** IOutlineModel.java 5 Mar 2004 14:36:37 -0000 1.3 --- IOutlineModel.java 5 Mar 2004 22:04:44 -0000 1.4 *************** *** 6,10 **** package org.python.pydev.outline; - import org.eclipse.jface.text.Region; import org.eclipse.jface.viewers.StructuredSelection; --- 6,9 ---- *************** *** 27,30 **** --- 26,30 ---- */ int compare(Object e1, Object e2); + /** * this will be called in response to selection event *************** *** 32,55 **** * @return Point that contains line/column, or item to be selected */ ! SelectThis selectionChanged(StructuredSelection sel); ! ! class SelectThis { ! public Region r; ! ! int line; ! int column; // use WHOLE_LINE to select the whole line ! int length; ! ! static final int WHOLE_LINE=999; ! ! SelectThis(Region r) { ! this.r = r; ! } ! SelectThis(int line, int column, int length) { ! this.line = line; ! this.column = column; ! this.length = length; ! this.r = null; ! } ! }; } --- 32,35 ---- * @return Point that contains line/column, or item to be selected */ ! SelectionPosition getSelectionPosition(StructuredSelection sel); } Index: RawPartitionModel.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/outline/RawPartitionModel.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** RawPartitionModel.java 10 Dec 2003 10:14:27 -0000 1.2 --- RawPartitionModel.java 5 Mar 2004 22:04:44 -0000 1.3 *************** *** 113,117 **** // IOutlineModel API ! public IOutlineModel.SelectThis selectionChanged(StructuredSelection sel) { Region r = null; if(sel.size() == 1) { // only sync the editing view if it is a single-selection --- 113,117 ---- // IOutlineModel API ! public SelectionPosition getSelectionPosition(StructuredSelection sel) { Region r = null; if(sel.size() == 1) { // only sync the editing view if it is a single-selection *************** *** 119,123 **** r = new Region(p.offset, p.length); } ! return new IOutlineModel.SelectThis(r); } --- 119,123 ---- r = new Region(p.offset, p.length); } ! return new SelectionPosition(r); } Index: ParsedItem.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/outline/ParsedItem.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ParsedItem.java 5 Mar 2004 14:38:51 -0000 1.5 --- ParsedItem.java 5 Mar 2004 22:04:44 -0000 1.6 *************** *** 111,115 **** * @return where in the document is this item located */ ! public IOutlineModel.SelectThis getPosition() { return getPosition(token); } --- 111,115 ---- * @return where in the document is this item located */ ! public SelectionPosition getPosition() { return getPosition(token); } *************** *** 118,122 **** * @return where in the document is this item located */ ! public static IOutlineModel.SelectThis getPosition(SimpleNode token) { int startOffset = 0; boolean wholeLine = false; --- 118,122 ---- * @return where in the document is this item located */ ! public static SelectionPosition getPosition(SimpleNode token) { int startOffset = 0; boolean wholeLine = false; *************** *** 135,142 **** } ! IOutlineModel.SelectThis position = new IOutlineModel.SelectThis(token.beginLine, token.beginColumn+startOffset, toString(token).length()); if (wholeLine) ! position.column = IOutlineModel.SelectThis.WHOLE_LINE; return position; } --- 135,142 ---- } ! SelectionPosition position = new SelectionPosition(token.beginLine, token.beginColumn+startOffset, toString(token).length()); if (wholeLine) ! position.column = SelectionPosition.WHOLE_LINE; return position; } |