From 29df3a9b90396e3f2a2dc11dfc9ca5ec129e099d Mon Sep 17 00:00:00 2001 From: Simeon Andreev Date: Thu, 18 Oct 2018 15:20:34 +0200 Subject: Bug 540253 - Debug inactive after switching perspectives The fix for bug 538548 introduces a regression as follows. Switch from Java to Debug perspective, then back to Java perspective. Debug a snippet until a breakpoint is hit. Choose yes when asked whether to switch to the Debug perspective. Observe that debug controls are inactive. This is the case since LaunchView context provider no longer reacts to debug events, after switching to the Java perspective. It misses the breakpoint hit (which also triggers the Debug perspective switch-to confirmation dialog). This change removes the fix for bug 538548 and adds a local fix to SourceLookupService. The added fix prevents an editor popping up in the current perspective under the following conditions: 1. If the Debug View was not open in the current perspective. 2. Preferences to switch to a debug perspective on a breakpoint hit or on launch are set to "never". 3. Preference to activate the Debug View on a breakpoint hit is set to "disabled". Change-Id: Iab575ee2f9a292c23c47c95d23afadc49b8b2dff Signed-off-by: Simeon Andreev Signed-off-by: Andrey Loskutov --- .../ui/sourcelookup/SourceLookupService.java | 50 +++++++++++++++++++--- .../debug/internal/ui/views/launch/LaunchView.java | 4 +- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupService.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupService.java index 5337c5ff5..e5dcf37d0 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupService.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/sourcelookup/SourceLookupService.java @@ -16,12 +16,17 @@ package org.eclipse.debug.internal.ui.sourcelookup; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.PlatformObject; +import org.eclipse.debug.internal.ui.DebugUIPlugin; +import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; import org.eclipse.debug.internal.ui.views.launch.DebugElementAdapterFactory; import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.IDebugUIConstants; import org.eclipse.debug.ui.contexts.DebugContextEvent; import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.debug.ui.contexts.IDebugContextService; import org.eclipse.debug.ui.sourcelookup.ISourceDisplay; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbenchPage; @@ -52,8 +57,44 @@ public class SourceLookupService implements IDebugContextListener, ISourceDispla @Override public synchronized void debugContextChanged(DebugContextEvent event) { if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) { - displaySource(event.getContext(), event.getDebugContextProvider().getPart(), false); + if (isDebugViewActive() || canActivateDebugView()) { + displaySource(event.getContext(), event.getDebugContextProvider().getPart(), false); + } + } + } + + private boolean isDebugViewActive() { + if (isDisposed()) { + return false; + } + IWorkbenchPage activePage = fWindow.getActivePage(); + if (activePage != null) { + return activePage.findView(IDebugUIConstants.ID_DEBUG_VIEW) != null; + } + return false; + } + + private boolean canActivateDebugView() { + if (isDisposed()) { + return false; + } + IPreferenceStore preferenceStore = DebugUIPlugin.getDefault().getPreferenceStore(); + String[] switchPreferences = { + IInternalDebugUIConstants.PREF_SWITCH_TO_PERSPECTIVE, + IInternalDebugUIConstants.PREF_SWITCH_PERSPECTIVE_ON_SUSPEND, + }; + for (String switchPreference : switchPreferences) { + String preferenceValue = preferenceStore.getString(switchPreference); + if (!MessageDialogWithToggle.NEVER.equals(preferenceValue)) { + return true; + } } + boolean canActivateDebugView = preferenceStore.getBoolean(IInternalDebugUIConstants.PREF_ACTIVATE_DEBUG_VIEW); + return canActivateDebugView; + } + + private boolean isDisposed() { + return fWindow == null; } /** @@ -65,7 +106,9 @@ public class SourceLookupService implements IDebugContextListener, ISourceDispla * @param force */ protected synchronized void displaySource(ISelection selection, IWorkbenchPart part, boolean force) { - if (fWindow == null) return; // disposed + if (isDisposed()) { + return; + } if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection)selection; @@ -82,9 +125,6 @@ public class SourceLookupService implements IDebugContextListener, ISourceDispla } } - /* (non-Javadoc) - * @see org.eclipse.debug.internal.ui.contexts.ISourceDisplayAdapter#displaySource(java.lang.Object, org.eclipse.ui.IWorkbenchPage, boolean) - */ @Override public void displaySource(Object context, IWorkbenchPage page, boolean forceSourceLookup) { if (context instanceof IAdaptable) { diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java index df5fe6ded..9ba292322 100644 --- a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java +++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/views/launch/LaunchView.java @@ -474,9 +474,7 @@ public class LaunchView extends AbstractDebugView private ISelectionChangedListener fTreeViewerSelectionChangedListener = new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { - if (isActive()) { - fTreeViewerDebugContextProvider.activate(event.getSelection()); - } + fTreeViewerDebugContextProvider.activate(event.getSelection()); } }; -- cgit v1.2.3