Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 300096 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/cdt/debug/internal/ui/actions/MoveToLineActionDelegate.java (-85 / +100 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008 Freescale Secmiconductor and others.
2
 * Copyright (c) 2008, 2010 Freescale Secmiconductor 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 7-20 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     Freescale Semiconductor - Initial API and implementation
9
 *     Freescale Semiconductor - Initial API and implementation
10
 *     Ericsson                - Updated to latest platform code
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.cdt.debug.internal.ui.actions; 
12
package org.eclipse.cdt.debug.internal.ui.actions; 
12
13
14
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
13
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IAdapterManager;
16
import org.eclipse.core.runtime.IAdapterManager;
15
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.debug.core.DebugPlugin;
16
import org.eclipse.debug.core.model.ISuspendResume;
19
import org.eclipse.debug.core.model.ISuspendResume;
17
import org.eclipse.debug.ui.IDebugUIConstants;
20
import org.eclipse.debug.ui.DebugUITools;
21
import org.eclipse.debug.ui.contexts.DebugContextEvent;
22
import org.eclipse.debug.ui.contexts.IDebugContextListener;
23
import org.eclipse.debug.ui.contexts.IDebugContextManager;
24
import org.eclipse.debug.ui.contexts.IDebugContextService;
18
import org.eclipse.jface.action.IAction;
25
import org.eclipse.jface.action.IAction;
19
import org.eclipse.jface.dialogs.ErrorDialog;
26
import org.eclipse.jface.dialogs.ErrorDialog;
20
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.ISelection;
Lines 24-169 Link Here
24
import org.eclipse.ui.IActionDelegate2;
31
import org.eclipse.ui.IActionDelegate2;
25
import org.eclipse.ui.IEditorActionDelegate;
32
import org.eclipse.ui.IEditorActionDelegate;
26
import org.eclipse.ui.IEditorPart;
33
import org.eclipse.ui.IEditorPart;
27
import org.eclipse.ui.ISelectionListener;
28
import org.eclipse.ui.IViewActionDelegate;
34
import org.eclipse.ui.IViewActionDelegate;
29
import org.eclipse.ui.IViewPart;
35
import org.eclipse.ui.IViewPart;
30
import org.eclipse.ui.IWorkbenchPart;
36
import org.eclipse.ui.IWorkbenchPart;
31
import org.eclipse.ui.IWorkbenchPartSite;
37
import org.eclipse.ui.IWorkbenchPartSite;
38
import org.eclipse.ui.IWorkbenchWindow;
32
 
39
 
33
/**
40
/**
34
 * A move to line action that can be contributed to a an editor. The action
41
 * A move to line action that can be contributed to a an editor. The action
35
 * will perform the "move to line" operation for editors that provide
42
 * will perform the "move to line" operation for editors that provide
36
 * an appropriate <code>IMoveToLineTarget</code> adapter.
43
 * an appropriate <code>IMoveToLineTarget</code> adapter.
37
 */
44
 */
38
public class MoveToLineActionDelegate implements IEditorActionDelegate, IViewActionDelegate, IActionDelegate2 {
45
public class MoveToLineActionDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate {
39
46
	
40
	private IWorkbenchPart fActivePart = null;
47
	private IWorkbenchPart fActivePart = null;
41
42
	private IMoveToLineTarget fPartTarget = null;
48
	private IMoveToLineTarget fPartTarget = null;
43
44
	private IAction fAction = null;
49
	private IAction fAction = null;
50
	private DebugContextListener fContextListener = new DebugContextListener();
51
	private ISuspendResume fTargetElement = null;
52
	
53
	class DebugContextListener implements IDebugContextListener {
45
54
46
	private ISelectionListener fSelectionListener = new DebugSelectionListener();
55
		protected void contextActivated(ISelection selection) {
47
48
	protected ISuspendResume fTargetElement = null;
49
50
	class DebugSelectionListener implements ISelectionListener {
51
52
		/* (non-Javadoc)
53
		 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
54
		 */
55
		public void selectionChanged( IWorkbenchPart part, ISelection selection ) {
56
			fTargetElement = null;
56
			fTargetElement = null;
57
			if ( selection instanceof IStructuredSelection ) {
57
			if (selection instanceof IStructuredSelection) {
58
				IStructuredSelection ss = (IStructuredSelection)selection;
58
				IStructuredSelection ss = (IStructuredSelection) selection;
59
				if ( ss.size() == 1 ) {
59
				if (ss.size() == 1) {
60
					Object object = ss.getFirstElement();
60
                    fTargetElement = (ISuspendResume)
61
					if ( object instanceof ISuspendResume ) {
61
                        DebugPlugin.getAdapter(ss.getFirstElement(), ISuspendResume.class);
62
						fTargetElement = (ISuspendResume)object;
63
					}
64
				}
62
				}
65
			}
63
			}
66
			update();
64
			update();
67
		}
65
		}
68
	}
69
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
72
	 */
73
	public void setActiveEditor( IAction action, IEditorPart targetEditor ) {
74
		init( action );
75
		bindTo( targetEditor );
76
	}
77
66
78
	/* (non-Javadoc)
67
		public void debugContextChanged(DebugContextEvent event) {
79
	 * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
68
			contextActivated(event.getContext());
80
	 */
69
		}
81
	public void init( IAction action ) {
70
		
82
		this.fAction = action;
71
	}		
83
	}
72
	
84
73
	/*(non-Javadoc)
85
	/* (non-Javadoc)
86
	 * @see org.eclipse.ui.IActionDelegate2#dispose()
74
	 * @see org.eclipse.ui.IActionDelegate2#dispose()
87
	 */
75
	 */
88
	public void dispose() {
76
	public void dispose() {
89
		fActivePart.getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener );
77
		DebugUITools.getDebugContextManager().getContextService(fActivePart.getSite().getWorkbenchWindow()).removeDebugContextListener(fContextListener);
90
		fActivePart = null;
78
		fActivePart = null;
91
		fPartTarget = null;
79
		fPartTarget = null;
80
		
92
	}
81
	}
93
94
	/* (non-Javadoc)
95
	 * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
96
	 */
97
	public void runWithEvent( IAction action, Event event ) {
98
		run( action );
99
	}
100
101
	/* (non-Javadoc)
82
	/* (non-Javadoc)
102
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
83
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
103
	 */
84
	 */
104
	public void run( IAction action ) {
85
	public void run(IAction action) {
105
		if ( fPartTarget != null && fTargetElement != null ) {
86
		if (fPartTarget != null && fTargetElement != null) {
106
			try {
87
			try {
107
				fPartTarget.moveToLine( fActivePart, fActivePart.getSite().getSelectionProvider().getSelection(), fTargetElement );
88
				fPartTarget.moveToLine(fActivePart, fActivePart.getSite().getSelectionProvider().getSelection(), fTargetElement);
108
			}
89
			} catch (CoreException e) {
109
			catch( CoreException e ) {
110
				ErrorDialog.openError( fActivePart.getSite().getWorkbenchWindow().getShell(), ActionMessages.getString( "MoveToLineActionDelegate.1" ), ActionMessages.getString( "MoveToLineActionDelegate.2" ), e.getStatus() ); //$NON-NLS-1$ //$NON-NLS-2$
90
				ErrorDialog.openError( fActivePart.getSite().getWorkbenchWindow().getShell(), ActionMessages.getString( "MoveToLineActionDelegate.1" ), ActionMessages.getString( "MoveToLineActionDelegate.2" ), e.getStatus() ); //$NON-NLS-1$ //$NON-NLS-2$
111
			}
91
			}
112
		}
92
		}
113
	}
93
	}
114
115
	/* (non-Javadoc)
94
	/* (non-Javadoc)
116
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
95
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
117
	 */
96
	 */
118
	public void selectionChanged( IAction action, ISelection selection ) {
97
	public void selectionChanged(IAction action, ISelection selection) {
119
		this.fAction = action;
98
		this.fAction = action;
120
		update();
99
		update();
121
	}
100
	}
122
101
	
123
	protected void update() {
102
	/* (non-Javadoc)
124
		if ( fAction == null ) {
103
	 * @see org.eclipse.ui.texteditor.IUpdate#update()
104
	 */
105
	public void update() {
106
		if (fAction == null) {
125
			return;
107
			return;
126
		}
108
		}
127
		boolean enabled = false;
109
		Runnable r = new Runnable() {
128
		if ( fPartTarget != null && fTargetElement != null ) {
110
			public void run() {
129
			IWorkbenchPartSite site = fActivePart.getSite();
111
				boolean enabled = false;
130
			if ( site != null ) {
112
				if (fPartTarget != null && fTargetElement != null) {
131
				ISelectionProvider selectionProvider = site.getSelectionProvider();
113
					IWorkbenchPartSite site = fActivePart.getSite();
132
				if ( selectionProvider != null ) {
114
					if (site != null) {
133
					ISelection selection = selectionProvider.getSelection();
115
					    ISelectionProvider selectionProvider = site.getSelectionProvider();
134
					enabled = fTargetElement.isSuspended() && fPartTarget.canMoveToLine( fActivePart, selection, fTargetElement );
116
					    if (selectionProvider != null) {
117
					        ISelection selection = selectionProvider.getSelection();
118
					        enabled = fTargetElement.isSuspended() && fPartTarget.canMoveToLine(fActivePart, selection, fTargetElement);
119
					    }
120
					}
135
				}
121
				}
122
				fAction.setEnabled(enabled);				
136
			}
123
			}
137
		}
124
		};
138
		fAction.setEnabled( enabled );
125
		CDebugUIPlugin.getStandardDisplay().asyncExec(r);
139
	}
126
	}
