[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.platform] Re: Get the project for the current editor?
|
I use the following method to get the Current Project.
public static IProject getCurrentProject(){
IEditorPart editor =
ecletexPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
IEditorInput input = editor.getEditorInput();
IFile file = null;
if(input instanceof IFileEditorInput){
file = ((IFileEditorInput)input).getFile();
}
if(file==null)
return null;
IProject project = file.getProject();
return project;
}
it seems to do the trick.
"Manish Garg" <manish.garg@xxxxxxxxx> wrote in message
news:ckhmg3$abb$1@xxxxxxxxxxxxxx
> Hi,
>
> 1. Is is possible to detect which project does the currently active editor
> belong to? The problem I am trying to solve is to detect which project is
> selected on the package explorer view, when my plug-in is started by say a
> menu option or a key combination. Is there a straight forward way to do
> that, other than going through the active editor?
>
> 2. If I am not wrong, then to extract the current editor, the following
> code
> should be correct?
> IEditorPart editor =
>
> PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActi
> veEditor();
>
> Thanks a bunch for your time.
>
>