[Pydev-cvs] org.python.pydev/src/org/python/pydev/plugin PydevPlugin.java,1.5,1.6 ExternalEditorInpu
Brought to you by:
fabioz
From: Aleksandar T. <at...@us...> - 2004-04-27 01:07:08
|
Update of /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32709/src/org/python/pydev/plugin Modified Files: PydevPlugin.java ExternalEditorInput.java Log Message: Minor bug fixes: - model elements take a better guess where they are with tabs - OpenAction worker method got refactored into PydevPlugin Index: ExternalEditorInput.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/ExternalEditorInput.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ExternalEditorInput.java 15 Apr 2004 23:19:22 -0000 1.1 --- ExternalEditorInput.java 27 Apr 2004 01:06:58 -0000 1.2 *************** *** 19,22 **** --- 19,27 ---- /** * An EditorInput for an external file. + * + * From Eclipse: EditorInput is like a file name, but more abstract + * It gets passed in to EditorPart. FileStorageEditorInput exposes the + * file, and that's how documents get their bytes. StorageEditorInput + * exposes the InputStream. */ public class ExternalEditorInput implements IStorageEditorInput { Index: PydevPlugin.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/plugin/PydevPlugin.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** PydevPlugin.java 22 Apr 2004 10:35:23 -0000 1.5 --- PydevPlugin.java 27 Apr 2004 01:06:58 -0000 1.6 *************** *** 4,13 **** --- 4,18 ---- import java.util.ResourceBundle; + import org.eclipse.core.resources.IFile; + import org.eclipse.core.resources.IStorage; import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; + import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.IPluginDescriptor; + import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Preferences; import org.eclipse.core.runtime.Status; + import org.eclipse.ui.*; import org.eclipse.ui.plugin.AbstractUIPlugin; *************** *** 100,102 **** --- 105,136 ---- } + /** + * Utility function that opens an editor on a given path. + * + * @return part that is the editor + */ + public IEditorPart doOpenEditor(IPath path) { + if (path == null) + return null; + IWorkspace w = ResourcesPlugin.getWorkspace(); + IFile file = w.getRoot().getFileForLocation(path); + IWorkbenchPage wp = getWorkbench().getActiveWorkbenchWindow().getActivePage(); + try { + if (file != null && file.exists()) { + // File is inside the workspace + return wp.openEditor(file, null, true); + } else { + IStorage storage = new FileStorage(path); + IEditorRegistry registry = PlatformUI.getWorkbench().getEditorRegistry(); + IEditorDescriptor desc = registry.getDefaultEditor(path.lastSegment()); + if (desc == null) + desc = registry.getDefaultEditor(); + IEditorInput input = new ExternalEditorInput(storage); + return wp.openEditor(input, desc.getId()); + } + } catch (PartInitException e) { + log(IStatus.ERROR, "Unexpected error opening path " + path.toString(),e); + return null; + } + } } |