140
127
		
128
	/* (non-Javadoc)
129
	 * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
130
	 */
131
	public void init(IAction action) {
132
		this.fAction = action; 
133
	}
134
	/* (non-Javadoc)
135
	 * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
136
	 */
137
	public void runWithEvent(IAction action, Event event) {
138
		run(action);
139
	}
140
	/* (non-Javadoc)
141
	 * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
142
	 */
143
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
144
		init(action);
145
		bindTo(targetEditor);	
146
	}
147
	
141
	/* (non-Javadoc)
148
	/* (non-Javadoc)
142
	 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
149
	 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
143
	 */
150
	 */
144
	public void init( IViewPart view ) {
151
	public void init(IViewPart view) {
145
		bindTo( view );
152
		bindTo(view);
146
	}
153
	}
147
154
	
148
	/**
155
	/**
149
	 * Binds this action to operate on the given part's run to line adapter.
156
	 * Binds this action to operate on the given part's run to line adapter.
157
	 *  
158
	 * @param part
150
	 */
159
	 */
151
	private void bindTo( IWorkbenchPart part ) {
160
	private void bindTo(IWorkbenchPart part) {
161
		IDebugContextManager manager = DebugUITools.getDebugContextManager();
162
		if (fActivePart != null && !fActivePart.equals(part)) {
163
			manager.getContextService(fActivePart.getSite().getWorkbenchWindow()).removeDebugContextListener(fContextListener);
164
		}
165
		fPartTarget = null;
152
		fActivePart = part;
166
		fActivePart = part;
153
		if ( part != null ) {
167
		if (part != null) {
154
			part.getSite().getWorkbenchWindow().getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener );
168
			IWorkbenchWindow workbenchWindow = part.getSite().getWorkbenchWindow();
155
			fPartTarget = (IMoveToLineTarget)part.getAdapter( IMoveToLineTarget.class );
169
			IDebugContextService service = manager.getContextService(workbenchWindow);
156
			if ( fPartTarget == null ) {
170
			service.addDebugContextListener(fContextListener);
171
			fPartTarget  = (IMoveToLineTarget) part.getAdapter(IMoveToLineTarget.class);
172
			if (fPartTarget == null) {
157
				IAdapterManager adapterManager = Platform.getAdapterManager();
173
				IAdapterManager adapterManager = Platform.getAdapterManager();
158
				// TODO: we could restrict loading to cases when the debugging context is on
174
				// TODO: we could restrict loading to cases when the debugging context is on
159
				if ( adapterManager.hasAdapter( part, IMoveToLineTarget.class.getName() ) ) {
175
				if (adapterManager.hasAdapter(part, IMoveToLineTarget.class.getName())) {
160
					fPartTarget = (IMoveToLineTarget)adapterManager.loadAdapter( part, IMoveToLineTarget.class.getName() );
176
					fPartTarget = (IMoveToLineTarget) adapterManager.loadAdapter(part, IMoveToLineTarget.class.getName());
161
				}
177
				}
162
			}
178
			}
163
			// Force the selection update
179
			ISelection activeContext = service.getActiveContext();
164
			ISelection selection = part.getSite().getWorkbenchWindow().getSelectionService().getSelection( IDebugUIConstants.ID_DEBUG_VIEW );
180
			fContextListener.contextActivated(activeContext);
165
			fSelectionListener.selectionChanged( part, selection );
166
		}
181
		}
167
		update();		
182
		update();			
168
	}
