I want to do a small plugin with a single command which prints the current project name. The code fragment is a below:
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
IEditorPart editorPart = window.getActivePage().getActiveEditor();
if (editorPart != null){
IFileEditorInput input = (IFileEditorInput)editorPart.getEditorInput() ;
IFile file = input.getFile();
IProject activeProject = file.getProject();
String activeProjectName = activeProject.getName();
//... use activeProjectName
}
Problem: IFileEditorInput cannot be found(error msg: cannot be resolved to a type). I have import org.eclipse.ui.*; at the top of the file, but it doesn't work. Seems that IFileEditorInput is missing, but how I can find it?
Thank you very much!
You need to add a dependency on the org.eclipse.ui.ide
plug-in. IFileEditorInput
lives in the org.eclipse.ui
package, but not the plug-in of the same name, which is confusing. You can also avoid this type of confusion by using package dependencies rather than depending explicitly on certain plug-ins.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With