[Pydev-cvs] org.python.pydev/src_completions/org/python/pydev/editor/codecompletion AbstractPyComp
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-06-15 21:03:24
|
Update of /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv8386/src_completions/org/python/pydev/editor/codecompletion Modified Files: PyLinkedModeCompletionProposal.java PyCodeCompletionPreferencesPage.java Added Files: AbstractPyCompletionProposalExtension2.java Removed Files: PyCompletionProposalExtension2.java Log Message: When '.' is auto-triggered, don't really apply the current completion. Only put a '.' (but this needs to be done in auto-trigger to request a new completion after that). --- PyCompletionProposalExtension2.java DELETED --- Index: PyLinkedModeCompletionProposal.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/PyLinkedModeCompletionProposal.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** PyLinkedModeCompletionProposal.java 14 Jun 2008 22:14:55 -0000 1.6 --- PyLinkedModeCompletionProposal.java 15 Jun 2008 21:03:31 -0000 1.7 *************** *** 27,31 **** import org.python.pydev.plugin.PydevPlugin; ! public class PyLinkedModeCompletionProposal extends PyCompletionProposalExtension2 implements ICompletionProposalExtension{ --- 27,31 ---- import org.python.pydev.plugin.PydevPlugin; ! public class PyLinkedModeCompletionProposal extends AbstractPyCompletionProposalExtension2 implements ICompletionProposalExtension{ *************** *** 52,55 **** --- 52,60 ---- /** + * Offset forced to be returned (only valid if >= 0) + */ + private int newForcedOffset = -1; + + /** * Constructor where the image and the docstring are lazily computed (initially added for the java integration). */ *************** *** 109,112 **** --- 114,121 ---- */ public Point getSelection(IDocument document) { + if(newForcedOffset >= 0){ + return new Point(newForcedOffset, 0); + } + if(onApplyAction == ON_APPLY_JUST_SHOW_CTX_INFO){ return null; *************** *** 126,132 **** --- 135,156 ---- public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) { + boolean eat = (stateMask & SWT.MOD1) != 0; IDocument doc = viewer.getDocument(); + if(trigger == '.'){ + //do not apply completion when it's triggered by '.', because that's usually not what's wanted + //e.g.: if the user writes sys and the current completion is SystemError, pressing '.' will apply + //the completion, but what the user usually wants is just having sys.xxx and not SystemError.xxx + try { + doc.replace(offset, 0, "."); + newForcedOffset = offset+1; + } catch (BadLocationException e) { + PydevPlugin.log(e); + } + return; + } + + if(onApplyAction == ON_APPLY_JUST_SHOW_CTX_INFO){ return; *************** *** 305,309 **** ! //ICompletionProposalExtension protected final static char[] VAR_TRIGGER= new char[] { '.' }; --- 329,333 ---- ! //-------------------------------------------- ICompletionProposalExtension protected final static char[] VAR_TRIGGER= new char[] { '.' }; *************** *** 314,317 **** --- 338,343 ---- * When . is entered, the user will finish (and apply) the current completion * and request a new one with '.' + * + * If not added, it won't request the new one (and will just stop the current) */ public char[] getTriggerCharacters(){ --- NEW FILE: AbstractPyCompletionProposalExtension2.java --- /* * Created on Jul 15, 2006 * @author Fabio */ package org.python.pydev.editor.codecompletion; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.DocumentEvent; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextViewer; import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2; import org.eclipse.jface.text.contentassist.IContextInformation; import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.graphics.Image; import org.python.pydev.core.docutils.PySelection; import org.python.pydev.plugin.PydevPlugin; public abstract class AbstractPyCompletionProposalExtension2 extends PyCompletionProposal implements ICompletionProposalExtension2 { protected PyCompletionPresentationUpdater presentationUpdater; public int fLen; public boolean fLastIsPar; public AbstractPyCompletionProposalExtension2(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo, int priority, int onApplyAction, String args) { super(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, contextInformation, additionalProposalInfo, priority, onApplyAction, args); presentationUpdater = new PyCompletionPresentationUpdater(); } /** * Called when Ctrl is selected during the completions * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, boolean) */ public void selected(ITextViewer viewer, boolean smartToggle) { if(smartToggle){ StyledText text= viewer.getTextWidget(); if (text == null || text.isDisposed()) return; int widgetCaret= text.getCaretOffset(); IDocument document = viewer.getDocument(); int finalOffset = widgetCaret; try { if(finalOffset >= document.getLength()){ unselected(viewer); return; } char c; do{ c = document.getChar(finalOffset); finalOffset++; }while(isValidChar(c) && finalOffset < document.getLength()); if(c == '('){ fLastIsPar = true; }else{ fLastIsPar = false; } if(!isValidChar(c)){ finalOffset--; } this.fLen = finalOffset-widgetCaret; this.presentationUpdater.updateStyle(viewer, widgetCaret, this.fLen); } catch (BadLocationException e) { PydevPlugin.log(e); } }else{ unselected(viewer); } } /** * @param c * @return */ private boolean isValidChar(char c) { return Character.isJavaIdentifierPart(c); } public void unselected(ITextViewer viewer) { this.presentationUpdater.repairPresentation(viewer); } public boolean validate(IDocument document, int offset, DocumentEvent event) { String[] strs = PySelection.getActivationTokenAndQual(document, offset, false); //System.out.println("validating:"+strs[0]+" - "+strs[1]); String qualifier = strs[1].toLowerCase(); //when we end with a '.', we should start a new completion (and not stay in the old one). if(strs[1].length() == 0 && (strs[0].length() == 0 || strs[0].endsWith("."))){ //System.out.println(false); return false; } String displayString = getDisplayString().toLowerCase(); if(displayString.startsWith(qualifier)){ //System.out.println(true); return true; } //System.out.println(false); return false; } } Index: PyCodeCompletionPreferencesPage.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_completions/org/python/pydev/editor/codecompletion/PyCodeCompletionPreferencesPage.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyCodeCompletionPreferencesPage.java 25 Mar 2007 16:08:59 -0000 1.1 --- PyCodeCompletionPreferencesPage.java 15 Jun 2008 21:03:31 -0000 1.2 *************** *** 78,82 **** "analyzed to get its actual token and if it maps to a method, its paramaters will be added in the completion.", 80); IntegerFieldEditor deepAnalysisFieldEditor = new IntegerFieldEditor( ! ARGUMENTS_DEEP_ANALYSIS_N_CHARS, "Minimun number of chars in qualifier for\ndeep analysis for parameters in 'from' imports:", p); addField(deepAnalysisFieldEditor); deepAnalysisFieldEditor.getLabelControl(p).setToolTipText(tooltip); --- 78,82 ---- "analyzed to get its actual token and if it maps to a method, its paramaters will be added in the completion.", 80); IntegerFieldEditor deepAnalysisFieldEditor = new IntegerFieldEditor( ! ARGUMENTS_DEEP_ANALYSIS_N_CHARS, "Minimum number of chars in qualifier for\ndeep analysis for parameters in 'from' imports:", p); addField(deepAnalysisFieldEditor); deepAnalysisFieldEditor.getLabelControl(p).setToolTipText(tooltip); *************** *** 102,106 **** addField(new BooleanFieldEditor( ! DEBUG_CODE_COMPLETION, "Debug code completion?.", p)); } --- 102,106 ---- addField(new BooleanFieldEditor( ! DEBUG_CODE_COMPLETION, "Debug code completion?", p)); } |