183
	}
169
}
184
}
(-)src/org/eclipse/cdt/debug/internal/ui/actions/ResumeAtLineActionDelegate.java (-85 / +100 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2005 QNX Software Systems and others.
2
 * Copyright (c) 2004, 2010 QNX Software Systems 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 7-20 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 * QNX Software Systems - Initial API and implementation
9
 * QNX Software Systems - Initial API and implementation
10
 * Ericsson             - Updated to latest platform code
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.cdt.debug.internal.ui.actions; 
12
package org.eclipse.cdt.debug.internal.ui.actions; 
12
13
14
import org.eclipse.cdt.debug.ui.CDebugUIPlugin;
13
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IAdapterManager;
16
import org.eclipse.core.runtime.IAdapterManager;
15
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.core.runtime.Platform;
18
import org.eclipse.debug.core.DebugPlugin;
16
import org.eclipse.debug.core.model.ISuspendResume;
19
import org.eclipse.debug.core.model.ISuspendResume;
17
import org.eclipse.debug.ui.IDebugUIConstants;
20
import org.eclipse.debug.ui.DebugUITools;
21
import org.eclipse.debug.ui.contexts.DebugContextEvent;
22
import org.eclipse.debug.ui.contexts.IDebugContextListener;
23
import org.eclipse.debug.ui.contexts.IDebugContextManager;
24
import org.eclipse.debug.ui.contexts.IDebugContextService;
18
import org.eclipse.jface.action.IAction;
25
import org.eclipse.jface.action.IAction;
19
import org.eclipse.jface.dialogs.ErrorDialog;
26
import org.eclipse.jface.dialogs.ErrorDialog;
20
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.ISelection;
Lines 24-169 Link Here
24
import org.eclipse.ui.IActionDelegate2;
31
import org.eclipse.ui.IActionDelegate2;
25
import org.eclipse.ui.IEditorActionDelegate;
32
import org.eclipse.ui.IEditorActionDelegate;
26
import org.eclipse.ui.IEditorPart;
33
import org.eclipse.ui.IEditorPart;
27
import org.eclipse.ui.ISelectionListener;
28
import org.eclipse.ui.IViewActionDelegate;
34
import org.eclipse.ui.IViewActionDelegate;
29
import org.eclipse.ui.IViewPart;
35
import org.eclipse.ui.IViewPart;
30
import org.eclipse.ui.IWorkbenchPart;
36
import org.eclipse.ui.IWorkbenchPart;
31
import org.eclipse.ui.IWorkbenchPartSite;
37
import org.eclipse.ui.IWorkbenchPartSite;
38
import org.eclipse.ui.IWorkbenchWindow;
32
 
39
 
33
/**
40
/**
34
 * A resume at line action that can be contributed to a an editor. The action
41
 * A resume at line action that can be contributed to a an editor. The action
35
 * will perform the "resume at line" operation for editors that provide
42
 * will perform the "resume at line" operation for editors that provide
36
 * an appropriate <code>IResumeAtLineTarget</code> adapter.
43
 * an appropriate <code>IResumeAtLineTarget</code> adapter.
37
 */
44
 */
38
public class ResumeAtLineActionDelegate implements IEditorActionDelegate, IViewActionDelegate, IActionDelegate2 {
45
public class ResumeAtLineActionDelegate implements IEditorActionDelegate, IActionDelegate2, IViewActionDelegate {
39
46
	
40
	private IWorkbenchPart fActivePart = null;
47
	private IWorkbenchPart fActivePart = null;
41
42
	private IResumeAtLineTarget fPartTarget = null;
48
	private IResumeAtLineTarget fPartTarget = null;
43
44
	private IAction fAction = null;
49
	private IAction fAction = null;
50
	private DebugContextListener fContextListener = new DebugContextListener();
51
	private ISuspendResume fTargetElement = null;
52
	
53
	class DebugContextListener implements IDebugContextListener {
45
54
46
	private ISelectionListener fSelectionListener = new DebugSelectionListener();
55
		protected void contextActivated(ISelection selection) {
47
48
	protected ISuspendResume fTargetElement = null;
49
50
	class DebugSelectionListener implements ISelectionListener {
51
52
		/* (non-Javadoc)
53
		 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
54
		 */
55
		public void selectionChanged( IWorkbenchPart part, ISelection selection ) {
56
			fTargetElement = null;
56
			fTargetElement = null;
57
			if ( selection instanceof IStructuredSelection ) {
57
			if (selection instanceof IStructuredSelection) {
58
				IStructuredSelection ss = (IStructuredSelection)selection;
58
				IStructuredSelection ss = (IStructuredSelection) selection;
59
				if ( ss.size() == 1 ) {
59
				if (ss.size() == 1) {
60
					Object object = ss.getFirstElement();
60
                    fTargetElement = (ISuspendResume)
61
					if ( object instanceof ISuspendResume ) {
61
                        DebugPlugin.getAdapter(ss.getFirstElement(), ISuspendResume.class);
62
						fTargetElement = (ISuspendResume)object;
63
					}
64
				}
62
				}
65
			}
63
			}
66
			update();
64
			update();
67
		}
65
		}
68
	}
69
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
72
	 */
73
	public void setActiveEditor( IAction action, IEditorPart targetEditor ) {
74
		init( action );
75
		bindTo( targetEditor );
76
	}
77
66
78
	/* (non-Javadoc)
67
		public void debugContextChanged(DebugContextEvent event) {
79
	 * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
68
			contextActivated(event.getContext());
80
	 */
69
		}
81
	public void init( IAction action ) {
70
		
82
		this.fAction = action;
71
	}		
83
	}
72
	
84
73
	/*(non-Javadoc)
85
	/* (non-Javadoc)
86
	 * @see org.eclipse.ui.IActionDelegate2#dispose()
74
	 * @see org.eclipse.ui.IActionDelegate2#dispose()
87
	 */
75
	 */
88
	public void dispose() {
76
	public void dispose() {
89
		fActivePart.getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener );
77
		DebugUITools.getDebugContextManager().getContextService(fActivePart.getSite().getWorkbenchWindow()).removeDebugContextListener(fContextListener);
90
		fActivePart = null;
78
		fActivePart = null;
91
		fPartTarget = null;
79
		fPartTarget = null;
80
		
92
	}
81
	}
93
94
	/* (non-Javadoc)
95
	 * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
96
	 */
97
	public void runWithEvent( IAction action, Event event ) {
98
		run( action );
99
	}
100
101
	/* (non-Javadoc)
82
	/* (non-Javadoc)
102
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
83
	 * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
103
	 */
84
	 */
104
	public void run( IAction action ) {
85
	public void run(IAction action) {
105
		if ( fPartTarget != null && fTargetElement != null ) {
86
		if (fPartTarget != null && fTargetElement != null) {
106
			try {
87
			try {
107
				fPartTarget.resumeAtLine( fActivePart, fActivePart.getSite().getSelectionProvider().getSelection(), fTargetElement );
88
				fPartTarget.resumeAtLine(fActivePart, fActivePart.getSite().getSelectionProvider().getSelection(), fTargetElement);
108
			}
89
			} catch (CoreException e) {
109
			catch( CoreException e ) {
110
				ErrorDialog.openError( fActivePart.getSite().getWorkbenchWindow().getShell(), ActionMessages.getString( "ResumeAtLineActionDelegate.1" ), ActionMessages.getString( "ResumeAtLineActionDelegate.2" ), e.getStatus() ); //$NON-NLS-1$ //$NON-NLS-2$
90
				ErrorDialog.openError( fActivePart.getSite().getWorkbenchWindow().getShell(), ActionMessages.getString( "ResumeAtLineActionDelegate.1" ), ActionMessages.getString( "ResumeAtLineActionDelegate.2" ), e.getStatus() ); //$NON-NLS-1$ //$NON-NLS-2$
111
			}
91
			}
112
		}
92
		}
113
	}
93
	}
114
115
	/* (non-Javadoc)
94
	/* (non-Javadoc)
116
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
95
	 * @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
117
	 */
96
	 */
118
	public void selectionChanged( IAction action, ISelection selection ) {
97
	public void selectionChanged(IAction action, ISelection selection) {
119
		this.fAction = action;
98
		this.fAction = action;
120
		update();
99
		update();
121
	}
100
	}
122
101
	
123
	protected void update() {
102
	/* (non-Javadoc)
124
		if ( fAction == null ) {
103
	 * @see org.eclipse.ui.texteditor.IUpdate#update()
104
	 */
105
	public void update() {
106
		if (fAction == null) {
125
			return;
107
			return;
126
		}
108
		}
127
		boolean enabled = false;
109
		Runnable r = new Runnable() {
128
		if ( fPartTarget != null && fTargetElement != null ) {
110
			public void run() {
129
			IWorkbenchPartSite site = fActivePart.getSite();
111
				boolean enabled = false;
130
			if ( site != null ) {
112
				if (fPartTarget != null && fTargetElement != null) {
131
				ISelectionProvider selectionProvider = site.getSelectionProvider();
113
					IWorkbenchPartSite site = fActivePart.getSite();
132
				if ( selectionProvider != null ) {
114
					if (site != null) {
133
					ISelection selection = selectionProvider.getSelection();
115
					    ISelectionProvider selectionProvider = site.getSelectionProvider();
134
					enabled = fTargetElement.isSuspended() && fPartTarget.canResumeAtLine( fActivePart, selection, fTargetElement );
116
					    if (selectionProvider != null) {
117
					        ISelection selection = selectionProvider.getSelection();
118
					        enabled = fTargetElement.isSuspended() && fPartTarget.canResumeAtLine(fActivePart, selection, fTargetElement);
119
					    }
120
					}
135
				}
121
				}
122
				fAction.setEnabled(enabled);				
136
			}
123
			}
137
		}
124
		};
138
		fAction.setEnabled( enabled );
125
		CDebugUIPlugin.getStandardDisplay().asyncExec(r);
139
	}
126
	}
