[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [cdt-dev] How to get an open file's project in Eclipse
|
Remove the block regarding selection, you don't need it as far as I
can see.
/*
ISelection iselection =
window.getSelectionService().getSelection();
IStructuredSelection selection =
(IStructuredSelection) iselection;
if (selection == null) {
log.error("null selection");
return;
}
*/
Regards,
AF
20.02.2020 11:56, Ming Cheng пишет:
I selected a tab in Eclipse Edit window.
my code to get the selected open file project like this:
public static void getCurrentProject() {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
IWorkbenchWindow window =
PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window != null) {
ISelection iselection =
window.getSelectionService().getSelection();
IStructuredSelection selection =
(IStructuredSelection) iselection;
if (selection == null) {
log.error("null selection");
return;
}
IWorkbenchPage activePage =
window.getActivePage();
IEditorPart activeEditor =
activePage.getActiveEditor();
if (activeEditor != null) {
IEditorInput input =
activeEditor.getEditorInput();
project =
input.getAdapter(IProject.class);
if (project == null) {
IResource resource =
input.getAdapter(IResource.class);
if (resource != null) {
project =
resource.getProject();
}
}
} else {
log.error("null activeEditor");
}
} else {
log.error("null window");
}
}
});
}
and window variable is not null but selection is null. Is my understanding
wrong?
project is a
class static member variable.
Thanks.
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://www.eclipse.org/mailman/listinfo/cdt-dev