[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor PyDoubleClickStrategy.java,NONE,1.1 Hyperli
Brought to you by:
fabioz
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16009/src/org/python/pydev/editor Modified Files: Hyperlink.java PyEdit.java PyEditConfiguration.java Added Files: PyDoubleClickStrategy.java Removed Files: PyContentAssistProcessor.java PyContentAssistant.java Log Message: More model code. Hyperlinks on function calls and imports now work. had to pull interpreter editor from PydevDebug plugin into this one since we needed interpreter locaiton for include paths. Model got extensive changes. Scopes are now used in the code. General code cleanup everywehre. Added findFunctionDefinition functionality with hyperlinks Added the ability to open external files (for external hyperlinks) Index: Hyperlink.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/Hyperlink.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Hyperlink.java 10 Apr 2004 01:48:14 -0000 1.1 --- Hyperlink.java 15 Apr 2004 23:19:21 -0000 1.2 *************** *** 6,9 **** --- 6,10 ---- package org.python.pydev.editor; + import java.util.ArrayList; import java.util.StringTokenizer; *************** *** 47,51 **** --- 48,55 ---- import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Display; + import org.eclipse.ui.PlatformUI; + import org.python.pydev.editor.actions.PyOpenAction; import org.python.pydev.editor.model.AbstractNode; + import org.python.pydev.editor.model.ItemPointer; import org.python.pydev.editor.model.ModelUtils; import org.python.pydev.plugin.PydevPlugin; *************** *** 79,82 **** --- 83,87 ---- private ISourceViewer fSourceViewer; private PyEdit fEditor; + private AbstractNode fClickedNode; public Hyperlink(ISourceViewer sourceViewer, PyEdit editor) { *************** *** 334,341 **** if (offset == -1) return null; ! ! AbstractNode node = ModelUtils.getElement(fEditor.getPythonModel(), offset, viewer.getDocument(), AbstractNode.PROP_CLICKABLE); ! if (node == null) return null; --- 339,345 ---- if (offset == -1) return null; ! fClickedNode = ModelUtils.getElement(fEditor.getPythonModel(), offset, viewer.getDocument(), AbstractNode.PROP_CLICKABLE); ! if (fClickedNode == null) return null; *************** *** 526,530 **** if (wasActive) { ! System.out.println("Clicked for action"); // IAction action= getAction("OpenEditor"); //$NON-NLS-1$ // if (action != null) --- 530,539 ---- if (wasActive) { ! PyOpenAction action = (PyOpenAction)fEditor.getAction(PyEdit.ACTION_OPEN); ! ArrayList where = ModelUtils.findDefinition(fClickedNode); ! if (where.size() > 0) ! action.run((ItemPointer)where.get(0)); ! else ! PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().getDisplay().beep(); // IAction action= getAction("OpenEditor"); //$NON-NLS-1$ // if (action != null) --- NEW FILE: PyDoubleClickStrategy.java --- /* * Author: atotic * Created on Apr 14, 2004 * License: Common Public License v1.0 */ package org.python.pydev.editor; import org.eclipse.jdt.internal.ui.text.JavaPairMatcher; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextDoubleClickStrategy; import org.eclipse.jface.text.ITextViewer; /** * Our double-click implementation. * * Copied org.eclipse.jdt.internal.ui.text.java.JavaDoubleClickStrategy. */ public class PyDoubleClickStrategy implements ITextDoubleClickStrategy { protected static final char[] BRACKETS = { '{', '}', '(', ')', '[', ']' }; protected JavaPairMatcher fPairMatcher = new JavaPairMatcher(BRACKETS); /** * @see ITextDoubleClickStrategy#doubleClicked */ public void doubleClicked(ITextViewer textViewer) { int offset = textViewer.getSelectedRange().x; if (offset < 0) return; IDocument document = textViewer.getDocument(); IRegion region = fPairMatcher.match(document, offset); if (region != null && region.getLength() >= 2) textViewer.setSelectedRange( region.getOffset() + 1, region.getLength() - 2); else selectWord(textViewer, document, offset); } protected void selectWord( ITextViewer textViewer, IDocument document, int anchor) { try { int offset = anchor; char c; while (offset >= 0) { c = document.getChar(offset); if (!Character.isJavaIdentifierPart(c)) break; --offset; } int start = offset; offset = anchor; int length = document.getLength(); while (offset < length) { c = document.getChar(offset); if (!Character.isJavaIdentifierPart(c)) break; ++offset; } int end = offset; if (start == end) textViewer.setSelectedRange(start, 0); else textViewer.setSelectedRange(start + 1, end - start - 1); } catch (BadLocationException x) { } } } --- PyContentAssistProcessor.java DELETED --- Index: PyEditConfiguration.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/PyEditConfiguration.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** PyEditConfiguration.java 2 Apr 2004 18:07:50 -0000 1.7 --- PyEditConfiguration.java 15 Apr 2004 23:19:21 -0000 1.8 *************** *** 136,141 **** ISourceViewer sourceViewer, String contentType) { ! // TODO Implement smarter double-click strategy ! return super.getDoubleClickStrategy(sourceViewer, contentType); } --- 136,143 ---- ISourceViewer sourceViewer, String contentType) { ! if (contentType.equals(IDocument.DEFAULT_CONTENT_TYPE)) ! return new PyDoubleClickStrategy(); ! else ! return super.getDoubleClickStrategy(sourceViewer, contentType); } Index: PyEdit.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/PyEdit.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** PyEdit.java 10 Apr 2004 01:48:14 -0000 1.11 --- PyEdit.java 15 Apr 2004 23:19:21 -0000 1.12 *************** *** 37,40 **** --- 37,41 ---- import org.python.parser.TokenMgrError; import org.python.pydev.plugin.*; + import org.python.pydev.editor.actions.PyOpenAction; import org.python.pydev.editor.model.AbstractNode; import org.python.pydev.editor.model.IModelListener; *************** *** 65,68 **** --- 66,71 ---- public class PyEdit extends TextEditor implements IParserListener { + static public String ACTION_OPEN = "OpenEditor"; + /** color cache */ private ColorCache colorCache; *************** *** 190,196 **** protected void createActions() { super.createActions(); // This action will fire a CONTENTASSIST_PROPOSALS operation ! // when executed ! IAction action= new TextOperationAction(PydevPlugin.getDefault().getResourceBundle(), "ContentAssistProposal",this,SourceViewer.CONTENTASSIST_PROPOSALS); --- 193,199 ---- protected void createActions() { super.createActions(); + // This action will fire a CONTENTASSIST_PROPOSALS operation ! // when executed IAction action= new TextOperationAction(PydevPlugin.getDefault().getResourceBundle(), "ContentAssistProposal",this,SourceViewer.CONTENTASSIST_PROPOSALS); *************** *** 202,205 **** --- 205,210 ---- setActionActivationCode(CONTENTASSIST_PROPOSAL_ID,' ', -1, SWT.CTRL); + IAction openAction = new PyOpenAction(); + setAction(ACTION_OPEN, openAction); enableBrowserLikeLinks(); } *************** *** 290,294 **** try { r = document.getLineInformation(lastLine-1); ! pythonModel = ModelMaker.createModel(root, lastLine , r.getLength()); fireModelChanged(pythonModel); } catch (BadLocationException e1) { --- 295,299 ---- try { r = document.getLineInformation(lastLine-1); ! pythonModel = ModelMaker.createModel(root, document, original); fireModelChanged(pythonModel); } catch (BadLocationException e1) { *************** *** 325,330 **** IRegion startLine = document.getLineInformation(errorToken.beginLine - 1); ! IRegion endLine = ! document.getLineInformation(errorToken.endLine - 1); errorStart = startLine.getOffset() + errorToken.beginColumn - 1; errorEnd = endLine.getOffset() + errorToken.endColumn; --- 330,338 ---- IRegion startLine = document.getLineInformation(errorToken.beginLine - 1); ! IRegion endLine; ! if (errorToken.endLine == 0) ! endLine = startLine; ! else ! endLine = document.getLineInformation(errorToken.endLine - 1); errorStart = startLine.getOffset() + errorToken.beginColumn - 1; errorEnd = endLine.getOffset() + errorToken.endColumn; *************** *** 352,356 **** map.put(IMarker.CHAR_START, new Integer(errorStart)); map.put(IMarker.CHAR_END, new Integer(errorEnd)); ! map.put(IMarker.TRANSIENT, new Boolean(true)); MarkerUtilities.createMarker(original, map, IMarker.PROBLEM); --- 360,364 ---- map.put(IMarker.CHAR_START, new Integer(errorStart)); map.put(IMarker.CHAR_END, new Integer(errorEnd)); ! map.put(IMarker.TRANSIENT, Boolean.valueOf(true)); MarkerUtilities.createMarker(original, map, IMarker.PROBLEM); --- PyContentAssistant.java DELETED --- |