open an editor [message #221311] |
Fri, 13 July 2007 08:00 |
Eclipse User |
|
|
|
Originally posted by: karl.lindsten.com
Trying to open an editor on a textfile. I got an IFile that seems to work
but when create a new FileEditorInput with the ifile the program crash.
IWorkspace ws = ResourcesPlugin.getWorkspace();
IProject project = ws.getRoot().getProject("project");
String name = "/Users/usr/workspace/project/file.txt";
IPath location = new Path(name);
IFile file = project.getFile(location.lastSegment());
System.out.println("IFile: " + file.getname()) // ok
IEditorInput editorInput = new FileEditorInput(file);
// crash!!!
IWorkbenchPage page = window.getActivePage();
if (page != null)
page.openEditor(editorInput, "org.eclipse.ui.DefaultTextEditor");
|
|
|
|
|
Re: open an editor [message #221374 is a reply to message #221343] |
Fri, 13 July 2007 11:42 |
Eclipse User |
|
|
|
Originally posted by: karl.lindsten.com
Now it almost work. my IPath is workspace/project/file.txt but when I made
my IFile it got the location runtime-EclipseApplication/project/file.txt.
Should I copy the file to that directory to?
|
|
|
|
Re: open an editor [message #221390 is a reply to message #221382] |
Fri, 13 July 2007 12:36 |
Eclipse User |
|
|
|
Originally posted by: karl.lindsten.com
I'm trying to open a file outside the workspace. When I do that I get an
IPath with the right path to the file. Then when I make the IFile (IFile
file = project.getFile(path.lastSegment());) with the path the IFiles
location isn't the same as the path. So when the the program tries to
open the file it look at the wrong location. It moves the location from
the workspace directory to the runtime-EclipseApplicication directory so
then it cant find the file.
When i run the program it opens a texteditor that says it can't find the
file.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.08988 seconds