[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/codecompletion LabelFieldEditor.java,NONE,1
Brought to you by:
fabioz
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32131/src/org/python/pydev/editor/codecompletion Modified Files: PyContentAssistant.java PyCodeCompletionPreferencesPage.java PythonShell.java PythonCompletionProcessor.java Added Files: LabelFieldEditor.java Log Message: Code completion changes. --- NEW FILE: LabelFieldEditor.java --- /* * Created on Oct 19, 2004 * * @author Fabio Zadrozny */ package org.python.pydev.editor.codecompletion; import org.eclipse.jface.preference.FieldEditor; import org.eclipse.swt.widgets.Composite; class LabelFieldEditor extends FieldEditor { public LabelFieldEditor(String name, String labelText, Composite parent) { init(name, labelText); createControl(parent); } protected void adjustForNumColumns(int numColumns) { } protected void doFillIntoGrid(Composite parent, int numColumns) { getLabelControl(parent); } protected void doLoad() { } protected void doLoadDefault() { } protected void doStore() { } public int getNumberOfControls() { return 1; } } Index: PythonShell.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonShell.java,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** PythonShell.java 13 Oct 2004 19:52:53 -0000 1.15 --- PythonShell.java 19 Oct 2004 13:29:33 -0000 1.16 *************** *** 30,33 **** --- 30,34 ---- public class PythonShell { + private static final int DEFAULT_SLEEP_BETWEEN_ATTEMPTS = 100; /** * Reference to a 'global python shell' *************** *** 151,162 **** process = Runtime.getRuntime().exec(execMsg); boolean connected = false; int attempts = 0; ! sleepALittle(200); while(!connected && attempts < 20){ attempts += 1; try { ! socketToWrite = new Socket("127.0.0.1",pWrite); //we should write in this port serverSocket = new ServerSocket(pRead); //and read in this port socketToRead = serverSocket.accept(); --- 152,174 ---- process = Runtime.getRuntime().exec(execMsg); + sleepALittle(200); + if(process == null){ + throw new CoreException(PydevPlugin.makeStatus(IStatus.ERROR, "Error creating python process - got null process("+execMsg+")", new Exception("Error creating python process - got null process."))); + } + try { + int exitVal = process.exitValue(); //should throw exception saying that it still is not terminated... + //if no exception is thrown, we have an error... + throw new CoreException(PydevPlugin.makeStatus(IStatus.ERROR, "Error creating python process - exited before creating sockets - exitValue = ("+exitVal+")("+execMsg+")", new Exception("Error creating python process - exited before creating sockets - exitValue = ("+exitVal+")."))); + } catch (IllegalThreadStateException e2) { //this is ok + } + boolean connected = false; int attempts = 0; ! sleepALittle(300); while(!connected && attempts < 20){ attempts += 1; try { ! socketToWrite = new Socket("127.0.0.1",pWrite); //we should write in this port serverSocket = new ServerSocket(pRead); //and read in this port socketToRead = serverSocket.accept(); *************** *** 165,169 **** PydevPlugin.log(IStatus.ERROR, "Attempt: "+attempts+" of 20 failed, trying again...", e1); } ! sleepALittle(milisSleep); } --- 177,185 ---- PydevPlugin.log(IStatus.ERROR, "Attempt: "+attempts+" of 20 failed, trying again...", e1); } ! ! //if not connected, let's sleep a little for another attempt ! if(!connected){ ! sleepALittle(milisSleep); ! } } *************** *** 171,175 **** //what, after all this trouble we are still not connected????!?!?!?! //let's communicate this to the user... ! throw new CoreException(PydevPlugin.makeStatus(IStatus.ERROR, "Error creating python process ("+execMsg+")", new Exception("Error creating python process."))); } --- 187,191 ---- //what, after all this trouble we are still not connected????!?!?!?! //let's communicate this to the user... ! throw new CoreException(PydevPlugin.makeStatus(IStatus.ERROR, "Error connecting to python process ("+execMsg+")", new Exception("Error connecting to python process."))); } *************** *** 203,207 **** */ public void startIt() throws IOException, CoreException{ ! this.startIt(25); } --- 219,223 ---- */ public void startIt() throws IOException, CoreException{ ! this.startIt(DEFAULT_SLEEP_BETWEEN_ATTEMPTS); } Index: PyCodeCompletionPreferencesPage.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PyCodeCompletionPreferencesPage.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PyCodeCompletionPreferencesPage.java 21 Sep 2004 13:18:03 -0000 1.4 --- PyCodeCompletionPreferencesPage.java 19 Oct 2004 13:29:33 -0000 1.5 *************** *** 9,15 **** import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; import org.eclipse.jface.preference.BooleanFieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; - import org.eclipse.jface.preference.IntegerFieldEditor; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; --- 9,16 ---- import org.eclipse.core.runtime.Preferences.PropertyChangeEvent; import org.eclipse.jface.preference.BooleanFieldEditor; + import org.eclipse.jface.preference.FieldEditor; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.swt.widgets.Composite; + import org.eclipse.swt.widgets.Label; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; *************** *** 18,40 **** /** * @author Fabio Zadrozny */ ! public class PyCodeCompletionPreferencesPage extends FieldEditorPreferencePage ! implements IWorkbenchPreferencePage , Preferences.IPropertyChangeListener { ! public static final String AUTOCOMPLETE_ON_DOT = "AUTOCOMPLETE_ON_DOT"; ! public static final boolean DEFAULT_AUTOCOMPLETE_ON_DOT = true; ! ! public static final String USE_AUTOCOMPLETE = "USE_AUTOCOMPLETE"; ! public static final boolean DEFAULT_USE_AUTOCOMPLETE = true; ! ! public static final String AUTOCOMPLETE_DELAY = "AUTOCOMPLETE_DELAY"; ! public static final int DEFAULT_AUTOCOMPLETE_DELAY = 250; ! ! public static final String AUTOCOMPLETE_ON_PAR = "AUTOCOMPLETE_ON_PAR"; ! public static final boolean DEFAULT_AUTOCOMPLETE_ON_PAR = false; ! /** */ public PyCodeCompletionPreferencesPage() { --- 19,46 ---- /** + * The preferences for autocompletion should only be reactivated when the code completion feature gets better (more stable and precise). + * * @author Fabio Zadrozny */ ! public class PyCodeCompletionPreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage, ! Preferences.IPropertyChangeListener { + public static final String USE_CODECOMPLETION = "USE_CODECOMPLETION"; + public static final boolean DEFAULT_USE_CODECOMPLETION = false; ! // public static final String AUTOCOMPLETE_ON_DOT = "AUTOCOMPLETE_ON_DOT"; ! // public static final boolean DEFAULT_AUTOCOMPLETE_ON_DOT = true; ! // ! // public static final String USE_AUTOCOMPLETE = "USE_AUTOCOMPLETE"; ! // public static final boolean DEFAULT_USE_AUTOCOMPLETE = true; ! // ! // public static final String AUTOCOMPLETE_DELAY = "AUTOCOMPLETE_DELAY"; ! // public static final int DEFAULT_AUTOCOMPLETE_DELAY = 250; ! // ! // public static final String AUTOCOMPLETE_ON_PAR = "AUTOCOMPLETE_ON_PAR"; ! // public static final boolean DEFAULT_AUTOCOMPLETE_ON_PAR = false; ! private Label labelWarning; ! /** */ public PyCodeCompletionPreferencesPage() { *************** *** 49,65 **** */ protected void createFieldEditors() { ! Composite p = getFieldEditorParent(); ! addField(new BooleanFieldEditor( ! USE_AUTOCOMPLETE, "Use autocompletion?", p)); ! addField(new IntegerFieldEditor( ! AUTOCOMPLETE_DELAY, "Autocompletion delay: ", p)); ! addField(new BooleanFieldEditor( ! AUTOCOMPLETE_ON_DOT, "Autocomplete on '.'?", p)); ! addField(new BooleanFieldEditor( ! AUTOCOMPLETE_ON_PAR, "Autocomplete on '('?", p)); } --- 55,89 ---- */ protected void createFieldEditors() { ! Composite p = getFieldEditorParent(); ! String w = "WARNINGS for code completion:\n\n" ! + "Code completion works on top of a python shell and really \n" ! + "EXECUTES THE CODE YOU WRITE on the top level on the module.\n\n" ! + "So, you should NEVER call code that allocates resources or \n" ! + "make any other dangerous initializations in the global scope of \n" ! + "the module (not only because of code completion, as a simple \n" ! + "import of that code would be dangerous).\n\n" ! + "Code completion might also not work if the interpreter is not \n" ! + "correctly set, as it creates a shell to make code completion.\n\n" ! + "Code completion is activated by Ctrl+Space, as are the templates, so,\n" ! + "if you stop using code completion, the templates should still appear."; ! FieldEditor fe = new LabelFieldEditor("Warning", w, p); ! addField(fe); ! addField(new BooleanFieldEditor( ! USE_CODECOMPLETION, "Use code completion?", p)); ! // addField(new BooleanFieldEditor( ! // USE_AUTOCOMPLETE, "Use autocompletion?", p)); ! // ! // addField(new IntegerFieldEditor( ! // AUTOCOMPLETE_DELAY, "Autocompletion delay: ", p)); ! // ! // addField(new BooleanFieldEditor( ! // AUTOCOMPLETE_ON_DOT, "Autocomplete on '.'?", p)); ! // ! // addField(new BooleanFieldEditor( ! // AUTOCOMPLETE_ON_PAR, "Autocomplete on '('?", p)); } *************** *** 73,113 **** PydevPrefs.getPreferences().addPropertyChangeListener(this); } - /** - * Sets default preference values - */ - public static void initializeDefaultPreferences(Preferences prefs) { - prefs.setDefault(AUTOCOMPLETE_ON_DOT, DEFAULT_AUTOCOMPLETE_ON_DOT); - prefs.setDefault(USE_AUTOCOMPLETE, DEFAULT_USE_AUTOCOMPLETE); - prefs.setDefault(AUTOCOMPLETE_DELAY, DEFAULT_AUTOCOMPLETE_DELAY); - prefs.setDefault(AUTOCOMPLETE_ON_PAR, DEFAULT_AUTOCOMPLETE_ON_PAR); - } - - public static boolean isToAutocompleteOnDot() { - return PydevPrefs.getPreferences().getBoolean(PyCodeCompletionPreferencesPage.AUTOCOMPLETE_ON_DOT); - } ! public static boolean isToAutocompleteOnPar() { ! return PydevPrefs.getPreferences().getBoolean(PyCodeCompletionPreferencesPage.AUTOCOMPLETE_ON_PAR); ! } ! ! public static boolean useAutocomplete() { ! return PydevPrefs.getPreferences().getBoolean(PyCodeCompletionPreferencesPage.USE_AUTOCOMPLETE); } ! public static int getAutocompleteDelay() { ! return PydevPrefs.getPreferences().getInt(PyCodeCompletionPreferencesPage.AUTOCOMPLETE_DELAY); } ! /* (non-Javadoc) * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent event) { ! // System.out.println( event.getProperty() ! // + "\n\told setting: " ! // + event.getOldValue() ! // + "\n\tnew setting: " ! // + event.getNewValue()); ! } --- 97,144 ---- PydevPrefs.getPreferences().addPropertyChangeListener(this); } ! /** ! * Sets default preference values ! */ ! public static void initializeDefaultPreferences(Preferences prefs) { ! prefs.setDefault(USE_CODECOMPLETION, DEFAULT_USE_CODECOMPLETION); ! // prefs.setDefault(AUTOCOMPLETE_ON_DOT, DEFAULT_AUTOCOMPLETE_ON_DOT); ! // prefs.setDefault(USE_AUTOCOMPLETE, DEFAULT_USE_AUTOCOMPLETE); ! // prefs.setDefault(AUTOCOMPLETE_DELAY, DEFAULT_AUTOCOMPLETE_DELAY); ! // prefs.setDefault(AUTOCOMPLETE_ON_PAR, DEFAULT_AUTOCOMPLETE_ON_PAR); } ! public static boolean useCodeCompletion() { ! return PydevPrefs.getPreferences().getBoolean(PyCodeCompletionPreferencesPage.USE_CODECOMPLETION); } + // public static boolean isToAutocompleteOnDot() { + // return PydevPrefs.getPreferences().getBoolean(PyCodeCompletionPreferencesPage.AUTOCOMPLETE_ON_DOT); + // } + // + // public static boolean isToAutocompleteOnPar() { + // return PydevPrefs.getPreferences().getBoolean(PyCodeCompletionPreferencesPage.AUTOCOMPLETE_ON_PAR); + // } + // + // public static boolean useAutocomplete() { + // return PydevPrefs.getPreferences().getBoolean(PyCodeCompletionPreferencesPage.USE_AUTOCOMPLETE); + // } + // + // public static int getAutocompleteDelay() { + // return PydevPrefs.getPreferences().getInt(PyCodeCompletionPreferencesPage.AUTOCOMPLETE_DELAY); + // } ! /* ! * (non-Javadoc) ! * * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent) */ public void propertyChange(PropertyChangeEvent event) { ! // System.out.println( event.getProperty() ! // + "\n\told setting: " ! // + event.getOldValue() ! // + "\n\tnew setting: " ! // + event.getNewValue()); ! } Index: PythonCompletionProcessor.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PythonCompletionProcessor.java,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** PythonCompletionProcessor.java 13 Oct 2004 19:52:54 -0000 1.10 --- PythonCompletionProcessor.java 19 Oct 2004 13:29:33 -0000 1.11 *************** *** 90,107 **** int qlen = qualifier.length(); - try { - PythonShell.getServerShell(PythonShell.COMPLETION_SHELL).sendGoToDirMsg(edit.getEditorFile()); - } catch (Exception e) { - //if we don't suceed, we don't have to fail... just go on and try - // to complete... - e.printStackTrace(); - } - - List pythonProposals = getPythonProposals(documentOffset, doc, activationToken, qlen); - List templateProposals = getTemplateProposals(viewer, documentOffset, activationToken, qualifier, - pythonProposals); - ArrayList pythonAndTemplateProposals = new ArrayList(); ! pythonAndTemplateProposals.addAll(pythonProposals); pythonAndTemplateProposals.addAll(templateProposals); --- 90,107 ---- int qlen = qualifier.length(); ArrayList pythonAndTemplateProposals = new ArrayList(); ! if(PyCodeCompletionPreferencesPage.useCodeCompletion()){ ! try { ! PythonShell.getServerShell(PythonShell.COMPLETION_SHELL).sendGoToDirMsg(edit.getEditorFile()); ! } catch (Exception e) { ! //if we don't suceed, we don't have to fail... just go on and try ! // to complete... ! e.printStackTrace(); ! } ! ! List pythonProposals = getPythonProposals(documentOffset, doc, activationToken, qlen); ! pythonAndTemplateProposals.addAll(pythonProposals); ! } ! List templateProposals = getTemplateProposals(viewer, documentOffset, activationToken, qualifier); pythonAndTemplateProposals.addAll(templateProposals); *************** *** 153,157 **** */ private List getTemplateProposals(ITextViewer viewer, int documentOffset, String activationToken, ! java.lang.String qualifier, List allProposals) { List propList = new ArrayList(); this.templatesCompletion.addTemplateProposals(viewer, documentOffset, propList); --- 153,157 ---- */ private List getTemplateProposals(ITextViewer viewer, int documentOffset, String activationToken, ! java.lang.String qualifier) { List propList = new ArrayList(); this.templatesCompletion.addTemplateProposals(viewer, documentOffset, propList); *************** *** 176,185 **** public char[] getCompletionProposalAutoActivationCharacters() { char[] c = new char[0]; ! if (PyCodeCompletionPreferencesPage.isToAutocompleteOnDot()) { ! c = addChar(c, '.'); ! } ! if (PyCodeCompletionPreferencesPage.isToAutocompleteOnPar()) { ! c = addChar(c, '('); ! } return c; } --- 176,185 ---- public char[] getCompletionProposalAutoActivationCharacters() { char[] c = new char[0]; ! // if (PyCodeCompletionPreferencesPage.isToAutocompleteOnDot()) { ! // c = addChar(c, '.'); ! // } ! // if (PyCodeCompletionPreferencesPage.isToAutocompleteOnPar()) { ! // c = addChar(c, '('); ! // } return c; } Index: PyContentAssistant.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/codecompletion/PyContentAssistant.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PyContentAssistant.java 25 Aug 2004 17:25:23 -0000 1.1 --- PyContentAssistant.java 19 Oct 2004 13:29:33 -0000 1.2 *************** *** 18,23 **** public PyContentAssistant(){ PydevPrefs.getPreferences().addPropertyChangeListener(this); ! enableAutoActivation(PyCodeCompletionPreferencesPage.useAutocomplete()); ! setAutoActivationDelay(PyCodeCompletionPreferencesPage.getAutocompleteDelay()); } --- 18,22 ---- public PyContentAssistant(){ PydevPrefs.getPreferences().addPropertyChangeListener(this); ! // enableAutoActivation(PyCodeCompletionPreferencesPage.useAutocomplete()); } *************** *** 26,35 **** */ public void propertyChange(PropertyChangeEvent event) { ! if(event.getProperty().equals(PyCodeCompletionPreferencesPage.USE_AUTOCOMPLETE)){ ! this.enableAutoActivation( ((Boolean)event.getNewValue()).booleanValue() ); ! } ! if(event.getProperty().equals(PyCodeCompletionPreferencesPage.AUTOCOMPLETE_DELAY)){ ! this.setAutoActivationDelay( ((Integer)event.getNewValue()).intValue() ); ! } } } --- 25,31 ---- */ public void propertyChange(PropertyChangeEvent event) { ! // if(event.getProperty().equals(PyCodeCompletionPreferencesPage.USE_AUTOCOMPLETE)){ ! // this.enableAutoActivation( ((Boolean)event.getNewValue()).booleanValue() ); ! // } } } |