mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 17:35:35 +02:00
Bug 303808: Add menu context to the debugger console to invert colors
Change-Id: I5f7137cd0372c554afd2861aa42ba3cf0c2ae7ba
This commit is contained in:
parent
999c2e97cc
commit
5e9332c8ab
9 changed files with 117 additions and 4 deletions
Binary file not shown.
After Width: | Height: | Size: 381 B |
|
@ -25,6 +25,9 @@ public class ConsoleMessages extends NLS {
|
|||
public static String ConsoleMessages_save_info_io_error_title;
|
||||
public static String ConsoleMessages_save_info_io_error_desc;
|
||||
|
||||
public static String ConsoleInvertColorsAction_name;
|
||||
public static String ConsoleInvertColorsAction_description;
|
||||
|
||||
static {
|
||||
// initialize resource bundle
|
||||
NLS.initializeMessages(ConsoleMessages.class.getName(), ConsoleMessages.class);
|
||||
|
|
|
@ -17,3 +17,6 @@ ConsoleMessages_save_confirm_overwrite_title=Confirm overwrite
|
|||
ConsoleMessages_save_confirm_overwrite_desc=File exists, do you want overwrite it?
|
||||
ConsoleMessages_save_info_io_error_title=Error
|
||||
ConsoleMessages_save_info_io_error_desc=Error during save console content. Task failed.
|
||||
|
||||
ConsoleInvertColorsAction_name=Invert Colors
|
||||
ConsoleInvertColorsAction_description=Invert the colors for the gdb consoles
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.ui.part.IPageBookViewPage;
|
|||
public class GdbCliConsole extends AbstractConsole implements IDebuggerConsole {
|
||||
private final ILaunch fLaunch;
|
||||
private String fLabel;
|
||||
private GdbCliConsolePage fConsolePage;
|
||||
|
||||
public GdbCliConsole(ILaunch launch, String label) {
|
||||
super(label, null);
|
||||
|
@ -79,7 +80,8 @@ public class GdbCliConsole extends AbstractConsole implements IDebuggerConsole {
|
|||
@Override
|
||||
public IPageBookViewPage createPage(IDebuggerConsoleView view) {
|
||||
view.setFocus();
|
||||
return new GdbCliConsolePage(this, view);
|
||||
fConsolePage = new GdbCliConsolePage(this, view);
|
||||
return fConsolePage;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -87,4 +89,10 @@ public class GdbCliConsole extends AbstractConsole implements IDebuggerConsole {
|
|||
// This console is not used in the IConsoleView
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setInvertedColors(boolean enable) {
|
||||
if (fConsolePage != null) {
|
||||
fConsolePage.setInvertedColors(enable);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ import java.util.concurrent.RejectedExecutionException;
|
|||
import org.eclipse.cdt.debug.ui.debuggerconsole.IDebuggerConsole;
|
||||
import org.eclipse.cdt.debug.ui.debuggerconsole.IDebuggerConsoleView;
|
||||
import org.eclipse.cdt.dsf.concurrent.DsfRunnable;
|
||||
import org.eclipse.cdt.dsf.gdb.IGdbDebugPreferenceConstants;
|
||||
import org.eclipse.cdt.dsf.gdb.internal.ui.GdbUIPlugin;
|
||||
import org.eclipse.cdt.dsf.gdb.launching.GdbLaunch;
|
||||
import org.eclipse.cdt.dsf.gdb.service.IGDBBackend;
|
||||
|
@ -26,11 +27,15 @@ import org.eclipse.debug.core.ILaunch;
|
|||
import org.eclipse.debug.ui.DebugUITools;
|
||||
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.MenuManager;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.tm.internal.terminal.control.ITerminalListener;
|
||||
import org.eclipse.tm.internal.terminal.control.ITerminalViewControl;
|
||||
import org.eclipse.tm.internal.terminal.control.TerminalViewControlFactory;
|
||||
|
@ -51,6 +56,10 @@ public class GdbCliConsolePage extends Page implements IDebugContextListener {
|
|||
private IDebuggerConsoleView fView;
|
||||
private IDebuggerConsole fConsole;
|
||||
|
||||
private MenuManager fMenuManager;
|
||||
|
||||
private GdbConsoleInvertColorsAction fInvertColorsAction;
|
||||
|
||||
/** The control for the terminal widget embedded in the console */
|
||||
private ITerminalViewControl fTerminalControl;
|
||||
|
||||
|
@ -71,6 +80,7 @@ public class GdbCliConsolePage extends Page implements IDebugContextListener {
|
|||
DebugUITools.getDebugContextManager().getContextService(
|
||||
getSite().getWorkbenchWindow()).removeDebugContextListener(this);
|
||||
fTerminalControl.disposeTerminal();
|
||||
fMenuManager.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -82,6 +92,14 @@ public class GdbCliConsolePage extends Page implements IDebugContextListener {
|
|||
DebugUITools.getDebugContextManager().getContextService(
|
||||
getSite().getWorkbenchWindow()).addDebugContextListener(this);
|
||||
|
||||
createTerminalControl();
|
||||
createContextMenu();
|
||||
|
||||
// Hook the terminal control to the GDB process
|
||||
attachTerminalToGdbProcess();
|
||||
}
|
||||
|
||||
private void createTerminalControl() {
|
||||
// Create the terminal control that will be used to interact with GDB
|
||||
fTerminalControl = TerminalViewControlFactory.makeControl(
|
||||
new ITerminalListener() {
|
||||
|
@ -96,9 +114,30 @@ public class GdbCliConsolePage extends Page implements IDebugContextListener {
|
|||
fTerminalControl.setEncoding(Charset.defaultCharset().name());
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
}
|
||||
|
||||
// Hook the terminal control to the GDB process
|
||||
attachTerminalToGdbProcess();
|
||||
|
||||
// Set the inverted colors option based on the stored preference
|
||||
IPreferenceStore store = GdbUIPlugin.getDefault().getPreferenceStore();
|
||||
setInvertedColors(store.getBoolean(IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS));
|
||||
}
|
||||
|
||||
protected void createContextMenu() {
|
||||
fMenuManager = new MenuManager();
|
||||
fMenuManager.setRemoveAllWhenShown(true);
|
||||
fMenuManager.addMenuListener((menuManager) -> { contextMenuAboutToShow(menuManager); });
|
||||
Menu menu = fMenuManager.createContextMenu(fTerminalControl.getControl());
|
||||
fTerminalControl.getControl().setMenu(menu);
|
||||
|
||||
createActions();
|
||||
|
||||
getSite().registerContextMenu(null, fMenuManager, getSite().getSelectionProvider());
|
||||
}
|
||||
|
||||
protected void createActions() {
|
||||
fInvertColorsAction = new GdbConsoleInvertColorsAction();
|
||||
}
|
||||
|
||||
protected void contextMenuAboutToShow(IMenuManager menuManager) {
|
||||
menuManager.add(fInvertColorsAction);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -200,4 +239,8 @@ public class GdbCliConsolePage extends Page implements IDebugContextListener {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setInvertedColors(boolean enable) {
|
||||
fTerminalControl.setInvertedColors(enable);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*******************************************************************************
|
||||
* 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.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;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.core.runtime.preferences.InstanceScope;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.osgi.service.prefs.BackingStoreException;
|
||||
|
||||
/**
|
||||
* Action to toggle the inverted colors setting of all the GDB consoles
|
||||
*/
|
||||
public class GdbConsoleInvertColorsAction extends Action {
|
||||
|
||||
public GdbConsoleInvertColorsAction() {
|
||||
setText(ConsoleMessages.ConsoleInvertColorsAction_name);
|
||||
setToolTipText(ConsoleMessages.ConsoleInvertColorsAction_description);
|
||||
setImageDescriptor(GdbUIPlugin.getImageDescriptor(IConsoleImagesConst.IMG_CONSOLE_INVERT_COLORS));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(GdbPlugin.PLUGIN_ID);
|
||||
boolean enabled = preferences.getBoolean(IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS, false);
|
||||
preferences.putBoolean(IGdbDebugPreferenceConstants.PREF_CONSOLE_INVERTED_COLORS, !enabled);
|
||||
try {
|
||||
preferences.flush();
|
||||
} catch (BackingStoreException e) {
|
||||
}
|
||||
|
||||
IDebuggerConsoleManager manager = CDebugUIPlugin.getDebuggerConsoleManager();
|
||||
for (IDebuggerConsole console : manager.getConsoles()) {
|
||||
if (console instanceof GdbCliConsole) {
|
||||
((GdbCliConsole)console).setInvertedColors(!enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -15,4 +15,5 @@ package org.eclipse.cdt.dsf.gdb.internal.ui.console;
|
|||
*/
|
||||
public interface IConsoleImagesConst {
|
||||
public static final String IMG_SAVE_CONSOLE = "icons/full/obj16/save_console.gif"; //$NON-NLS-1$
|
||||
public static final String IMG_CONSOLE_INVERT_COLORS = "icons/full/obj16/console_invert_colors.gif"; //$NON-NLS-1$
|
||||
}
|
||||
|
|
|
@ -172,5 +172,10 @@ 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 <code>false</code>.
|
||||
* @since 5.1
|
||||
*/
|
||||
public static final String PREF_CONSOLE_INVERTED_COLORS = PREFIX + "consoleInvertedColors"; //$NON-NLS-1$
|
||||
}
|
||||
|
||||
|
|
|
@ -47,5 +47,6 @@ 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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue