[Pydev-cvs] org.python.pydev/src/org/python/pydev/editor/actions PyAddBlockComment.java,1.4,1.5 PyOp
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/editor/actions In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv32709/src/org/python/pydev/editor/actions Modified Files: PyAddBlockComment.java PyOpenAction.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: PyOpenAction.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyOpenAction.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PyOpenAction.java 22 Apr 2004 10:35:24 -0000 1.2 --- PyOpenAction.java 27 Apr 2004 01:06:59 -0000 1.3 *************** *** 9,15 **** 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.IPath; import org.eclipse.core.runtime.IStatus; --- 9,12 ---- *************** *** 19,34 **** import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.TextSelection; - import org.eclipse.ui.IEditorDescriptor; - import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorPart; - import org.eclipse.ui.IEditorRegistry; - import org.eclipse.ui.IWorkbenchPage; - import org.eclipse.ui.PartInitException; - import org.eclipse.ui.PlatformUI; import org.eclipse.ui.texteditor.ITextEditor; import org.python.pydev.editor.model.ItemPointer; import org.python.pydev.editor.model.Location; - import org.python.pydev.plugin.ExternalEditorInput; - import org.python.pydev.plugin.FileStorage; import org.python.pydev.plugin.PydevPlugin; --- 16,23 ---- *************** *** 36,41 **** * Opens an editor and selects text in it. * ! * Inspired by {@link org.eclipse.jdt.ui.actions.OpenAction}, but simplifies ! * traversal of functions. */ public class PyOpenAction extends Action { --- 25,30 ---- * Opens an editor and selects text in it. * ! * Inspired by org.eclipse.jdt.ui.actions.OpenAction, but simplifies ! * all handling in a single class. */ public class PyOpenAction extends Action { *************** *** 43,88 **** public PyOpenAction() { } ! ! /** ! * Opens the file, and sets the selection. ! * @param start: ok if null, won't set selection ! * @param end ! */ ! private void openInFile(IFile file, Location start, Location end) { ! if (file == null) ! return; ! IWorkbenchPage p = PydevPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); ! try { ! IEditorPart editorPart= p.openEditor(file, null, true); ! if (start != null && ! editorPart instanceof ITextEditor) { ! ITextEditor textEdit = (ITextEditor)editorPart; ! showInEditor(textEdit, start, end); ! } ! } catch (PartInitException e) { ! PydevPlugin.log(IStatus.ERROR, "Unexpected error opening file", e); ! } ! } ! ! private void openInExternalFile(IPath path, Location start, Location end) { ! 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); ! IWorkbenchPage p = PydevPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage(); ! try { ! IEditorPart editor = p.openEditor(input, desc.getId()); ! if (start != null && ! editor instanceof ITextEditor) { ! ITextEditor textEdit = (ITextEditor)editor; ! showInEditor(textEdit, start, end); ! } ! } catch (PartInitException e) { ! PydevPlugin.log(IStatus.ERROR, "Unexpected error opening external file", e); ! } ! } ! private void showInEditor( ITextEditor textEdit, --- 32,36 ---- public PyOpenAction() { } ! private void showInEditor( ITextEditor textEdit, *************** *** 104,129 **** - public void run(ItemPointer p) { if (p.file instanceof IFile) ! openInFile((IFile)p.file, p.start, p.end); else if (p.file instanceof File) { ! IPath path = new Path(((File)p.file).getAbsolutePath()); ! IWorkspace w = ResourcesPlugin.getWorkspace(); ! IFile file = w.getRoot().getFileForLocation(path); ! if (file != null && file.exists()) ! openInFile(file, p.start, p.end); ! else { ! openInExternalFile(path, p.start, p.end); ! } ! // I wrote a plugin that does something like this; see the Fileopen plugin at ! // www.eclipsepowered.org (open source on sourceforge). Since you don't want to ! // save the file it's even easier, see the sample code posted for ! // https://bugs.eclipse.org/bugs/show_bug.cgi?id=2869 . Basically it's the same ! // idea used by the CVS plugin to view source code on an arbitrary revision, so ! // that's another place to look. HTH. } ! else { ! PydevPlugin.log(IStatus.ERROR, "Unknown ItemPointer file format", null); } } --- 52,68 ---- public void run(ItemPointer p) { + IEditorPart editor = null; if (p.file instanceof IFile) ! editor = PydevPlugin.getDefault().doOpenEditor(((IFile)p.file).getFullPath()); ! else if (p.file instanceof IPath) { ! editor = PydevPlugin.getDefault().doOpenEditor((IPath)p.file); ! } else if (p.file instanceof File) { ! Path path = new Path(((File)p.file).getAbsolutePath()); ! editor = PydevPlugin.getDefault().doOpenEditor(path); } ! if (editor instanceof ITextEditor) { ! showInEditor((ITextEditor)editor, p.start, p.end); } } Index: PyAddBlockComment.java =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/src/org/python/pydev/editor/actions/PyAddBlockComment.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** PyAddBlockComment.java 20 Apr 2004 14:42:05 -0000 1.4 --- PyAddBlockComment.java 27 Apr 2004 01:06:59 -0000 1.5 *************** *** 21,24 **** --- 21,25 ---- /** + * . * Insert a comment block. * #===... |