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 5940a658411..73fb49dc0a8 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.17.0.qualifier +Bundle-Version: 1.17.100.qualifier Bundle-Name: %pluginName Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java index 3989f671859..7ed0738dab1 100644 --- a/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java +++ b/bundles/org.eclipse.e4.ui.workbench/src/org/eclipse/e4/ui/internal/workbench/PartServiceImpl.java @@ -192,6 +192,10 @@ private MPart toPart(MStackElement stackElement) { private boolean constructed = false; + private boolean switchingPerspective = false; + + private boolean focusingActivePart = false; + @Inject public PartServiceImpl(MApplication application, @Optional MWindow window) { // no need to track changes: @@ -604,6 +608,15 @@ public boolean isPartOrPlaceholderInPerspective(String elementId, MPerspective p @Override public void switchPerspective(MPerspective perspective) { + try { + switchingPerspective = true; + switchPerspectiveInternal(perspective); + } finally { + switchingPerspective = false; + } + } + + private void switchPerspectiveInternal(MPerspective perspective) { Assert.isNotNull(perspective); MWindow window = getWindow(); if (window != null && isInContainer(window, perspective)) { @@ -687,6 +700,11 @@ public void activate(MPart part, boolean requiresFocus) { } private void activate(MPart part, boolean requiresFocus, boolean activateBranch) { + if (focusingActivePart) { + Activator.trace(Policy.DEBUG_FOCUS_FLAG, + "Active part is being focused on perspective switch: " + activePart, null);//$NON-NLS-1$ + return; + } if (part == null) { if (constructed && activePart != null) { if (Policy.DEBUG_FOCUS) { @@ -727,12 +745,23 @@ private void activate(MPart part, boolean requiresFocus, boolean activateBranch) IEclipseContext windowContext = window.getContext(); // check if the active part has changed or if we are no longer the active window if (windowContext.getParent().getActiveChild() == windowContext && part == activePart) { - // insert it in the beginning of the activation history, it may not have been inserted - // pending when this service was instantiated - partActivationHistory.prepend(part); - UIEvents.publishEvent(UIEvents.UILifeCycle.ACTIVATE, part); - if (Policy.DEBUG_FOCUS) { - Activator.trace(Policy.DEBUG_FOCUS_FLAG, "Trying to activate already active part: " + part, null);//$NON-NLS-1$ + if (!focusingActivePart) { + // insert it in the beginning of the activation history, it may not have been + // inserted + // pending when this service was instantiated + partActivationHistory.prepend(part); + if (switchingPerspective && requiresFocus) { + focusingActivePart = true; + try { + focusPart(part); + } finally { + focusingActivePart = false; + } + } + UIEvents.publishEvent(UIEvents.UILifeCycle.ACTIVATE, part); + if (Policy.DEBUG_FOCUS) { + Activator.trace(Policy.DEBUG_FOCUS_FLAG, "Trying to activate already active part: " + part, null);//$NON-NLS-1$ + } } return; } @@ -767,11 +796,7 @@ private void activate(MPart part, boolean requiresFocus, boolean activateBranch) partActivationHistory.activate(part, activateBranch); if (requiresFocus) { - IEclipseContext context = part.getContext(); - if (context != null) { - IPresentationEngine pe = context.get(IPresentationEngine.class); - pe.focusGui(part); - } + focusPart(part); } // store the activation time to sort the parts in MRU order @@ -1513,4 +1538,12 @@ private MElementContainer getContainer() { } return outerContainer; } + + private void focusPart(MPart part) { + IEclipseContext context = part.getContext(); + if (context != null) { + IPresentationEngine pe = context.get(IPresentationEngine.class); + pe.focusGui(part); + } + } }