mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-15 20:25:46 +02:00
Contribution from bug #154854 - GDB console - verbose console mode and save console content buttons
This commit is contained in:
parent
25b75b4163
commit
814e8ae7b6
11 changed files with 323 additions and 2 deletions
|
@ -22,5 +22,6 @@ Require-Bundle: org.eclipse.core.resources,
|
|||
org.eclipse.debug.core,
|
||||
org.eclipse.debug.ui,
|
||||
org.eclipse.core.runtime,
|
||||
org.eclipse.ui.console
|
||||
org.eclipse.ui.console,
|
||||
org.eclipse.jface.text
|
||||
Eclipse-LazyStart: true
|
||||
|
|
BIN
debug/org.eclipse.cdt.debug.mi.ui/icons/obj16/save_console.gif
Normal file
BIN
debug/org.eclipse.cdt.debug.mi.ui/icons/obj16/save_console.gif
Normal file
Binary file not shown.
After Width: | Height: | Size: 641 B |
|
@ -72,5 +72,15 @@
|
|||
tooltip="%VerboseMode.tooltip"/>
|
||||
</objectContribution>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.console.consolePageParticipants">
|
||||
<consolePageParticipant
|
||||
class="org.eclipse.cdt.debug.mi.ui.console.MiConsolePageParticipant"
|
||||
id="org.eclipse.cdt.debug.mi.ui.console.miConsolePageParticipant">
|
||||
<enablement>
|
||||
<instanceof value="org.eclipse.debug.internal.ui.views.console.ProcessConsole"/>
|
||||
</enablement>
|
||||
</consolePageParticipant>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package org.eclipse.cdt.debug.mi.internal.ui.actions;
|
||||
|
||||
import org.eclipse.cdt.debug.mi.core.GDBProcess;
|
||||
import org.eclipse.cdt.debug.mi.ui.console.VerboseModeChangedEvent;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
|
@ -35,6 +36,7 @@ public class VerboseModeActionDelegate extends ActionDelegate implements IObject
|
|||
if ( fProcess != null ) {
|
||||
boolean enabled = fProcess.getTarget().isVerboseModeEnabled();
|
||||
fProcess.getTarget().enableVerboseMode( !enabled );
|
||||
fProcess.getTarget().getMISession().notifyObservers(new VerboseModeChangedEvent(fProcess.getTarget().getMISession(),0));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +46,8 @@ public class VerboseModeActionDelegate extends ActionDelegate implements IObject
|
|||
public void selectionChanged( IAction action, ISelection selection ) {
|
||||
IStructuredSelection s = (IStructuredSelection)selection;
|
||||
fProcess = ( !s.isEmpty() ) ? (GDBProcess)s.getFirstElement() : null;
|
||||
action.setEnabled( fProcess != null );
|
||||
action.setEnabled( fProcess != null && !fProcess.isTerminated());
|
||||
action.setChecked( fProcess != null && fProcess.getTarget().isVerboseModeEnabled() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,110 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 STMicroelectronics.
|
||||
* 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:
|
||||
* STMicroelectronics - Process console enhancements
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.mi.ui.console;
|
||||
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import org.eclipse.cdt.debug.mi.core.GDBProcess;
|
||||
import org.eclipse.cdt.debug.mi.ui.console.actions.MiConsoleSaveAction;
|
||||
import org.eclipse.cdt.debug.mi.ui.console.actions.MiConsoleVerboseModeAction;
|
||||
import org.eclipse.debug.core.DebugEvent;
|
||||
import org.eclipse.debug.core.DebugPlugin;
|
||||
import org.eclipse.debug.core.IDebugEventSetListener;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.console.IConsoleConstants;
|
||||
import org.eclipse.ui.console.IConsolePageParticipant;
|
||||
import org.eclipse.ui.part.IPageBookViewPage;
|
||||
import org.eclipse.ui.console.IConsole;
|
||||
|
||||
/**
|
||||
* Enhances ProcessConsole when the process attached is a GDBProcess
|
||||
*
|
||||
*/
|
||||
public class MiConsolePageParticipant implements IConsolePageParticipant, IDebugEventSetListener, Observer {
|
||||
|
||||
private MiConsoleSaveAction fSaveConsole = null;
|
||||
private MiConsoleVerboseModeAction fVerboseMode = null;
|
||||
private org.eclipse.debug.ui.console.IConsole fConsole = null;
|
||||
private org.eclipse.cdt.debug.mi.core.GDBProcess GDBProcess = null;
|
||||
|
||||
public void activated() {
|
||||
}
|
||||
|
||||
public void deactivated() {
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
if(GDBProcess != null) {
|
||||
DebugPlugin.getDefault().removeDebugEventListener(this);
|
||||
}
|
||||
fSaveConsole = null;
|
||||
fVerboseMode = null;
|
||||
GDBProcess = null;
|
||||
fConsole = null;
|
||||
}
|
||||
|
||||
public void init(IPageBookViewPage page, IConsole console) {
|
||||
|
||||
if(console instanceof org.eclipse.debug.ui.console.IConsole)
|
||||
{
|
||||
fConsole = (org.eclipse.debug.ui.console.IConsole) console;
|
||||
if(fConsole.getProcess() instanceof GDBProcess) {
|
||||
|
||||
GDBProcess = (GDBProcess) fConsole.getProcess();
|
||||
|
||||
// add two new actions: save console content and verbose console mode switcher
|
||||
IActionBars bars = page.getSite().getActionBars();
|
||||
bars.getToolBarManager().appendToGroup(IConsoleConstants.LAUNCH_GROUP, new Separator());
|
||||
fSaveConsole = new MiConsoleSaveAction(fConsole);
|
||||
bars.getToolBarManager().appendToGroup(IConsoleConstants.LAUNCH_GROUP, fSaveConsole);
|
||||
fVerboseMode = new MiConsoleVerboseModeAction(fConsole);
|
||||
bars.getToolBarManager().appendToGroup(IConsoleConstants.LAUNCH_GROUP, fVerboseMode);
|
||||
bars.getToolBarManager().appendToGroup(IConsoleConstants.LAUNCH_GROUP, new Separator());
|
||||
|
||||
// add a debug event listener
|
||||
DebugPlugin.getDefault().addDebugEventListener(this);
|
||||
|
||||
// register this object as MISession observer
|
||||
GDBProcess.getTarget().getMISession().addObserver(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Object getAdapter(Class adapter) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void handleDebugEvents(DebugEvent[] events) {
|
||||
for (int i = 0; i < events.length; i++) {
|
||||
DebugEvent event = events[i];
|
||||
if (event.getSource().equals(GDBProcess)) {
|
||||
if (fVerboseMode != null) {
|
||||
fVerboseMode.setEnabled(!GDBProcess.isTerminated());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle MISession notification
|
||||
*/
|
||||
public void update(Observable arg0, Object arg1) {
|
||||
if((arg1!=null) && (arg1 instanceof VerboseModeChangedEvent) && (fVerboseMode != null)) {
|
||||
try {
|
||||
fVerboseMode.setChecked(GDBProcess.getTarget().isVerboseModeEnabled());
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 STMicroelectronics.
|
||||
* 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:
|
||||
* STMicroelectronics - Process console enhancements
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.mi.ui.console;
|
||||
|
||||
import org.eclipse.cdt.debug.mi.core.MISession;
|
||||
import org.eclipse.cdt.debug.mi.core.event.MIEvent;
|
||||
|
||||
/**
|
||||
* MISession event, verbose console mode changed
|
||||
*
|
||||
*/
|
||||
public class VerboseModeChangedEvent extends MIEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public VerboseModeChangedEvent(MISession session, int token) {
|
||||
super(session, token);
|
||||
setPropagate(false);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 STMicroelectronics.
|
||||
* 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:
|
||||
* STMicroelectronics - Process console enhancements
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.mi.ui.console.actions;
|
||||
|
||||
public interface IMiConsoleImagesConst {
|
||||
|
||||
public static final String IMG_SAVE_CONSOLE = "icons/obj16/save_console.gif";
|
||||
public static final String IMG_VERBOSE_CONSOLE = "icons/obj16/verbose_mode_co.gif";
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 STMicroelectronics.
|
||||
* 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:
|
||||
* STMicroelectronics - Process console enhancements
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.mi.ui.console.actions;
|
||||
|
||||
import org.eclipse.osgi.util.NLS;
|
||||
|
||||
public class MiConsoleMessages extends NLS {
|
||||
private static final String BUNDLE_NAME = "org.eclipse.cdt.debug.mi.ui.console.actions.MiConsoleMessages";
|
||||
|
||||
public static String saveActionTooltip;
|
||||
public static String verboseActionTooltip;
|
||||
|
||||
public static String confirmOverWrite;
|
||||
public static String infoIOError;
|
||||
|
||||
static {
|
||||
// load message values from bundle file
|
||||
NLS.initializeMessages(BUNDLE_NAME, MiConsoleMessages.class);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
saveActionTooltip=Save console content
|
||||
verboseActionTooltip=Verbose console mode
|
||||
confirmOverWrite=File exists, do you want overwrite it?
|
||||
infoIOError=Error during save console content. Task failed.
|
|
@ -0,0 +1,77 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 STMicroelectronics.
|
||||
* 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:
|
||||
* STMicroelectronics - Process console enhancements
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.debug.mi.ui.console.actions;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.cdt.debug.mi.internal.ui.MIUIPlugin;
|
||||
import org.eclipse.debug.ui.console.IConsole;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.BusyIndicator;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
|
||||
/**
|
||||
* Save console content
|
||||
*
|
||||
*/
|
||||
public class MiConsoleSaveAction extends Action{
|
||||
|
||||
private IConsole fConsole;
|
||||
private String fileName;
|
||||
|
||||
public MiConsoleSaveAction(IConsole console) {
|
||||
super();
|
||||
setToolTipText(MiConsoleMessages.saveActionTooltip);
|
||||
setImageDescriptor(MIUIPlugin.imageDescriptorFromPlugin(MIUIPlugin.PLUGIN_ID,IMiConsoleImagesConst.IMG_SAVE_CONSOLE));
|
||||
fConsole = console;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
|
||||
FileDialog fileDialog = new FileDialog(Display.getCurrent().getActiveShell(), SWT.SAVE);
|
||||
fileName = fileDialog.open();
|
||||
|
||||
Runnable saveJob = new Runnable() {
|
||||
public void run() {
|
||||
saveContent();
|
||||
}
|
||||
};
|
||||
BusyIndicator.showWhile(Display.getCurrent(), saveJob);
|
||||
|
||||
}
|
||||
|
||||
protected void saveContent() {
|
||||
boolean confirmed = true;
|
||||
|
||||
try {
|
||||
File f = new File(fileName);
|
||||
if(f.exists()) {
|
||||
confirmed = MessageDialog.openQuestion(Display.getCurrent().getActiveShell(), "Confirm overwrite", MiConsoleMessages.confirmOverWrite);
|
||||
}
|
||||
if(confirmed) {
|
||||
BufferedWriter out = new BufferedWriter(new FileWriter(fileName));
|
||||
out.write(fConsole.getDocument().get());
|
||||
out.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
MessageDialog.openError(Display.getCurrent().getActiveShell(),"Error",MiConsoleMessages.infoIOError);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 STMicroelectronics.
|
||||
* 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:
|
||||
* STMicroelectronics - Process console enhancements
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.debug.mi.ui.console.actions;
|
||||
|
||||
import org.eclipse.cdt.debug.mi.core.GDBProcess;
|
||||
import org.eclipse.cdt.debug.mi.internal.ui.MIUIPlugin;
|
||||
import org.eclipse.debug.ui.console.IConsole;
|
||||
import org.eclipse.jface.action.Action;
|
||||
|
||||
/**
|
||||
* Verbose console mode switcher
|
||||
*
|
||||
*/
|
||||
public class MiConsoleVerboseModeAction extends Action {
|
||||
|
||||
private IConsole fConsole;
|
||||
|
||||
public MiConsoleVerboseModeAction(IConsole console) {
|
||||
super();
|
||||
setToolTipText(MiConsoleMessages.verboseActionTooltip);
|
||||
setImageDescriptor(MIUIPlugin.imageDescriptorFromPlugin(MIUIPlugin.PLUGIN_ID,IMiConsoleImagesConst.IMG_VERBOSE_CONSOLE));
|
||||
fConsole = console;
|
||||
GDBProcess fProcess = (GDBProcess) fConsole.getProcess();
|
||||
setChecked(fProcess.getTarget().getMISession().isVerboseModeEnabled());
|
||||
}
|
||||
|
||||
public void run() {
|
||||
GDBProcess fProcess = (GDBProcess) fConsole.getProcess();
|
||||
fProcess.getTarget().enableVerboseMode(isChecked());
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue