[Pydev-cvs] org.python.pydev/src/org/python/pydev/plugin PydevPlugin.java,1.62,1.63
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2006-03-29 22:26:33
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16968/src/org/python/pydev/plugin Modified Files: PydevPlugin.java Log Message: Fixed bug (it was unable to get the nature when it was an editor for an external file, so, go to declaration wouldn't work). Index: PydevPlugin.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/PydevPlugin.java,v retrieving revision 1.62 retrieving revision 1.63 diff -C2 -d -r1.62 -r1.63 *** PydevPlugin.java 15 Mar 2006 00:18:34 -0000 1.62 --- PydevPlugin.java 29 Mar 2006 22:26:26 -0000 1.63 *************** *** 54,57 **** --- 54,58 ---- import org.python.pydev.core.IPythonNature; import org.python.pydev.core.REF; + import org.python.pydev.core.Tuple; import org.python.pydev.core.bundle.BundleInfo; import org.python.pydev.core.bundle.IBundleInfo; *************** *** 61,64 **** --- 62,66 ---- import org.python.pydev.editor.templates.PyContextType; import org.python.pydev.plugin.nature.PythonNature; + import org.python.pydev.plugin.nature.SystemPythonNature; import org.python.pydev.pyunit.ITestRunListener; import org.python.pydev.pyunit.PyUnitTestRunner; *************** *** 66,69 **** --- 68,72 ---- import org.python.pydev.ui.interpreters.PythonInterpreterManager; + /** * The main plugin class - initialized on startup - has resource bundle for internationalization - has preferences *************** *** 728,731 **** --- 731,799 ---- } /** + * @param file the file we want to get info on. + * @return a tuple with the pythonnature to be used and the name of the module represented by the file in that scenario. + */ + public static Tuple<SystemPythonNature, String> getInfoForFile(File file){ + String modName = null; + IInterpreterManager pythonInterpreterManager = getPythonInterpreterManager(); + IInterpreterManager jythonInterpreterManager = getJythonInterpreterManager(); + + SystemPythonNature systemPythonNature = new SystemPythonNature(pythonInterpreterManager); + SystemPythonNature pySystemPythonNature = systemPythonNature; + SystemPythonNature jySystemPythonNature = null; + try { + modName = systemPythonNature.resolveModule(file); + } catch (Exception e) { + // that's ok + } + if(modName == null){ + systemPythonNature = new SystemPythonNature(jythonInterpreterManager); + jySystemPythonNature = systemPythonNature; + try { + modName = systemPythonNature.resolveModule(file); + } catch (Exception e) { + // that's ok + } + } + if(modName != null){ + return new Tuple<SystemPythonNature, String>(systemPythonNature, modName); + }else{ + //unable to discover it + try { + // the default one is python (actually, this should never happen, but who knows) + pythonInterpreterManager.getDefaultInterpreter(); + modName = getModNameFromFile(file); + return new Tuple<SystemPythonNature, String>(pySystemPythonNature, modName); + } catch (Exception e) { + //the python interpreter manager is not valid or not configured + try { + // the default one is jython + jythonInterpreterManager.getDefaultInterpreter(); + modName = getModNameFromFile(file); + return new Tuple<SystemPythonNature, String>(jySystemPythonNature, modName); + } catch (Exception e1) { + // ok, nothing to do about it, no interpreter is configured + return null; + } + } + } + } + + /** + * This is the last resort (should not be used anywhere else). + */ + private static String getModNameFromFile(File file) { + if(file == null){ + return null; + } + String name = file.getName(); + int i = name.indexOf('.'); + if (i != -1){ + return name.substring(0, i); + } + return name; + } + + /** * @return a preference store that has the pydev preference store and the default editors text store */ |