From b63adf43dbb4275edb76e439112147095cf53b54 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez-Leon Date: Wed, 14 Sep 2016 16:35:08 -0400 Subject: [PATCH] Bug 303808: Add a Preference page for GDB CLI consoles In addition, a new "Preferences" Action is available for the GDB CLI consoles so the user can easily find/adjust them. Change-Id: I8d2756683f92ca9b42454906dd600c97e1e07cd2 Signed-off-by: Alvaro Sanchez-Leon --- .../plugin.properties | 5 +- dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.xml | 8 +- .../internal/ui/console/ConsoleMessages.java | 2 + .../ui/console/ConsoleMessages.properties | 2 + .../GdbAbstractConsolePreferenceListener.java | 38 ++++++++++ .../ui/console/GdbBasicCliConsole.java | 48 ++++++++++-- .../ui/console/GdbBasicCliConsolePage.java | 5 ++ .../console/GdbConsoleInvertColorsAction.java | 10 --- .../GdbConsoleShowPreferencesAction.java | 27 +++++++ .../ui/console/GdbFullCliConsole.java | 9 +-- .../ui/console/GdbFullCliConsolePage.java | 76 +++++++++++++------ .../internal/ui/console/IGdbCliConsole.java | 17 ----- .../preferences/GdbConsolePreferencePage.java | 68 +++++++++++++++++ .../preferences/MessagesForPreferences.java | 5 +- .../MessagesForPreferences.properties | 5 +- .../dsf/gdb/IGdbDebugPreferenceConstants.java | 22 +++++- .../internal/GdbPreferenceInitializer.java | 3 +- 17 files changed, 277 insertions(+), 73 deletions(-) create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbAbstractConsolePreferenceListener.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbConsoleShowPreferencesAction.java delete mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/IGdbCliConsole.java create mode 100644 dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbConsolePreferencePage.java diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.properties index 4a570463e63..1023fbddb91 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.properties @@ -60,4 +60,7 @@ view.osresources.name=OS Resources command.connect.description = Connect to selected processes command.connect.name = Connect command.connect.label = Connect -command.connect.tooltip = Connect to process \ No newline at end of file +command.connect.tooltip = Connect to process + +# GDB CLI Console +console.preferences.name = Console \ No newline at end of file diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.xml b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.xml index 3a309b27a00..16ca680837c 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.xml +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/plugin.xml @@ -523,7 +523,13 @@ class="org.eclipse.cdt.dsf.gdb.internal.ui.preferences.ReverseDebugPreferencePage" id="org.eclipse.cdt.dsf.gdb.ui.preferences.reversedebugpreferences" name="%reverseDebugPreferences.name"> - + + + 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 8d9f8926760..831e2869a32 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 @@ -49,6 +49,8 @@ public class ConsoleMessages extends NLS { public static String ConsoleAutoTerminateAction_name; public static String ConsoleAutoTerminateAction_description; + public static String GdbConsolePreferences_name; + 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 25be82322e9..8ad374aaafa 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 @@ -41,3 +41,5 @@ ConsoleSelectAllAction_description=Select All available text in the associated c ConsoleAutoTerminateAction_name=Terminate GDB when last process exits ConsoleAutoTerminateAction_description=Automatically terminate GDB when the last process being debugged exits + +GdbConsolePreferences_name=Preferences... diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbAbstractConsolePreferenceListener.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbAbstractConsolePreferenceListener.java new file mode 100644 index 00000000000..42c1422566e --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbAbstractConsolePreferenceListener.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * 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.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; + +public abstract class GdbAbstractConsolePreferenceListener implements IPropertyChangeListener { + + @Override + public void propertyChange(PropertyChangeEvent event) { + String property = event.getProperty(); + + if (property.equals(IGdbDebugPreferenceConstants.PREF_AUTO_TERMINATE_GDB)) { + String terminateStr = event.getNewValue().toString(); + boolean terminate = terminateStr.equals(Boolean.FALSE.toString()) ? false : true; + handleAutoTerminatePref(terminate); + } else if (property.equals(IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS)) { + boolean enabled = Platform.getPreferencesService().getBoolean(GdbPlugin.PLUGIN_ID, IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS, IGdbDebugPreferenceConstants.CONSOLE_INVERTED_COLORS_DEFAULT, null); + handleInvertColorsPref(enabled); + } else if (property.equals(IGdbDebugPreferenceConstants.PREF_CONSOLE_BUFFERLINES)) { + int bufferLines = Platform.getPreferencesService().getInt(GdbPlugin.PLUGIN_ID, IGdbDebugPreferenceConstants.PREF_CONSOLE_BUFFERLINES, IGdbDebugPreferenceConstants.CONSOLE_BUFFERLINES_DEFAULT, null); + handleBufferLinesPref(bufferLines); + } + } + + protected abstract void handleAutoTerminatePref(boolean enabled); + protected abstract void handleInvertColorsPref(boolean enabled); + protected abstract void handleBufferLinesPref(int bufferLines); +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbBasicCliConsole.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbBasicCliConsole.java index 05f2ecdcadb..0d01b85a646 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbBasicCliConsole.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbBasicCliConsole.java @@ -37,7 +37,13 @@ import org.eclipse.ui.part.IPageBookViewPage; * towards GDB. It is used whenever {@link IGDBBackend#isFullGdbConsoleSupported()} * returns false. */ -public class GdbBasicCliConsole extends IOConsole implements IDebuggerConsole, IGdbCliConsole { +public class GdbBasicCliConsole extends IOConsole implements IDebuggerConsole { + + /** + * A conversion factor used to resolve number of characters from number of lines + */ + private final static int CHARS_PER_LINE_AVG = 80; + private final static int HIGH_WATERMARK_OFFSET_CHARS = 8000; private final ILaunch fLaunch; private final String fLabel; @@ -45,6 +51,24 @@ public class GdbBasicCliConsole extends IOConsole implements IDebuggerConsole, I private final IOConsoleOutputStream fOutputStream; private final IOConsoleOutputStream fErrorStream; + private GdbAbstractConsolePreferenceListener fPreferenceListener = new GdbAbstractConsolePreferenceListener() { + + @Override + protected void handleAutoTerminatePref(boolean enabled) { + // Nothing to do for this class + } + + @Override + protected void handleInvertColorsPref(boolean enabled) { + setInvertedColors(enabled); + } + + @Override + protected void handleBufferLinesPref(int bufferLines) { + setBufferLineLimit(bufferLines); + } + }; + public GdbBasicCliConsole(ILaunch launch, String label, Process process) { super("", null, null, false); //$NON-NLS-1$ fLaunch = launch; @@ -58,8 +82,10 @@ public class GdbBasicCliConsole extends IOConsole implements IDebuggerConsole, I // Create a lifecycle listener to call init() and dispose() new GdbConsoleLifecycleListener(this); + GdbUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPreferenceListener); + resetName(); - setColors(); + setDefaults(); new InputReadJob().schedule(); new OutputReadJob().schedule(); @@ -77,19 +103,22 @@ public class GdbBasicCliConsole extends IOConsole implements IDebuggerConsole, I } catch (IOException e) { } + GdbUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPreferenceListener); + super.dispose(); } - private void setColors() { - // Set the inverted colors option based on the stored preference + private void setDefaults() { IPreferenceStore store = GdbUIPlugin.getDefault().getPreferenceStore(); boolean enabled = store.getBoolean(IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS); + int bufferLines = store.getInt(IGdbDebugPreferenceConstants.PREF_CONSOLE_BUFFERLINES); Display.getDefault().asyncExec(() -> { getInputStream().setColor(Display.getDefault().getSystemColor(SWT.COLOR_GREEN)); fErrorStream.setColor(Display.getDefault().getSystemColor(SWT.COLOR_RED)); setInvertedColors(enabled); + setBufferLineLimit(bufferLines); }); } @@ -152,8 +181,7 @@ public class GdbBasicCliConsole extends IOConsole implements IDebuggerConsole, I return null; } - @Override - public void setInvertedColors(boolean enable) { + private void setInvertedColors(boolean enable) { if (enable) { setBackground(Display.getDefault().getSystemColor(SWT.COLOR_BLACK)); fOutputStream.setColor(Display.getDefault().getSystemColor(SWT.COLOR_WHITE)); @@ -163,6 +191,14 @@ public class GdbBasicCliConsole extends IOConsole implements IDebuggerConsole, I } } + private void setBufferLineLimit(int bufferLines) { + int chars = bufferLines * CHARS_PER_LINE_AVG; + // The buffer will be allowed to grow up-to the high watermark. + // When high watermark is passed, it will be trimmed-down to the low watermark. + // So here add an extra buffer for high watermark. + setWaterMarks(chars, chars + HIGH_WATERMARK_OFFSET_CHARS); + } + private class InputReadJob extends Job { { setSystem(true); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbBasicCliConsolePage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbBasicCliConsolePage.java index de1c9125050..f741f0c6c11 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbBasicCliConsolePage.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbBasicCliConsolePage.java @@ -16,6 +16,7 @@ import org.eclipse.debug.ui.contexts.DebugContextEvent; import org.eclipse.debug.ui.contexts.IDebugContextListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.action.Separator; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.console.IConsoleView; import org.eclipse.ui.internal.console.IOConsolePage; @@ -29,6 +30,7 @@ public class GdbBasicCliConsolePage extends IOConsolePage implements IDebugConte private GdbConsoleInvertColorsAction fInvertColorsAction; private GdbConsoleTerminateLaunchAction fTerminateLaunchAction; + private GdbConsoleShowPreferencesAction fShowPreferencePageAction; public GdbBasicCliConsolePage(GdbBasicCliConsole gdbConsole, IConsoleView view) { super(gdbConsole, view); @@ -58,12 +60,15 @@ public class GdbBasicCliConsolePage extends IOConsolePage implements IDebugConte protected void createActions() { fInvertColorsAction = new GdbConsoleInvertColorsAction(); fTerminateLaunchAction = new GdbConsoleTerminateLaunchAction(fLaunch); + fShowPreferencePageAction = new GdbConsoleShowPreferencesAction(getSite().getShell()); } @Override protected void contextMenuAboutToShow(IMenuManager menuManager) { menuManager.add(fTerminateLaunchAction); menuManager.add(fInvertColorsAction); + menuManager.add(new Separator()); + menuManager.add(fShowPreferencePageAction); } /** diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbConsoleInvertColorsAction.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbConsoleInvertColorsAction.java index b047dac83dc..fc2dc776365 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbConsoleInvertColorsAction.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbConsoleInvertColorsAction.java @@ -7,9 +7,6 @@ *******************************************************************************/ package org.eclipse.cdt.dsf.gdb.internal.ui.console; -import org.eclipse.cdt.debug.ui.CDebugUIPlugin; -import org.eclipse.cdt.debug.ui.debuggerconsole.IDebuggerConsole; -import org.eclipse.cdt.debug.ui.debuggerconsole.IDebuggerConsoleManager; import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants; import org.eclipse.cdt.dsf.gdb.internal.GdbPlugin; import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; @@ -38,12 +35,5 @@ public class GdbConsoleInvertColorsAction extends Action { preferences.flush(); } catch (BackingStoreException e) { } - - IDebuggerConsoleManager manager = CDebugUIPlugin.getDebuggerConsoleManager(); - for (IDebuggerConsole console : manager.getConsoles()) { - if (console instanceof IGdbCliConsole) { - ((IGdbCliConsole)console).setInvertedColors(!enabled); - } - } } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbConsoleShowPreferencesAction.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbConsoleShowPreferencesAction.java new file mode 100644 index 00000000000..45e69a5f026 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbConsoleShowPreferencesAction.java @@ -0,0 +1,27 @@ +/******************************************************************************* + * Copyright (c) 2016 Ericsson AB 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.jface.action.Action; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.dialogs.PreferencesUtil; + +public class GdbConsoleShowPreferencesAction extends Action { + private final static String PREF_PAGE_ID = "org.eclipse.cdt.dsf.gdb.ui.preferences.console.GdbConsolePreferencePage"; //$NON-NLS-1$ + private final Shell fShell; + + public GdbConsoleShowPreferencesAction(Shell shell) { + fShell = shell; + setText(ConsoleMessages.GdbConsolePreferences_name); + } + + @Override + public void run() { + PreferencesUtil.createPreferenceDialogOn(fShell, PREF_PAGE_ID, new String[] { PREF_PAGE_ID }, null).open(); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsole.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsole.java index 881bfa3635b..274d3da7287 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsole.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/GdbFullCliConsole.java @@ -36,7 +36,7 @@ import org.eclipse.ui.part.IPageBookViewPage; * full-featured CLI interface. This is only supported with GDB >= 7.12 * and if IGDBBackend.isFullGdbConsoleSupported() returns true. */ -public class GdbFullCliConsole extends AbstractConsole implements IDebuggerConsole, IGdbCliConsole { +public class GdbFullCliConsole extends AbstractConsole implements IDebuggerConsole { private final ILaunch fLaunch; private final String fLabel; private final PTY fGdbPty; @@ -203,13 +203,6 @@ public class GdbFullCliConsole extends AbstractConsole implements IDebuggerConso return fConsolePage; } - @Override - public void setInvertedColors(boolean enable) { - if (fConsolePage != null) { - fConsolePage.setInvertedColors(enable); - } - } - public IGdbTerminalControlConnector getTerminalControlConnector() { return fTerminalConnector; } 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 c0d3f8214b7..784e156fdb0 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 @@ -26,8 +26,6 @@ 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; @@ -67,8 +65,27 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener private GdbConsoleSelectAllAction fSelectAllAction; private GdbAutoTerminateAction fAutoTerminateAction; - private IPropertyChangeListener fConsolePropertyChangeListener; + private GdbConsoleShowPreferencesAction fShowPreferencePageAction; + private GdbAbstractConsolePreferenceListener fPreferenceListener = new GdbAbstractConsolePreferenceListener() { + + @Override + protected void handleAutoTerminatePref(boolean enabled) { + if (fAutoTerminateAction != null) { + fAutoTerminateAction.setChecked(enabled); + } + } + + @Override + protected void handleInvertColorsPref(boolean enabled) { + setInvertedColors(enabled); + } + + @Override + protected void handleBufferLinesPref(int bufferLines) { + setBufferLineLimit(bufferLines); + } + }; public GdbFullCliConsolePage(GdbFullCliConsole gdbConsole, IDebuggerConsoleView view, PTY pty) { fConsole = gdbConsole; @@ -76,19 +93,8 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener fView = view; fLaunch = gdbConsole.getLaunch(); fGdbPty = pty; - - 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); + + GdbUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(fPreferenceListener); } @Override @@ -98,8 +104,7 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener getSite().getWorkbenchWindow()).removeDebugContextListener(this); fTerminalControl.disposeTerminal(); fMenuManager.dispose(); - - GdbUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fConsolePropertyChangeListener); + GdbUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(fPreferenceListener); } @Override @@ -116,8 +121,16 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener configureToolBar(getSite().getActionBars().getToolBarManager()); } + private void setDefaults() { + IPreferenceStore store = GdbUIPlugin.getDefault().getPreferenceStore(); + setInvertedColors(store.getBoolean(IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS)); + setBufferLineLimit(store.getInt(IGdbDebugPreferenceConstants.PREF_CONSOLE_BUFFERLINES)); + } + private void createTerminalControl() { // Create the terminal control that will be used to interact with GDB + // Don't use common terminal preferences as GDB consoles are having their own + boolean useCommonPrefs = false; fTerminalControl = TerminalViewControlFactory.makeControl( new ITerminalListener() { @Override public void setState(TerminalState state) {} @@ -125,7 +138,7 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener }, fMainComposite, new ITerminalConnector[] {}, - true); + useCommonPrefs); fTerminalControl.setConnector(new GdbTerminalPageConnector(fGdbTerminalControlConnector, fGdbPty)); @@ -133,15 +146,11 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener fTerminalControl.setEncoding(Charset.defaultCharset().name()); } catch (UnsupportedEncodingException e) { } - if (fTerminalControl instanceof ITerminalControl) { ((ITerminalControl)fTerminalControl).setConnectOnEnterIfClosed(false); ((ITerminalControl)fTerminalControl).setVT100LineWrapping(true); } - // Set the inverted colors option based on the stored preference - IPreferenceStore store = GdbUIPlugin.getDefault().getPreferenceStore(); - setInvertedColors(store.getBoolean(IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS)); // Must use syncExec because the logic within must complete before the rest // of the class methods (specifically getProcess()) is called @@ -151,6 +160,10 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener if (fTerminalControl != null && !fTerminalControl.isDisposed()) { fTerminalControl.clearTerminal(); fTerminalControl.connectTerminal(); + + // The actual terminal widget initializes its defaults in the line above, + // lets override them with our application defaults right after. + setDefaults(); } } }); @@ -177,6 +190,7 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener fScrollLockAction = new GdbConsoleScrollLockAction(fTerminalControl); fSelectAllAction = new GdbConsoleSelectAllAction(fTerminalControl); fAutoTerminateAction = new GdbAutoTerminateAction(); + fShowPreferencePageAction = new GdbConsoleShowPreferencesAction(getSite().getShell()); } protected void configureToolBar(IToolBarManager mgr) { @@ -200,6 +214,9 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener menuManager.add(fTerminateLaunchAction); menuManager.add(fInvertColorsAction); menuManager.add(fAutoTerminateAction); + menuManager.add(new Separator()); + + menuManager.add(fShowPreferencePageAction); } @Override @@ -212,6 +229,7 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener fTerminalControl.setFocus(); } + /** * Returns the launch to which the current selection belongs. * @@ -236,7 +254,15 @@ public class GdbFullCliConsolePage extends Page implements IDebugContextListener } } - public void setInvertedColors(boolean enable) { - fTerminalControl.setInvertedColors(enable); + private void setInvertedColors(boolean enable) { + if (fTerminalControl != null) { + fTerminalControl.setInvertedColors(enable); + } + } + + private void setBufferLineLimit(int bufferLines) { + if (fTerminalControl != null) { + fTerminalControl.setBufferLineLimit(bufferLines); + } } } diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/IGdbCliConsole.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/IGdbCliConsole.java deleted file mode 100644 index 3fdefbde2bf..00000000000 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/console/IGdbCliConsole.java +++ /dev/null @@ -1,17 +0,0 @@ -/******************************************************************************* - * 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.ui.console.IConsole; - -public interface IGdbCliConsole extends IConsole { - /** - * Enable or disable the inverted color option of the console. - */ - void setInvertedColors(boolean enable); -} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbConsolePreferencePage.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbConsolePreferencePage.java new file mode 100644 index 00000000000..4f6466fc609 --- /dev/null +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/GdbConsolePreferencePage.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2016 Wind River Systems, Inc. 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 + * + * The Initial version is based on: + * org.eclipse.tm.terminal.control/src/org/eclipse/tm/internal/terminal/preferences/TerminalPreferencePage.java + *******************************************************************************/ +package org.eclipse.cdt.dsf.gdb.internal.ui.preferences; + +import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants; +import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin; +import org.eclipse.jface.preference.BooleanFieldEditor; +import org.eclipse.jface.preference.FieldEditorPreferencePage; +import org.eclipse.jface.preference.IntegerFieldEditor; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +/** + * GDB CLI Console Preference Page. + * + * @noextend This class is not intended to be subclassed by clients. + * @noinstantiate This class is not intended to be instantiated by clients. + * @noreference This class is not intended to be referenced by clients. + */ +public class GdbConsolePreferencePage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage { + private static final int MIN_BUFFER_LINES = 16; /* minimum of ~1000 chars */ + // Instead of using a maximum of Integer.MAX_VALUE (which is some obscure number), + // let's use a well defined limit e.g. 2 billion lines, which is readable. + private static final int MAX_BUFFER_LINES = 2000000000; + + public GdbConsolePreferencePage() { + super(GRID); + } + + @Override + protected void createFieldEditors() { + setupPage(); + } + + @Override + public void init(IWorkbench workbench) { + // do nothing + } + + private void setupPage() { + setupData(); + setupEditors(); + } + + private void setupData() { + setPreferenceStore(GdbUIPlugin.getDefault().getPreferenceStore()); + } + + private void setupEditors() { + BooleanFieldEditor invertColors = new BooleanFieldEditor(IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS, + MessagesForPreferences.GdbConsolePreferencePage_InvertColors, getFieldEditorParent()); + IntegerFieldEditor editorBufferSize = new IntegerFieldEditor(IGdbDebugPreferenceConstants.PREF_CONSOLE_BUFFERLINES, + MessagesForPreferences.GdbConsolePreferencePage_BufferLines, getFieldEditorParent()); + + editorBufferSize.setValidRange(MIN_BUFFER_LINES, MAX_BUFFER_LINES); + + addField(invertColors); + addField(editorBufferSize); + } +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java index c0cb4ee627d..3e04fa4994f 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2012 Ericsson and others. + * Copyright (c) 2009, 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 @@ -73,6 +73,9 @@ class MessagesForPreferences extends NLS { public static String ReverseDebugPreferencePage_BranchTrace; public static String ReverseDebugPreferencePage_ProcessorTrace; + public static String GdbConsolePreferencePage_InvertColors; + public static String GdbConsolePreferencePage_BufferLines; + static { // initialize resource bundle NLS.initializeMessages(MessagesForPreferences.class.getName(), MessagesForPreferences.class); diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties index 8f69ef8f8d4..ae219d7e35f 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb.ui/src/org/eclipse/cdt/dsf/gdb/internal/ui/preferences/MessagesForPreferences.properties @@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2009, 2012 Ericsson and others. +# Copyright (c) 2009, 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 @@ -61,3 +61,6 @@ ReverseDebugPreferencePage_SelectHardwareTracingMethod=Hardware technology for i ReverseDebugPreferencePage_GDBPreference=Automatic (let GDB choose) ReverseDebugPreferencePage_BranchTrace=Branch Trace Store ReverseDebugPreferencePage_ProcessorTrace=Intel(R) Processor Trace + +GdbConsolePreferencePage_InvertColors = Invert console colors +GdbConsolePreferencePage_BufferLines = Console buffer lines: diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java index 9e80264aba0..6ed79a0dd63 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/IGdbDebugPreferenceConstants.java @@ -173,9 +173,27 @@ public interface IGdbDebugPreferenceConstants { public static final String PREF_REVERSE_TRACE_METHOD_PROCESSOR_TRACE = "UseProcessorTrace"; //$NON-NLS-1$ /** - * Boolean preference indicating if the GDB console should be shown using inverted colors. Default is false. + * Preference key controlling the coloring of GDB CLI consoles * @since 5.2 */ public static final String PREF_CONSOLE_INVERTED_COLORS = PREFIX + "consoleInvertedColors"; //$NON-NLS-1$ -} + /** + * Default preference value for the colors used by GDB CLI consoles + * @since 5.2 + */ + public static final Boolean CONSOLE_INVERTED_COLORS_DEFAULT = false; + + /** + * Preference key controlling the number of buffered lines used by GDB CLI consoles + * @since 5.2 + */ + public static final String PREF_CONSOLE_BUFFERLINES = PREFIX + "consoleBufferLines"; //$NON-NLS-1$ + + /** + * Default preference value for the number of buffered lines used by GDB CLI consoles + * @since 5.2 + */ + public static final int CONSOLE_BUFFERLINES_DEFAULT = 1000; + +} diff --git a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java index 281e61b11e2..5565c709476 100644 --- a/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java +++ b/dsf-gdb/org.eclipse.cdt.dsf.gdb/src/org/eclipse/cdt/dsf/gdb/internal/GdbPreferenceInitializer.java @@ -47,6 +47,7 @@ public class GdbPreferenceInitializer extends AbstractPreferenceInitializer { node.putBoolean(IGdbDebugPreferenceConstants.PREF_HIDE_RUNNING_THREADS, false); node.putBoolean(IGdbDebugPreferenceConstants.PREF_AGGRESSIVE_BP_FILTER, true); node.put(IGdbDebugPreferenceConstants.PREF_REVERSE_TRACE_METHOD_HARDWARE, IGdbDebugPreferenceConstants.PREF_REVERSE_TRACE_METHOD_GDB_TRACE); - node.putBoolean(IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS, false); + node.putBoolean(IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS, IGdbDebugPreferenceConstants.CONSOLE_INVERTED_COLORS_DEFAULT); + node.putInt(IGdbDebugPreferenceConstants.PREF_CONSOLE_BUFFERLINES, IGdbDebugPreferenceConstants.CONSOLE_BUFFERLINES_DEFAULT); } }