diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/ConsoleMessages.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/ConsoleMessages.java index a3d71971002..8d9f8926760 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/ConsoleMessages.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/ConsoleMessages.java @@ -46,6 +46,9 @@ public class ConsoleMessages extends NLS { public static String ConsoleSelectAllAction_name; public static String ConsoleSelectAllAction_description; + public static String ConsoleAutoTerminateAction_name; + public static String ConsoleAutoTerminateAction_description; + static { // initialize resource bundle NLS.initializeMessages(ConsoleMessages.class.getName(), ConsoleMessages.class); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/ConsoleMessages.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/ConsoleMessages.properties index d89c2e189db..25be82322e9 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/ConsoleMessages.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/ConsoleMessages.properties @@ -37,4 +37,7 @@ ConsolePasteAction_name=&Paste ConsolePasteAction_description=Paste contents of clip-board to console ConsoleSelectAllAction_name=Select &All -ConsoleSelectAllAction_description=Select All available text in the associated console \ No newline at end of file +ConsoleSelectAllAction_description=Select All available text in the associated console + +ConsoleAutoTerminateAction_name=Terminate GDB when last process exits +ConsoleAutoTerminateAction_description=Automatically terminate GDB when the last process being debugged exits diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbAutoTerminateAction.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbAutoTerminateAction.java new file mode 100644 index 00000000000..facd4f2d5a5 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbAutoTerminateAction.java @@ -0,0 +1,52 @@ +/******************************************************************************* + * Copyright (c) 2016 Ericsson 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 + *******************************************************************************/ +package org.eclipse.cdt.dsf.gdb.internal.ui.console; + +import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants; +import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.osgi.service.prefs.BackingStoreException; + +/** + * Action to toggle the preference to terminate GDB when last process exits + */ +public class GdbAutoTerminateAction extends Action { + + public GdbAutoTerminateAction() { + super(ConsoleMessages.ConsoleAutoTerminateAction_name, IAction.AS_CHECK_BOX); + setToolTipText(ConsoleMessages.ConsoleAutoTerminateAction_description); + + // initialize state + setChecked(readState()); + } + + private boolean readState() { + return Platform.getPreferencesService().getBoolean(GdbPlugin.PLUGIN_ID, + IGdbDebugPreferenceConstants.PREF_AUTO_TERMINATE_GDB, + true, null); + } + + @Override + public void run() { + // All we need to do is update the preference store. There is no other + // immediate action to take. + IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(GdbPlugin.PLUGIN_ID); + if (preferences != null) { + preferences.putBoolean(IGdbDebugPreferenceConstants.PREF_AUTO_TERMINATE_GDB, !readState()); + + try { + preferences.flush(); + } catch (BackingStoreException e) { + } + } + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java index 22a9a1d3bc5..5cb28d53085 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsolePage.java @@ -32,6 +32,8 @@ import org.eclipse.jface.action.IToolBarManager; import org.eclipse.jface.action.MenuManager; import org.eclipse.jface.action.Separator; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; @@ -63,11 +65,16 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener /** The control for the terminal widget embedded in the console */ private ITerminalViewControl fTerminalControl; + private GdbConsoleClearAction fClearAction; private GdbConsoleCopyAction fCopyAction; private GdbConsolePasteAction fPasteAction; private GdbConsoleScrollLockAction fScrollLockAction; private GdbConsoleSelectAllAction fSelectAllAction; + private GdbAutoTerminateAction fAutoTerminateAction; + + private IPropertyChangeListener fConsolePropertyChangeListener; + public GdbFullCliConsolePage(GdbFullCliConsole gdbConsole, IDebuggerConsoleView view) { fConsole = gdbConsole; @@ -79,6 +86,19 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener fSession = null; assert false; } + + fConsolePropertyChangeListener = new IPropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent event) { + if (event.getProperty().equals(IGdbDebugPreferenceConstants.PREF_AUTO_TERMINATE_GDB) && fAutoTerminateAction != null) { + String terminateStr = event.getNewValue().toString(); + boolean terminate = terminateStr.equals(Boolean.FALSE.toString()) ? false : true; + fAutoTerminateAction.setChecked(terminate); + } + } + }; + + GdbUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fConsolePropertyChangeListener); } @Override @@ -88,6 +108,8 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener getSite().getWorkbenchWindow()).removeDebugContextListener(this); fTerminalControl.disposeTerminal(); fMenuManager.dispose(); + + GdbUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fConsolePropertyChangeListener); } @Override @@ -148,6 +170,7 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener fPasteAction = new GdbConsolePasteAction(fTerminalControl); fScrollLockAction = new GdbConsoleScrollLockAction(fTerminalControl); fSelectAllAction = new GdbConsoleSelectAllAction(fTerminalControl); + fAutoTerminateAction = new GdbAutoTerminateAction(); } protected void configureToolBar(IToolBarManager mgr) { @@ -170,6 +193,7 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener menuManager.add(fTerminateLaunchAction); menuManager.add(fInvertColorsAction); + menuManager.add(fAutoTerminateAction); } @Override