-
Notifications
You must be signed in to change notification settings - Fork 228
Ensure active part receives focus on perspective switch #2841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is getting ugly... We can also take code from What about just leaving the double focusing in? Maybe it causes trouble in some client code which starts receiving 2 focus events instead of 0... With the flag for switching perspective protecting the focus call, I think that should be the only case of different behavior.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let say it this way: most of e4 is ugly, but what should we do? At least this works. |
||
| // 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<? extends MUIElement> getContainer() { | |
| } | ||
| return outerContainer; | ||
| } | ||
|
|
||
| private void focusPart(MPart part) { | ||
| IEclipseContext context = part.getContext(); | ||
| if (context != null) { | ||
| IPresentationEngine pe = context.get(IPresentationEngine.class); | ||
| pe.focusGui(part); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't init to defaults, here and below, and to be consistent we can remove it from above too.