diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java index 5a50b774632..aab89ed89c5 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbConnectCommand.java @@ -40,8 +40,8 @@ import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; import org.eclipse.cdt.dsf.gdb.actions.IConnect; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; import org.eclipse.cdt.dsf.gdb.internal.ui.actions.ProcessInfo; -import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableInfo; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.LaunchUIMessages; +import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableInfo; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.ProcessPrompter; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.ProcessPrompter.PrompterInfo; import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch; @@ -61,7 +61,6 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.IRequest; -import org.eclipse.debug.core.commands.AbstractDebugCommand; import org.eclipse.debug.core.commands.IDebugCommandRequest; import org.eclipse.debug.core.commands.IEnabledStateRequest; import org.eclipse.swt.SWT; @@ -70,7 +69,7 @@ import org.eclipse.swt.widgets.FileDialog; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.progress.UIJob; -public class GdbConnectCommand extends AbstractDebugCommand implements IConnectHandler, IConnect { +public class GdbConnectCommand extends RefreshableDebugCommand implements IConnectHandler, IConnect { private final GdbLaunch fLaunch; private final DsfExecutor fExecutor; @@ -279,7 +278,9 @@ public class GdbConnectCommand extends AbstractDebugCommand implements IConnectH // cancelled it. } catch (RejectedExecutionException e) { // Can be thrown if the session is shutdown - } + } finally { + updateEnablement(); + } } /* diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java index 4631445ea5c..b7b4305c1e1 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/GdbDebugNewExecutableCommand.java @@ -29,8 +29,8 @@ import org.eclipse.cdt.dsf.debug.service.IProcesses; import org.eclipse.cdt.dsf.debug.service.command.ICommandControlService; import org.eclipse.cdt.dsf.gdb.IGDBLaunchConfigurationConstants; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; -import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableInfo; import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableDialog; +import org.eclipse.cdt.dsf.gdb.internal.ui.launching.NewExecutableInfo; import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch; import org.eclipse.cdt.dsf.gdb.service.IGDBBackend; import org.eclipse.cdt.dsf.gdb.service.SessionType; @@ -43,12 +43,11 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; import org.eclipse.debug.core.ILaunchConfiguration; import org.eclipse.debug.core.IRequest; -import org.eclipse.debug.core.commands.AbstractDebugCommand; import org.eclipse.debug.core.commands.IEnabledStateRequest; import org.eclipse.jface.window.Window; import org.eclipse.ui.progress.UIJob; -public class GdbDebugNewExecutableCommand extends AbstractDebugCommand implements IDebugNewExecutableHandler { +public class GdbDebugNewExecutableCommand extends RefreshableDebugCommand implements IDebugNewExecutableHandler { private class PromptJob extends UIJob { @@ -188,6 +187,8 @@ public class GdbDebugNewExecutableCommand extends AbstractDebugCommand implement } catch( RejectedExecutionException e ) { // Can be thrown if the session is shutdown + } finally { + updateEnablement(); } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/RefreshableDebugCommand.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/RefreshableDebugCommand.java new file mode 100644 index 00000000000..c2f72c0d156 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/commands/RefreshableDebugCommand.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2013 Mentor Graphics and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Mentor Graphics - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.dsf.gdb.internal.ui.commands; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.debug.core.commands.AbstractDebugCommand; +import org.eclipse.debug.ui.IDebugUIConstants; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPartSite; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.progress.UIJob; + +/** + * The enablement of a {@link AbstractDebugCommand} is updated only when the current + * debug context is changed. In some cases we need to force an update without changing + * the context. This class provides such a functionality. + * The proper way is to modify {@link AbstractDebugCommand}. + */ +public abstract class RefreshableDebugCommand extends AbstractDebugCommand { + + protected class UpdateEnablementJob extends UIJob { + + protected UpdateEnablementJob() { + super("Update enablement job"); //$NON-NLS-1$ + } + + @Override + public IStatus runInUIThread(IProgressMonitor monitor) { + // Reseting the current selection in the Debug view will force the enablement update + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window != null) { + IWorkbenchPage page = window.getActivePage(); + if (page != null) { + IViewPart view = page.findView(IDebugUIConstants.ID_DEBUG_VIEW); + if (view != null) { + IWorkbenchPartSite site = view.getSite(); + if (site != null) { + ISelectionProvider selProvider = site.getSelectionProvider(); + if (selProvider != null) { + selProvider.setSelection(selProvider.getSelection()); + } + } + } + } + } + return Status.OK_STATUS; + } + } + + protected void updateEnablement() { + new UpdateEnablementJob().schedule(); + } +}