140
127
		
128
	/* (non-Javadoc)
129
	 * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
130
	 */
131
	public void init(IAction action) {
132
		this.fAction = action; 
133
	}
134
	/* (non-Javadoc)
135
	 * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
136
	 */
137
	public void runWithEvent(IAction action, Event event) {
138
		run(action);
139
	}
140
	/* (non-Javadoc)
141
	 * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
142
	 */
143
	public void setActiveEditor(IAction action, IEditorPart targetEditor) {
144
		init(action);
145
		bindTo(targetEditor);	
146
	}
147
	
141
	/* (non-Javadoc)
148
	/* (non-Javadoc)
142
	 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
149
	 * @see org.eclipse.ui.IViewActionDelegate#init(org.eclipse.ui.IViewPart)
143
	 */
150
	 */
144
	public void init( IViewPart view ) {
151
	public void init(IViewPart view) {
145
		bindTo( view );
152
		bindTo(view);
146
	}
153
	}
147
154
	
148
	/**
155
	/**
149
	 * Binds this action to operate on the given part's run to line adapter.
156
	 * Binds this action to operate on the given part's run to line adapter.
157
	 *  
158
	 * @param part
150
	 */
159
	 */
151
	private void bindTo( IWorkbenchPart part ) {
160
	private void bindTo(IWorkbenchPart part) {
161
		IDebugContextManager manager = DebugUITools.getDebugContextManager();
162
		if (fActivePart != null && !fActivePart.equals(part)) {
163
			manager.getContextService(fActivePart.getSite().getWorkbenchWindow()).removeDebugContextListener(fContextListener);
164
		}
165
		fPartTarget = null;
152
		fActivePart = part;
166
		fActivePart = part;
153
		if ( part != null ) {
167
		if (part != null) {
154
			part.getSite().getWorkbenchWindow().getSelectionService().addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, fSelectionListener );
168
			IWorkbenchWindow workbenchWindow = part.getSite().getWorkbenchWindow();
155
			fPartTarget = (IResumeAtLineTarget)part.getAdapter( IResumeAtLineTarget.class );
169
			IDebugContextService service = manager.getContextService(workbenchWindow);
156
			if ( fPartTarget == null ) {
170
			service.addDebugContextListener(fContextListener);
171
			fPartTarget  = (IResumeAtLineTarget) part.getAdapter(IResumeAtLineTarget.class);
172
			if (fPartTarget == null) {
157
				IAdapterManager adapterManager = Platform.getAdapterManager();
173
				IAdapterManager adapterManager = Platform.getAdapterManager();
158
				// TODO: we could restrict loading to cases when the debugging context is on
174
				// TODO: we could restrict loading to cases when the debugging context is on
159
				if ( adapterManager.hasAdapter( part, IResumeAtLineTarget.class.getName() ) ) {
175
				if (adapterManager.hasAdapter(part, IResumeAtLineTarget.class.getName())) {
160
					fPartTarget = (IResumeAtLineTarget)adapterManager.loadAdapter( part, IResumeAtLineTarget.class.getName() );
176
					fPartTarget = (IResumeAtLineTarget) adapterManager.loadAdapter(part, IResumeAtLineTarget.class.getName());
161
				}
177
				}
162
			}
178
			}
163
			// Force the selection update
179
			ISelection activeContext = service.getActiveContext();
164
			ISelection selection = part.getSite().getWorkbenchWindow().getSelectionService().getSelection( IDebugUIConstants.ID_DEBUG_VIEW );
180
			fContextListener.contextActivated(activeContext);
165
			fSelectionListener.selectionChanged( part, selection );
166
		}
181
		}
167
		update();		
182
		update();			
168
	}
