|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 Marc-Andre Laperle and others. |
2 |
* Copyright (c) 2010, 2011 Marc-Andre Laperle and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 10-34
Link Here
|
| 10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.cdt.dsf.gdb.internal.ui.console; |
11 |
package org.eclipse.cdt.dsf.gdb.internal.ui.console; |
| 12 |
|
12 |
|
|
|
13 |
import org.eclipse.cdt.dsf.datamodel.DMContexts; |
| 14 |
import org.eclipse.cdt.dsf.datamodel.IDMContext; |
| 15 |
import org.eclipse.cdt.dsf.gdb.IGdbDebugConstants; |
| 13 |
import org.eclipse.cdt.dsf.gdb.launching.GDBProcess; |
16 |
import org.eclipse.cdt.dsf.gdb.launching.GDBProcess; |
|
|
17 |
import org.eclipse.cdt.dsf.gdb.launching.InferiorRuntimeProcess; |
| 18 |
import org.eclipse.cdt.dsf.mi.service.IMIContainerDMContext; |
| 19 |
import org.eclipse.core.runtime.IAdaptable; |
| 20 |
import org.eclipse.debug.core.ILaunch; |
| 21 |
import org.eclipse.debug.core.model.IProcess; |
| 22 |
import org.eclipse.debug.ui.DebugUITools; |
| 23 |
import org.eclipse.debug.ui.contexts.DebugContextEvent; |
| 24 |
import org.eclipse.debug.ui.contexts.IDebugContextListener; |
| 14 |
import org.eclipse.jface.action.IToolBarManager; |
25 |
import org.eclipse.jface.action.IToolBarManager; |
| 15 |
import org.eclipse.jface.action.Separator; |
26 |
import org.eclipse.jface.action.Separator; |
| 16 |
import org.eclipse.ui.console.IConsole; |
27 |
import org.eclipse.ui.console.IConsole; |
| 17 |
import org.eclipse.ui.console.IConsoleConstants; |
28 |
import org.eclipse.ui.console.IConsoleConstants; |
| 18 |
import org.eclipse.ui.console.IConsolePageParticipant; |
29 |
import org.eclipse.ui.console.IConsolePageParticipant; |
|
|
30 |
import org.eclipse.ui.console.IConsoleView; |
| 19 |
import org.eclipse.ui.console.TextConsole; |
31 |
import org.eclipse.ui.console.TextConsole; |
| 20 |
import org.eclipse.ui.part.IPageBookViewPage; |
32 |
import org.eclipse.ui.part.IPageBookViewPage; |
| 21 |
|
33 |
|
| 22 |
/** |
34 |
/** |
| 23 |
* A console page participant for both the gdb tracing console and the gdb CLI console |
35 |
* A console page participant for DSF-GDB. |
|
|
36 |
* It adds a save button to both the gdb tracing console and the gdb CLI console. |
| 37 |
* It also brings to the front the proper inferior console when a container is selected. |
| 24 |
* |
38 |
* |
| 25 |
* @since 2.1 |
39 |
* @since 2.1 |
| 26 |
*/ |
40 |
*/ |
| 27 |
public class ConsolePageParticipant implements IConsolePageParticipant{ |
41 |
public class ConsolePageParticipant implements IConsolePageParticipant, IDebugContextListener { |
| 28 |
|
42 |
|
|
|
43 |
private IConsole fConsole; |
| 44 |
private IPageBookViewPage fPage; |
| 45 |
private IConsoleView fView; |
| 46 |
|
| 29 |
public void init(IPageBookViewPage page, IConsole console) { |
47 |
public void init(IPageBookViewPage page, IConsole console) { |
| 30 |
if(console instanceof TracingConsole || isConsoleGdbCli(console)) |
48 |
fPage = page; |
| 31 |
{ |
49 |
fConsole = console; |
|
|
50 |
fView = (IConsoleView)fPage.getSite().getPage().findView(IConsoleConstants.ID_CONSOLE_VIEW); |
| 51 |
|
| 52 |
if (isConsoleInferior(console) || isConsoleGdbCli(console)) { |
| 53 |
// This console participant will affect all consoles, even those not for DSF-GDB. |
| 54 |
// Only consoles for GDBProcess or InferiorRuntimeProcess are what we care about for DSF-GDB |
| 55 |
DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).addDebugContextListener(this); |
| 56 |
} |
| 57 |
|
| 58 |
if(console instanceof TracingConsole || isConsoleGdbCli(console)) { |
| 32 |
TextConsole textConsole = (TextConsole) console; |
59 |
TextConsole textConsole = (TextConsole) console; |
| 33 |
|
60 |
|
| 34 |
// Add the save console action |
61 |
// Add the save console action |
|
Lines 55-66
Link Here
|
| 55 |
return false; |
82 |
return false; |
| 56 |
} |
83 |
} |
| 57 |
|
84 |
|
|
|
85 |
/** |
| 86 |
* Checks if the the console is for an inferior. |
| 87 |
* |
| 88 |
* @param console The console to check |
| 89 |
* @return true if the the console is for an inferior |
| 90 |
*/ |
| 91 |
private boolean isConsoleInferior(IConsole console) { |
| 92 |
if(console instanceof org.eclipse.debug.ui.console.IConsole) { |
| 93 |
org.eclipse.debug.ui.console.IConsole debugConsole = (org.eclipse.debug.ui.console.IConsole)console; |
| 94 |
return (debugConsole.getProcess() instanceof InferiorRuntimeProcess); |
| 95 |
} |
| 96 |
return false; |
| 97 |
} |
| 98 |
|
| 58 |
@SuppressWarnings("rawtypes") |
99 |
@SuppressWarnings("rawtypes") |
| 59 |
public Object getAdapter(Class adapter) { |
100 |
public Object getAdapter(Class adapter) { |
| 60 |
return null; |
101 |
return null; |
| 61 |
} |
102 |
} |
| 62 |
|
103 |
|
| 63 |
public void dispose() { |
104 |
public void dispose() { |
|
|
105 |
if (isConsoleInferior(fConsole) || isConsoleGdbCli(fConsole)) { |
| 106 |
DebugUITools.getDebugContextManager().getContextService(fPage.getSite().getWorkbenchWindow()).removeDebugContextListener(this); |
| 107 |
} |
| 108 |
fConsole = null; |
| 64 |
} |
109 |
} |
| 65 |
|
110 |
|
| 66 |
public void activated() { |
111 |
public void activated() { |
|
Lines 69-72
Link Here
|
| 69 |
public void deactivated() { |
114 |
public void deactivated() { |
| 70 |
} |
115 |
} |
| 71 |
|
116 |
|
|
|
117 |
protected IProcess getConsoleProcess() { |
| 118 |
if (fConsole instanceof org.eclipse.debug.ui.console.IConsole) { |
| 119 |
return ((org.eclipse.debug.ui.console.IConsole)fConsole).getProcess(); |
| 120 |
} |
| 121 |
return null; |
| 122 |
} |
| 123 |
|
| 124 |
protected IProcess getCurrentProcess() { |
| 125 |
IAdaptable context = DebugUITools.getDebugContext(); |
| 126 |
|
| 127 |
// If the launch is selected, we should choose the first inferior being debugged |
| 128 |
if (context instanceof ILaunch) { |
| 129 |
ILaunch launch = (ILaunch)context; |
| 130 |
|
| 131 |
IProcess[] processes = launch.getProcesses(); |
| 132 |
if (processes != null && processes.length > 0) { |
| 133 |
for (IProcess process : processes) { |
| 134 |
if (process instanceof InferiorRuntimeProcess) { |
| 135 |
return process; |
| 136 |
} |
| 137 |
} |
| 138 |
|
| 139 |
// No inferior? return the gdb process |
| 140 |
// We have to check that the process is actually from a DSF-GDB session, |
| 141 |
// since the current context could be for any debug session |
| 142 |
if (processes[0] instanceof GDBProcess) { |
| 143 |
return launch.getProcesses()[0]; |
| 144 |
} |
| 145 |
} |
| 146 |
|
| 147 |
return null; |
| 148 |
} |
| 149 |
|
| 150 |
if (context != null) { |
| 151 |
// Look for the process that this context refers to, so we can select its console |
| 152 |
IDMContext dmc = (IDMContext)context.getAdapter(IDMContext.class); |
| 153 |
IMIContainerDMContext container = DMContexts.getAncestorOfType(dmc, IMIContainerDMContext.class); |
| 154 |
if (container != null) { |
| 155 |
ILaunch launch = (ILaunch)context.getAdapter(ILaunch.class); |
| 156 |
if (launch != null) { |
| 157 |
for (IProcess process : launch.getProcesses()) { |
| 158 |
String groupId = process.getAttribute(IGdbDebugConstants.INFERIOR_GROUPID_ATTR); |
| 159 |
if (container.getGroupId().equals(groupId)) { |
| 160 |
return process; |
| 161 |
} |
| 162 |
} |
| 163 |
} |
| 164 |
} |
| 165 |
} |
| 166 |
|
| 167 |
return null; |
| 168 |
} |
| 169 |
|
| 170 |
/* (non-Javadoc) |
| 171 |
* @see org.eclipse.debug.internal.ui.contexts.provisional.IDebugContextListener#contextEvent(org.eclipse.debug.internal.ui.contexts.provisional.DebugContextEvent) |
| 172 |
*/ |
| 173 |
public void debugContextChanged(DebugContextEvent event) { |
| 174 |
if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) { |
| 175 |
IProcess consoleProcess = getConsoleProcess(); |
| 176 |
if (fView != null && consoleProcess != null && consoleProcess.equals(getCurrentProcess())) { |
| 177 |
fView.display(fConsole); |
| 178 |
} |
| 179 |
} |
| 180 |
} |
| 72 |
} |
181 |
} |