eclipse.platform.ui icon indicating copy to clipboard operation
eclipse.platform.ui copied to clipboard

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

Open eobrienPilz opened this issue 1 year ago • 1 comments

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'.

eobrienPilz avatar Aug 09 '24 15:08 eobrienPilz

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

feilimb avatar Sep 23 '24 13:09 feilimb