Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » How to open source file in editor programatically
How to open source file in editor programatically [message #127073] Fri, 12 November 2004 19:13
Eclipse UserFriend
Originally posted by: weslao.comcast.net

I've created a new perspective and have added different views in it. One
of the view that I created is a table and contains some filenames. What I
want to do is to click on the table cell that contains a filename and the
file will be opened programmatically in the editor. How can I do that?

I've search around and found some code in the Eclipse FAQ. But it doesn't
do what I want. At the beginning because there's no file open so the
editor is blank. Then when I call the following code. All it does it read
the file and put it in the Tree in the Navigator view. How can I have the
file automatically opened in the editor and have the editor shown in the
views?

Please advice.

public void openExternalFile (String name) {
try {
IWorkspace ws = ResourcesPlugin.getWorkspace();
IProject project = ws.getRoot().getProject("External Files");
if (!project.exists())
project.create(null);
if (!project.isOpen())
project.open(null);
if (name == null)
return;
IPath location = new Path(name);
IFile file = project.getFile(location.lastSegment());
IEditorInput EInput = null;
file.createLink(location, IResource.NONE, null);
if (file != null)
EInput = new FileEditorInput (file);
IWorkbench wBench = PlatformUI.getWorkbench ();
_fWindow = ProfilerUiPlugin.getActiveWorkbenchWindow ();

if (_fWindow == null) {
IWorkbenchWindow[] windows = wBench.getWorkbenchWindows();
if(windows != null && windows.length > 0) {
_fWindow = windows[0];
}
else {
return;
}
}
IWorkbenchPage page = _fWindow.getActivePage();
if (page != null)
//page.openEditor(EInput, "org.eclipse.ui.DefaultTextEditor");
IDE.openEditor(page, file, "org.eclipse.ui.DefaultTextEditor");
}
catch (Exception e) {}
}
Previous Topic:[win32] undefinded referenced to gdi-functions?
Next Topic:syntax error when using a backslash?
Goto Forum:
  


Current Time: Tue Jul 22 15:38:21 EDT 2025

Powered by FUDForum. Page generated in 0.25732 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top