|
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 |
} |