[Pydev-cvs] org.python.pydev/src/org/python/pydev/plugin DebugPrefsPage.java,NONE,1.1 ExternalEditor
Brought to you by:
fabioz
From: Aleksandar T. <at...@us...> - 2004-04-15 23:19:30
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16009/src/org/python/pydev/plugin Modified Files: PydevPrefs.java Added Files: DebugPrefsPage.java ExternalEditorInput.java FileStorage.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) --- NEW FILE: ExternalEditorInput.java --- /* Copied by atotic from Eclipse's bugzilla. The bug talked about opening external files */ package org.python.pydev.plugin; /* * (c) Copyright QNX Software Systems Ltd. 2002. * All Rights Reserved. */ import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.core.resources.IStorage; import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.IPersistableElement; import org.eclipse.ui.IStorageEditorInput; import org.eclipse.ui.PlatformUI; /** * An EditorInput for an external file. */ public class ExternalEditorInput implements IStorageEditorInput { IStorage externalFile; /** * Two ExternalEditorInputs are equal if their IStorage's are equal. * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof ExternalEditorInput)) return false; ExternalEditorInput other = (ExternalEditorInput)obj; return externalFile.equals(other.externalFile); } /* * @see IEditorInput#exists() */ public boolean exists() { // External file ca not be deleted return true; } /* * @see IAdaptable#getAdapter(Class) */ public Object getAdapter(Class adapter) { return null; } /* * @see IEditorInput#getContentType() */ public String getContentType() { return externalFile.getFullPath().getFileExtension(); } /* * @see IEditorInput#getFullPath() */ public String getFullPath() { return externalFile.getFullPath().toString(); } /* * @see IEditorInput#getImageDescriptor() */ public ImageDescriptor getImageDescriptor() { IEditorRegistry registry= PlatformUI.getWorkbench().getEditorRegistry(); return registry.getImageDescriptor(externalFile.getFullPath().getFileExtension()); } /* * @see IEditorInput#getName() */ public String getName() { return externalFile.getName(); } /* * @see IEditorInput#getPersistable() */ public IPersistableElement getPersistable() { return null; } /* * see IStorageEditorInput#getStorage() */ public IStorage getStorage() { return externalFile; } /* * @see IEditorInput#getToolTipText() */ public String getToolTipText() { return externalFile.getFullPath().toString(); } public ExternalEditorInput(IStorage exFile) { externalFile = exFile; } } --- NEW FILE: DebugPrefsPage.java --- /* * Author: atotic * Created: Jun 23, 2003 * License: Common Public License v1.0 */ package org.python.pydev.plugin; import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.preference.FieldEditorPreferencePage; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.python.pydev.ui.InterpreterEditor; /** * Debug preferences. * * <p>Simple 1 page debug preferences page. * <p>Prefeernce constants are defined in Constants.java */ public class DebugPrefsPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage{ /** * Initializer sets the preference store */ public DebugPrefsPage() { super(GRID); setPreferenceStore(PydevPlugin.getDefault().getPreferenceStore()); } public void init(IWorkbench workbench) { String interpreterPath = getPreferenceStore().getString(PydevPrefs.INTERPRETER_PATH); // If the interpreter path is empty, always try to come up with something if (interpreterPath == null || interpreterPath.length() == 0) { getPreferenceStore().setDefault(PydevPrefs.INTERPRETER_PATH, getDefaultInterpreterPath()); getPreferenceStore().setToDefault(PydevPrefs.INTERPRETER_PATH); } } /** * Creates the editors */ protected void createFieldEditors() { Composite p = getFieldEditorParent(); InterpreterEditor pathEditor = new InterpreterEditor ( PydevPrefs.INTERPRETER_PATH, "Python interpreters (for example python.exe)", p); addField(pathEditor); } /** * Return the default python executable * I tried making this smarter, but you can't do much without getenv(PATH) */ private String getDefaultInterpreterPath() { String executable = "python"; return executable; // ideally, I'd search the system path here, but getenv has been disabled // some code on finding the binary // java.util.Properties p = System.getProperties(); // java.util.Enumeration keys = p.keys(); // while( keys.hasMoreElements() ) { // System.out.println( keys.nextElement() ); // } // StringBuffer retVal = new StringBuffer(); // String sysPath = System.getProperty("sys.path"); // if (sysPath == null) // sysPath = System.getenv("PATH"); // if (sysPath != null) { // StringTokenizer st = new StringTokenizer(sysPath, File.pathSeparator + "\n\r"); // while (st.hasMoreElements()) { // String path =st.nextToken(); // System.out.println(path); // } // } // return retVal.toString(); } /** * Sets default preference values */ protected void initializeDefaultPreferences(Preferences prefs) { prefs.setDefault(PydevPrefs.INTERPRETER_PATH, getDefaultInterpreterPath()); } } Index: PydevPrefs.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/PydevPrefs.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PydevPrefs.java 8 Jan 2004 22:41:15 -0000 1.4 --- PydevPrefs.java 15 Apr 2004 23:19:22 -0000 1.5 *************** *** 16,19 **** --- 16,20 ---- import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; + import org.python.pydev.ui.InterpreterEditor; /** *************** *** 45,48 **** --- 46,51 ---- public static final String COMMENT_COLOR = "COMMENT_COLOR"; private static final RGB DEFAULT_COMMENT_COLOR = new RGB(178, 34, 34); + public static final String INTERPRETER_PATH = "INTERPRETER_PATH"; + protected static final String DEFAULT_INTERPRETER_PATH = "python"; /** *************** *** 58,61 **** --- 61,69 ---- } + public static String[] getInterpreters() { + String interpreters = getPreferences().getString(PydevPrefs.INTERPRETER_PATH); + return InterpreterEditor.getInterpreterList(interpreters); + } + public void init(IWorkbench workbench) { } --- NEW FILE: FileStorage.java --- /* Copied by atotic from Eclipse's bugzilla. The bug talked about opening external files */ package org.python.pydev.plugin; /* * (c) Copyright QNX Software Systems Ltd. 2002. * All Rights Reserved. */ import java.io.InputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.PlatformObject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.IStatus; /** * * @see IStorage */ public class FileStorage extends PlatformObject implements IStorage { IPath path; InputStream in = null; /** * Two FileStorages are equal if their IPaths are equal. * @see java.lang.Object#equals(java.lang.Object) */ public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof FileStorage)) return false; FileStorage other = (FileStorage)obj; return path.equals(other.path); } /** * @see org.eclipse.core.resources.IStorage#getContents() */ public InputStream getContents() throws CoreException { if (in == null) { try { return new FileInputStream(path.toFile()); } catch (FileNotFoundException e) { throw new CoreException(new Status(IStatus.ERROR, "FileStorage unknown string", IStatus.ERROR, e.toString(), e)); } } else { return in; } } /** * @see IStorage#getFullPath */ public IPath getFullPath() { return this.path; } /** * @see IStorage#getName */ public String getName() { return this.path.lastSegment(); } /** * @see IStorage#isReadOnly() */ public boolean isReadOnly() { return true; } /** * Method FileStorage. * @param path */ public FileStorage(IPath path){ this.path = path; } /** * Method FileStorage. * @param in * @param path */ public FileStorage(InputStream in, IPath path){ this.path = path; this.in = in; } /** * @see IStorage#isReadOnly() */ public String toString() { return path.toOSString(); } } |