From 0b4269f73939bd7bc688ad04603a273f504dfc04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Mon, 20 May 2024 19:30:57 +0200 Subject: [PATCH 1/2] Handle the case when application has no focus in ApplicationPartService Currently when the application has no focus there is also no active window child and in this case several actions still fail even though a part is available for perform actions. This now handles the case of an application without focus with an empty optional to allow fall back to the part context. If that context has still no suitable part service implementation as a last resort the containing window context is used. --- .../workbench/ApplicationPartServiceImpl.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java index 6d15abbec0b..134a77c48b3 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/ApplicationPartServiceImpl.java @@ -27,6 +27,7 @@ import org.eclipse.e4.ui.model.application.ui.advanced.MPerspective; import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder; import org.eclipse.e4.ui.model.application.ui.basic.MPart; +import org.eclipse.e4.ui.model.application.ui.basic.MWindow; import org.eclipse.e4.ui.workbench.UIEvents; import org.eclipse.e4.ui.workbench.modeling.EModelService; import org.eclipse.e4.ui.workbench.modeling.EPartService; @@ -35,7 +36,7 @@ public class ApplicationPartServiceImpl implements EPartService { private static final Supplier NO_VALID_PARTSERVICE = () -> new IllegalStateException( - "No valid PartService can be aquired from the current context"); //$NON-NLS-1$ + "No valid PartService can be acquired from the current context"); //$NON-NLS-1$ private MApplication application; @@ -50,15 +51,17 @@ public class ApplicationPartServiceImpl implements EPartService { private Optional getActiveWindowService() { IEclipseContext activeWindowContext = application.getContext().getActiveChild(); if (activeWindowContext == null) { - throw new IllegalStateException("Application does not have an active window"); //$NON-NLS-1$ + // in this case the application has no focus so we can't determine the active + // child. + return Optional.empty(); } EPartService activeWindowPartService = activeWindowContext.get(EPartService.class); if (activeWindowPartService == null) { throw new IllegalStateException("Active window context is invalid"); //$NON-NLS-1$ } if (activeWindowPartService == this) { - // in this cas we would run into an infinite recursion, so from the current - // active window we can't aquire another part service + // in this case we would run into an infinite recursion, so from the current + // active window we can't acquire another part service return Optional.empty(); } return Optional.of(activeWindowPartService); @@ -68,10 +71,20 @@ private Optional getActiveWindowService(MPart part) { return getActiveWindowService().or(() -> { IEclipseContext context = part.getContext(); if (context != null) { + // First try the context of the part EPartService partService = context.get(EPartService.class); if (partService instanceof PartServiceImpl) { return Optional.of(partService); } + // Otherwise use the context of the contained window + MWindow window = modelService.getTopLevelWindowFor(part); + if (window != null) { + IEclipseContext windowContext = window.getContext(); + EPartService windowPartService = windowContext.get(EPartService.class); + if (windowPartService instanceof PartServiceImpl) { + return Optional.of(windowPartService); + } + } } return Optional.empty(); }); From 71070ea6833bca289d8548e9ae985a061d9064ba Mon Sep 17 00:00:00 2001 From: Eclipse Platform Bot Date: Sat, 28 Dec 2024 15:24:16 +0000 Subject: [PATCH 2/2] Version bump(s) for 4.35 stream --- bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF index b441a8c5d3a..2ea4c0a146f 100644 --- a/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.e4.ui.workbench/META-INF/MANIFEST.MF @@ -1,7 +1,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.e4.ui.workbench;singleton:=true -Bundle-Version: 1.16.0.qualifier +Bundle-Version: 1.16.100.qualifier Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin