[Pydev-cvs] org.python.pydev/src_dltk_console/org/python/pydev/dltk/console/ui/internal ScriptCons
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2008-03-20 16:56:05
|
Update of /cvsroot/pydev/org.python.pydev/src_dltk_console/org/python/pydev/dltk/console/ui/internal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23136/src_dltk_console/org/python/pydev/dltk/console/ui/internal Modified Files: ScriptConsoleViewer.java IScriptConsoleContentHandler.java Log Message: Console code-completion with: - default tab width - case independent completions - ESC/Shift+Enter handled with completions Index: ScriptConsoleViewer.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_dltk_console/org/python/pydev/dltk/console/ui/internal/ScriptConsoleViewer.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ScriptConsoleViewer.java 19 Mar 2008 19:59:21 -0000 1.3 --- ScriptConsoleViewer.java 20 Mar 2008 16:56:07 -0000 1.4 *************** *** 13,16 **** --- 13,21 ---- import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; + import org.eclipse.jface.text.contentassist.ContentAssistEvent; + import org.eclipse.jface.text.contentassist.ICompletionListener; + import org.eclipse.jface.text.contentassist.ICompletionProposal; + import org.eclipse.jface.text.contentassist.IContentAssistantExtension2; + import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ST; *************** *** 30,33 **** --- 35,39 ---- import org.python.pydev.dltk.console.ui.IScriptConsoleViewer; import org.python.pydev.dltk.console.ui.ScriptConsole; + import org.python.pydev.dltk.console.ui.ScriptConsoleContentAssistant; import org.python.pydev.dltk.console.ui.internal.actions.HandleBackspaceAction; import org.python.pydev.dltk.console.ui.internal.actions.HandleDeletePreviousWord; *************** *** 108,111 **** --- 114,119 ---- } + private boolean inCompletion = false; + private ScriptConsoleHistory history; *************** *** 113,116 **** --- 121,126 ---- IConsoleStyleProvider styleProvider; + + protected ScriptConsole console; public IConsoleStyleProvider getStyleProvider() { *************** *** 158,165 **** --- 168,184 ---- } + /** + * Constructor + * + * @param parent parent for this viewer + * @param console the console that this viewer is showing + * @param contentHandler + */ public ScriptConsoleViewer(Composite parent, ScriptConsole console, final IScriptConsoleContentHandler contentHandler) { super(parent, console); + this.console = console; + this.styleProvider = createStyleProvider(); *************** *** 167,170 **** --- 186,190 ---- this.listener = new ScriptConsoleDocumentListener(this, console, console.getPrompt(), console.getHistory()); + this.listener.setDocument(getDocument()); *************** *** 203,212 **** if (event.character == SWT.CR) { getTextWidget().setCaretOffset(getDocument().getLength()); return; } if (event.character == SWT.ESC) { ! listener.setCommandLine(""); return; } --- 223,241 ---- if (event.character == SWT.CR) { + //in a new line, always set the caret to the end of the document getTextWidget().setCaretOffset(getDocument().getLength()); + + //if we had an enter with the shift pressed and we're in a completion, we must stop it + if(inCompletion && (event.stateMask & SWT.SHIFT) != 0){ + ((ScriptConsoleContentAssistant)ScriptConsoleViewer.this.fContentAssistant).hide(); + } return; } if (event.character == SWT.ESC) { ! if(!inCompletion){ ! //while in a completion, esc won't clear the line (just stop the completion) ! listener.setCommandLine(""); ! } return; } *************** *** 253,256 **** --- 282,309 ---- } + + /** + * Listen to the completions because we've to know when we're doing a completion or not. + */ + @Override + public void configure(SourceViewerConfiguration configuration) { + super.configure(configuration); + if(fContentAssistant != null){ + ((IContentAssistantExtension2)fContentAssistant).addCompletionListener(new ICompletionListener(){ + + public void assistSessionStarted(ContentAssistEvent event) { + inCompletion = true; + } + + public void assistSessionEnded(ContentAssistEvent event) { + inCompletion = false; + } + + public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) { + }} + ); + } + } + /** * Can be overridden to create a style provider for the console. Index: IScriptConsoleContentHandler.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src_dltk_console/org/python/pydev/dltk/console/ui/internal/IScriptConsoleContentHandler.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** IScriptConsoleContentHandler.java 18 Mar 2008 02:55:16 -0000 1.1 --- IScriptConsoleContentHandler.java 20 Mar 2008 16:56:07 -0000 1.2 *************** *** 10,13 **** --- 10,16 ---- package org.python.pydev.dltk.console.ui.internal; + /** + * Used to handle content assist. + */ public interface IScriptConsoleContentHandler { |