183
	}
169
}
184
}
(-)icons/full/obj16/move_to_line.gif (+2 lines)
Added Link Here
1
GIF89aƒ¥k­oBRkhs‹µw½{½„ÿçœÿç¥ÿï­ÿïµÿï½ÿ÷Æÿ÷Îÿ÷Öÿÿÿ!ù,9ðÉI«½8[Ã{æNYaš
2
©IÄB¬R ¼p?+@ <hâ—;+ƒ¤`r$?çÒâL®—;
(-)icons/full/obj16/resume_at_line.gif (+2 lines)
Added Link Here
1
GIF89aƒ¥k­oNZso{”µsµ{½ÿçœÿç¥ÿï­ÿïµÿï½ÿ÷Æÿ÷Îÿ÷Öÿÿÿ!ù,>ðÉI«½8[Ã{æNYaš
2
©IÅ¢®?B<œQg/H<ì,€$P(‹îá¤>£•]uÅÅD;
(-)icons/full/obj16/watch_exp.gif (+3 lines)
Added Link Here
1
GIF89a¢9e•f“Åt?ʑ±Õ«ÄßÈØêÕáïÿÿÿ!ù,BxºÜ
2
ãÐè;d¢Ä‹“²-V‰Ú!¬Y[zXÒ9ƒ–§„No;VáBb=
3
Á^ƒ3ó…ÀPÉL©$vKý1;
(-)plugin.properties (+5 lines)
Lines 30-35 Link Here
30
tracepoints.property.common=Common
30
tracepoints.property.common=Common
31
tracepoints.property.actions=Actions
31
tracepoints.property.actions=Actions
32
32
33
popup.addExpression.label=Add Watch Expression...
34
popup.resumeAtLine.label=Resume At Li&ne
35
popup.moveToLine.label=&Move To Line 
36
popup.runToLine.label=Run To &Line
37
33
# Tracepoints
38
# Tracepoints
34
view.traceControl.name=Trace Control
39
view.traceControl.name=Trace Control
35
toolbar.startTracing.name=Start Tracing
40
toolbar.startTracing.name=Start Tracing
(-)plugin.xml (+78 lines)
Lines 414-417 Link Here
414
            </command>
414
            </command>
415
         </menuContribution>
415
         </menuContribution>
416
   </extension>
416
   </extension>
417
   <extension
418
         point="org.eclipse.ui.popupMenus">
419
      <viewerContribution
420
            id="org.eclipse.cdt.debug.ui.editor.actions.popup"
421
            targetID="#CEditorContext">
422
         <visibility>
423
            <and>
424
               <systemProperty
425
                     name="org.eclipse.cdt.dsf.gdb.ui.debuggerActive"
426
                     value="true">
427
               </systemProperty>
428
               <objectClass
429
                     name="org.eclipse.jface.text.ITextSelection">
430
               </objectClass>
431
            </and>
432
         </visibility>
433
         <action
434
               class="org.eclipse.cdt.debug.internal.ui.actions.AddExpressionEditorActionDelegate"
435
               helpContextId="add_expression_action_context"
436
               icon="icons/full/obj16/watch_exp.gif"
437
               id="org.eclipse.cdt.dsf.gdb.ui.actions.popup.AddWathExpression"
438
               label="%popup.addExpression.label"
439
               menubarPath="additions">
440
         </action>
441
         <action
442
               class="org.eclipse.cdt.debug.internal.ui.actions.ResumeAtLineActionDelegate"
443
               helpContextId="resume_at_line_action_context"
444
               icon="icons/full/obj16/resume_at_line.gif"
445
               id="org.eclipse.cdt.dsf.gdb.ui.actions.popup.ResumeAtLine"
446
               label="%popup.resumeAtLine.label"
447
               menubarPath="additions">
448
         </action>
449
         <action
450
               class="org.eclipse.cdt.debug.internal.ui.actions.MoveToLineActionDelegate"
451
               helpContextId="move_to_line_action_context"
452
               icon="icons/full/obj16/move_to_line.gif"
453
               id="org.eclipse.cdt.dsf.gdb.ui.actions.popup.MoveToLine"
454
               label="%popup.moveToLine.label"
455
               menubarPath="additions">
456
         </action>
457
         <action
458
               class="org.eclipse.debug.ui.actions.RunToLineActionDelegate"
459
               definitionId="org.eclipse.debug.ui.commands.RunToLine"
460
               helpContextId="run_to_line_action_context"
461
               id="org.eclipse.cdt.dsf.gdb.ui.actions.popup.RunToLine"
462
               label="%popup.runToLine.label"
463
               menubarPath="additions">
464
         </action>
465
      </viewerContribution>
466
      <viewerContribution
467
            id="org.eclipse.cdt.debug.ui.disassembly.actions.popup"
468
            targetID="#DisassemblyPartContext">
469
         <action
470
               class="org.eclipse.cdt.debug.internal.ui.actions.ResumeAtLineActionDelegate"
471
               helpContextId="resume_at_line_action_context"
472
               icon="icons/full/obj16/resume_at_line.gif"
473
               id="org.eclipse.cdt.dsf.gdb.ui.actions.popup.ResumeAtLine"
474
               label="%popup.resumeAtLine.label"
475
               menubarPath="additions">
476
         </action>
477
         <action
478
               class="org.eclipse.cdt.debug.internal.ui.actions.MoveToLineActionDelegate"
479
               helpContextId="move_to_line_action_context"
480
               icon="icons/full/obj16/move_to_line.gif"
481
               id="org.eclipse.cdt.dsf.gdb.ui.actions.popup.MoveToLine"
482
               label="%popup.moveToLine.label"
483
               menubarPath="additions">
484
         </action>
485
         <action
486
               class="org.eclipse.debug.ui.actions.RunToLineActionDelegate"
487
               definitionId="org.eclipse.debug.ui.commands.RunToLine"
488
               helpContextId="run_to_line_action_context"
489
               id="org.eclipse.cdt.dsf.gdb.ui.actions.popup.RunToLine"
490
               label="%popup.runToLine.label"
491
               menubarPath="additions">
492
         </action>
493
      </viewerContribution>
494
   </extension>
417
</plugin>
495
</plugin>
(-)src/org/eclipse/cdt/dsf/gdb/internal/ui/EvaluationContextManager.java (+231 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2010 QNX Software Systems and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * QNX Software Systems - Initial API and implementation
10
 * Ericsson             - DSF-GDB version
11
 *******************************************************************************/
12
package org.eclipse.cdt.dsf.gdb.internal.ui; 
13
14
import java.util.HashMap;
15
import java.util.Map;
16
17
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
18
import org.eclipse.debug.ui.IDebugUIConstants;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.jface.viewers.IStructuredSelection;
21
import org.eclipse.swt.widgets.Display;
22
import org.eclipse.ui.IPageListener;
23
import org.eclipse.ui.IPartListener2;
24
import org.eclipse.ui.ISelectionListener;
25
import org.eclipse.ui.IWindowListener;
26
import org.eclipse.ui.IWorkbench;
27
import org.eclipse.ui.IWorkbenchPage;
28
import org.eclipse.ui.IWorkbenchPart;
29
import org.eclipse.ui.IWorkbenchPartReference;
30
import org.eclipse.ui.IWorkbenchWindow;
31
import org.eclipse.ui.PlatformUI;
32
 
33
/**
34
 * Manages the current evaluation context (stack frame) for evaluation actions.
35
 * In each page, the selection is tracked in each debug view (if any). When a debug
36
 * target selection exists, the "debuggerActive" System property is set to true.
37
 * This property is used to make the "Run To Line", "Resume At Line",
38
 * "Move To Line" and "Add Watch Expression" actions
39
 * visible in editors only if there is a running debug session. 
40
 */
41
public class EvaluationContextManager implements IWindowListener, IPageListener, ISelectionListener, IPartListener2 {
42
43
	// Must use a different ID than for CDI
44
	private final static String DEBUGGER_ACTIVE = GdbUIPlugin.getUniqueIdentifier() + ".debuggerActive"; //$NON-NLS-1$
45
46
	protected static EvaluationContextManager fgManager;
47
48
	private Map<IWorkbenchPage,IDMVMContext> fContextsByPage = null;
49
50
	protected EvaluationContextManager() {
51
	}
52
53
	public static void startup() {
54
		Runnable r = new Runnable() {
55
56
			public void run() {
57
				if ( fgManager == null ) {
58
					fgManager = new EvaluationContextManager();
59
					IWorkbench workbench = PlatformUI.getWorkbench();
60
					IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
61
					for( int i = 0; i < windows.length; i++ ) {
62
						fgManager.windowOpened( windows[i] );
63
					}
64
					workbench.addWindowListener( fgManager );
65
				}
66
			}
67
		};
68
		Display display = Display.getCurrent();
69
		if ( display == null )
70
			display = Display.getDefault();
71
		display.asyncExec( r );
72
	}
73
74
	/* (non-Javadoc)
75
	 * @see org.eclipse.ui.IWindowListener#windowActivated(org.eclipse.ui.IWorkbenchWindow)
76
	 */
77
	public void windowActivated( IWorkbenchWindow window ) {
78
		windowOpened( window );
79
	}
80
81
	/* (non-Javadoc)
82
	 * @see org.eclipse.ui.IWindowListener#windowDeactivated(org.eclipse.ui.IWorkbenchWindow)
83
	 */
84
	public void windowDeactivated( IWorkbenchWindow window ) {
85
	}
86
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.ui.IWindowListener#windowClosed(org.eclipse.ui.IWorkbenchWindow)
89
	 */
90
	public void windowClosed( IWorkbenchWindow window ) {
91
		window.removePageListener( this );
92
	}
93
94
	/* (non-Javadoc)
95
	 * @see org.eclipse.ui.IWindowListener#windowOpened(org.eclipse.ui.IWorkbenchWindow)
96
	 */
97
	public void windowOpened( IWorkbenchWindow window ) {
98
		IWorkbenchPage[] pages = window.getPages();
99
		for( int i = 0; i < pages.length; i++ ) {
100
			window.addPageListener( this );
101
			pageOpened( pages[i] );
102
		}
103
	}
104
105
	/* (non-Javadoc)
106
	 * @see org.eclipse.ui.IPageListener#pageActivated(org.eclipse.ui.IWorkbenchPage)
107
	 */
108
	public void pageActivated( IWorkbenchPage page ) {
109
		pageOpened( page );
110
	}
111
112
	/* (non-Javadoc)
113
	 * @see org.eclipse.ui.IPageListener#pageClosed(org.eclipse.ui.IWorkbenchPage)
114
	 */
115
	public void pageClosed( IWorkbenchPage page ) {
116
		page.removeSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
117
		page.removePartListener( this );
118
	}
119
120
	/* (non-Javadoc)
121
	 * @see org.eclipse.ui.IPageListener#pageOpened(org.eclipse.ui.IWorkbenchPage)
122
	 */
123
	public void pageOpened( IWorkbenchPage page ) {
124
		page.addSelectionListener( IDebugUIConstants.ID_DEBUG_VIEW, this );
125
		page.addPartListener( this );
126
		IWorkbenchPartReference ref = page.getActivePartReference();
127
		if ( ref != null ) {
128
			partActivated( ref );
129
		}
130
	}
131
132
	/* (non-Javadoc)
133
	 * @see org.eclipse.ui.ISelectionListener#selectionChanged(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
134
	 */
135
	public void selectionChanged( IWorkbenchPart part, ISelection selection ) {
136
		IWorkbenchPage page = part.getSite().getPage();
137
		if ( selection instanceof IStructuredSelection ) {
138
			IStructuredSelection ss = (IStructuredSelection)selection;
139
			if ( ss.size() == 1 ) {
140
				Object element = ss.getFirstElement();
141
				if ( element instanceof IDMVMContext ) {
142
					setContext( page, (IDMVMContext)element );
143
					return;
144
				}
145
			}
146
		}
147
		// no context in the given view
148
		removeContext( page );
149
	}
150
151
	/* (non-Javadoc)
152
	 * @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference)
153
	 */
154
	public void partActivated( IWorkbenchPartReference partRef ) {
155
	}
156
157
	/* (non-Javadoc)
158
	 * @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference)
159
	 */
160
	public void partBroughtToTop( IWorkbenchPartReference partRef ) {
161
	}
162
163
	/* (non-Javadoc)
164
	 * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
165
	 */
166
	public void partClosed( IWorkbenchPartReference partRef ) {
167
		if ( IDebugUIConstants.ID_DEBUG_VIEW.equals( partRef.getId() ) ) {
168
			removeContext( partRef.getPage() );
169
		}
170
	}
171
172
	/* (non-Javadoc)
173
	 * @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
174
	 */
175
	public void partDeactivated( IWorkbenchPartReference partRef ) {
176
	}
177
178
	/* (non-Javadoc)
179
	 * @see org.eclipse.ui.IPartListener2#partOpened(org.eclipse.ui.IWorkbenchPartReference)
180
	 */
181
	public void partOpened( IWorkbenchPartReference partRef ) {
182
	}
183
184
	/* (non-Javadoc)
185
	 * @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference)
186
	 */
187
	public void partHidden( IWorkbenchPartReference partRef ) {
188
	}
189
190
	/* (non-Javadoc)
191
	 * @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference)
192
	 */
193
	public void partVisible( IWorkbenchPartReference partRef ) {
194
	}
195
196
	/* (non-Javadoc)
197
	 * @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference)
198
	 */
199
	public void partInputChanged( IWorkbenchPartReference partRef ) {
200
	}
201
202
	/**
203
	 * Sets the evaluation context for the given page, and notes that
204
	 * a valid execution context exists.
205
	 * 
206
	 * @param page
207
	 * @param frame
208
	 */
209
	private void setContext( IWorkbenchPage page, IDMVMContext target ) {
210
		if ( fContextsByPage == null ) {
211
			fContextsByPage = new HashMap<IWorkbenchPage,IDMVMContext>();
212
		}
213
		fContextsByPage.put( page, target );
214
		System.setProperty( DEBUGGER_ACTIVE, Boolean.TRUE.toString() );
215
	}
216
217
	/**
218
	 * Removes an evaluation context for the given page, and determines if
219
	 * any valid execution context remain.
220
	 * 
221
	 * @param page
222
	 */
223
	private void removeContext( IWorkbenchPage page ) {
224
		if ( fContextsByPage != null ) {
225
			fContextsByPage.remove( page );
226
			if ( fContextsByPage.isEmpty() ) {
227
				System.setProperty( DEBUGGER_ACTIVE, Boolean.FALSE.toString() );
228
			}
229
		}
230
	}
231
}
(-)src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbSuspendResumeAdapterFactory.java (-87 / +90 lines)
Lines 1-88 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2009, 2010 Wind River Systems and others.
2
 * Copyright (c) 2009, 2010 Wind River Systems 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
6
 * http://www.eclipse.org/legal/epl-v10.html
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
7
 * 
8
 * Contributors:
8
 * Contributors:
9
 *     Wind River Systems - initial API and implementation
9
 *     Wind River Systems - initial API and implementation
10
 *     Ericsson           - Updated to support Move-To-Line
10
 *     Ericsson           - Updated to support Move-To-Line
11
 *******************************************************************************/
11
 *******************************************************************************/
12
package org.eclipse.cdt.dsf.gdb.internal.ui;
12
package org.eclipse.cdt.dsf.gdb.internal.ui;
13
13
14
import org.eclipse.cdt.dsf.datamodel.DMContexts;
14
import org.eclipse.cdt.dsf.datamodel.DMContexts;
15
import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext;
15
import org.eclipse.cdt.dsf.debug.service.IRunControl.IContainerDMContext;
16
import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext;
16
import org.eclipse.cdt.dsf.debug.service.IRunControl.IExecutionDMContext;
17
import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbMoveToLine;
17
import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbMoveToLine;
18
import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbResumeAtLine;
18
import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbResumeAtLine;
19
import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbRunToLine;
19
import org.eclipse.cdt.dsf.gdb.internal.ui.actions.GdbRunToLine;
20
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
20
import org.eclipse.cdt.dsf.ui.viewmodel.datamodel.IDMVMContext;
21
import org.eclipse.core.runtime.IAdaptable;
21
import org.eclipse.core.runtime.IAdaptable;
22
import org.eclipse.core.runtime.IAdapterFactory;
22
import org.eclipse.core.runtime.IAdapterFactory;
23
import org.eclipse.debug.core.DebugException;
23
import org.eclipse.debug.core.DebugException;
24
import org.eclipse.debug.core.model.ISuspendResume;
24
import org.eclipse.debug.core.model.ISuspendResume;
25
25
26
/**
26
/**
27
 * Adapter factory for Run-To-Line, Move-To-Line
27
 * Adapter factory for Run-To-Line, Move-To-Line
28
 * and Resume-At-Line
28
 * and Resume-At-Line
29
 * 
29
 * 
30
 * @since 2.1
30
 * @since 2.1
31
 */
31
 */
32
public class GdbSuspendResumeAdapterFactory implements IAdapterFactory {
32
public class GdbSuspendResumeAdapterFactory implements IAdapterFactory {
33
33
34
    static class GdbSuspendResume implements ISuspendResume, IAdaptable {
34
    static class GdbSuspendResume implements ISuspendResume, IAdaptable {
35
35
36
        private final GdbRunToLine fRunToLine;
36
        private final GdbRunToLine fRunToLine;
37
        private final GdbMoveToLine fMoveToLine;
37
        private final GdbMoveToLine fMoveToLine;
38
        private final GdbResumeAtLine fResumeAtLine;
38
        private final GdbResumeAtLine fResumeAtLine;
39
        
39
        
40
        GdbSuspendResume(IExecutionDMContext execCtx) {
40
        GdbSuspendResume(IExecutionDMContext execCtx) {
41
            fRunToLine = new GdbRunToLine(execCtx);
41
            fRunToLine = new GdbRunToLine(execCtx);
42
            fMoveToLine = new GdbMoveToLine(execCtx);
42
            fMoveToLine = new GdbMoveToLine(execCtx);
43
            fResumeAtLine = new GdbResumeAtLine(execCtx);
43
            fResumeAtLine = new GdbResumeAtLine(execCtx);
44
        }
44
        }
45
        
45
        
46
        @SuppressWarnings("rawtypes")
46
        @SuppressWarnings("rawtypes")
47
        public Object getAdapter(Class adapter) {
47
        public Object getAdapter(Class adapter) {
48
            if (adapter.isInstance(fRunToLine)) {
48
            if (adapter.isInstance(fRunToLine)) {
49
                return fRunToLine;
49
                return fRunToLine;
50
            }
50
            }
51
            if (adapter.isInstance(fMoveToLine)) {
51
            if (adapter.isInstance(fMoveToLine)) {
52
                return fMoveToLine;
52
                return fMoveToLine;
53
            }
53
            }
54
            if (adapter.isInstance(fResumeAtLine)) {
54
            if (adapter.isInstance(fResumeAtLine)) {
55
                return fResumeAtLine;
55
                return fResumeAtLine;
56
            }
56
            }
57
            return null;
57
            return null;
58
        }
58
        }
59
59
60
        public boolean canResume() { return false; }
60
        public boolean canResume() { return false; }
61
        public boolean canSuspend() { return false; }
61
        public boolean canSuspend() { return false; }
62
        public boolean isSuspended() { return false; }
62
        // This must return true because the platform
63
        public void resume() throws DebugException {}
63
        // RunToLineActionDelegate will only enable the
64
        public void suspend() throws DebugException {}
64
        // action if we are suspended
65
    }
65
        public boolean isSuspended() { return true; }
66
    
66
        public void resume() throws DebugException {}
67
    @SuppressWarnings("rawtypes")
67
        public void suspend() throws DebugException {}
68
    public Object getAdapter(Object adaptableObject, Class adapterType) {
68
    }
69
        if (ISuspendResume.class.equals(adapterType)) {
69
    
70
            if (adaptableObject instanceof IDMVMContext) {
70
    @SuppressWarnings("rawtypes")
71
                IExecutionDMContext execDmc = DMContexts.getAncestorOfType(
71
    public Object getAdapter(Object adaptableObject, Class adapterType) {
72
                    ((IDMVMContext)adaptableObject).getDMContext(),
72
        if (ISuspendResume.class.equals(adapterType)) {
73
                    IExecutionDMContext.class);
73
            if (adaptableObject instanceof IDMVMContext) {
74
            	// It only makes sense to RunToLine, MoveToLine or
74
                IExecutionDMContext execDmc = DMContexts.getAncestorOfType(
75
                // ResumeAtLine if we are dealing with a thread, not a container
75
                    ((IDMVMContext)adaptableObject).getDMContext(),
76
                if (execDmc != null && !(execDmc instanceof IContainerDMContext)) {
76
                    IExecutionDMContext.class);
77
                    return new GdbSuspendResume(execDmc);
77
            	// It only makes sense to RunToLine, MoveToLine or
78
                }
78
                // ResumeAtLine if we are dealing with a thread, not a container
79
            }
79
                if (execDmc != null && !(execDmc instanceof IContainerDMContext)) {
80
        }
80
                    return new GdbSuspendResume(execDmc);
81
        return null;
81
                }
82
    }
82
            }
83
83
        }
84
    @SuppressWarnings("rawtypes")
84
        return null;
85
    public Class[] getAdapterList() {
85
    }
86
        return new Class[] { ISuspendResume.class };
86
87
    }
87
    @SuppressWarnings("rawtypes")
88
    public Class[] getAdapterList() {
89
        return new Class[] { ISuspendResume.class };
90
    }
88
}
91
}
(-)src/org/eclipse/cdt/dsf/gdb/internal/ui/GdbUIPlugin.java (+2 lines)
Lines 55-60 Link Here
55
		super.start(context);
55
		super.start(context);
56
		plugin = this;
56
		plugin = this;
57
		
57
		
58
		EvaluationContextManager.startup();
59
58
		fTracingConsoleManager = new TracingConsoleManager();
60
		fTracingConsoleManager = new TracingConsoleManager();
59
		fTracingConsoleManager.startup();
61
		fTracingConsoleManager.startup();
60
	}
62
	}

Return to bug 300096