eclipse-platform / eclipse.platform.ui

Eclipse Platform
https://projects.eclipse.org/projects/eclipse.platform
Eclipse Public License 2.0
79 stars 168 forks source link

File->'Close Editor' menu doesn't work with e4 editors. #2176

Open eobrienPilz opened 1 month ago

eobrienPilz commented 1 month ago

Steps to reproduce

To reproduce you will need to define an editor part in an e4 fragment. It should be marked as closable and given the 'Editor' tag. Run the code and launch the editor The Close menu option is available as a right click popup on the editor tab and it works.

image

However the File->Close Editor menu option is disabled.

image

From debuging I can see that the handler code (CloseEditorHandler) doesn't consider e4 editors. It expects IEditorPart and checks that ISources.ACTIVE_EDITOR_NAME is set on the evaluation context. E4 editors dont use IEditorPart or set ISources.ACTIVE_EDITOR_NAME.

From a quick prototype it seems to work for all editors (e4 and legacy) if the menu handlers are defined using an e4 fragment.

e.g. This seems to work for both E4 and legacy editors.

public class CloseActiveEditorHandlerE4 { @CanExecute boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) MPart part) { boolean isEditor = part.getTags().stream().filter(t -> t.equals(Workbench.EDITOR_TAG)).count() > 0; return isEditor && part.isCloseable();
}

@Execute
void execute(EPartService partService, @Named(IServiceConstants.ACTIVE_PART) MPart part) {
    partService.hidePart(part, false);
}

}

The same issue exists with File->'Close All Editors'.

feilimb commented 1 week ago

Pull request created to address this: https://github.com/eclipse-platform/eclipse.platform.ui/pull/2315