Lines 11-19
Link Here
|
11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
12 |
package org.eclipse.debug.internal.ui.views.expression; |
12 |
package org.eclipse.debug.internal.ui.views.expression; |
13 |
|
13 |
|
14 |
|
14 |
import org.eclipse.core.runtime.IAdaptable; |
15 |
import org.eclipse.debug.core.DebugPlugin; |
15 |
import org.eclipse.debug.core.DebugPlugin; |
|
|
16 |
import org.eclipse.debug.core.IExpressionManager; |
17 |
import org.eclipse.debug.core.ILaunch; |
18 |
import org.eclipse.debug.core.model.IDebugElement; |
19 |
import org.eclipse.debug.core.model.IWatchExpression; |
16 |
import org.eclipse.debug.internal.ui.IDebugHelpContextIds; |
20 |
import org.eclipse.debug.internal.ui.IDebugHelpContextIds; |
|
|
21 |
import org.eclipse.debug.internal.ui.actions.expressions.PasteWatchExpressionsAction; |
17 |
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; |
22 |
import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; |
18 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; |
23 |
import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; |
19 |
import org.eclipse.debug.internal.ui.views.variables.AvailableLogicalStructuresAction; |
24 |
import org.eclipse.debug.internal.ui.views.variables.AvailableLogicalStructuresAction; |
Lines 21-26
Link Here
|
21 |
import org.eclipse.debug.internal.ui.views.variables.VariablesView; |
26 |
import org.eclipse.debug.internal.ui.views.variables.VariablesView; |
22 |
import org.eclipse.debug.internal.ui.views.variables.VariablesViewMessages; |
27 |
import org.eclipse.debug.internal.ui.views.variables.VariablesViewMessages; |
23 |
import org.eclipse.debug.internal.ui.views.variables.details.AvailableDetailPanesAction; |
28 |
import org.eclipse.debug.internal.ui.views.variables.details.AvailableDetailPanesAction; |
|
|
29 |
import org.eclipse.debug.ui.DebugUITools; |
24 |
import org.eclipse.debug.ui.IDebugUIConstants; |
30 |
import org.eclipse.debug.ui.IDebugUIConstants; |
25 |
import org.eclipse.jface.action.IAction; |
31 |
import org.eclipse.jface.action.IAction; |
26 |
import org.eclipse.jface.action.IMenuManager; |
32 |
import org.eclipse.jface.action.IMenuManager; |
Lines 29-39
Link Here
|
29 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
35 |
import org.eclipse.jface.util.LocalSelectionTransfer; |
30 |
import org.eclipse.jface.viewers.ISelection; |
36 |
import org.eclipse.jface.viewers.ISelection; |
31 |
import org.eclipse.swt.SWT; |
37 |
import org.eclipse.swt.SWT; |
|
|
38 |
import org.eclipse.swt.dnd.Clipboard; |
32 |
import org.eclipse.swt.dnd.DND; |
39 |
import org.eclipse.swt.dnd.DND; |
33 |
import org.eclipse.swt.dnd.TextTransfer; |
40 |
import org.eclipse.swt.dnd.TextTransfer; |
34 |
import org.eclipse.swt.dnd.Transfer; |
41 |
import org.eclipse.swt.dnd.Transfer; |
|
|
42 |
import org.eclipse.swt.widgets.Display; |
43 |
import org.eclipse.ui.ISharedImages; |
35 |
import org.eclipse.ui.IWorkbenchActionConstants; |
44 |
import org.eclipse.ui.IWorkbenchActionConstants; |
36 |
|
45 |
import org.eclipse.ui.PlatformUI; |
|
|
46 |
import org.eclipse.ui.texteditor.IWorkbenchActionDefinitionIds; |
47 |
|
37 |
/** |
48 |
/** |
38 |
* Displays expressions and their values with a detail |
49 |
* Displays expressions and their values with a detail |
39 |
* pane. |
50 |
* pane. |
Lines 127-131
Link Here
|
127 |
viewer.addDragSupport(DND.DROP_MOVE, new Transfer[] {LocalSelectionTransfer.getTransfer()}, new SelectionDragAdapter(viewer)); |
138 |
viewer.addDragSupport(DND.DROP_MOVE, new Transfer[] {LocalSelectionTransfer.getTransfer()}, new SelectionDragAdapter(viewer)); |
128 |
viewer.addDropSupport(DND.DROP_MOVE|DND.DROP_COPY, new Transfer[] {LocalSelectionTransfer.getTransfer(), TextTransfer.getInstance()}, new ExpressionDropAdapter(viewer)); |
139 |
viewer.addDropSupport(DND.DROP_MOVE|DND.DROP_COPY, new Transfer[] {LocalSelectionTransfer.getTransfer(), TextTransfer.getInstance()}, new ExpressionDropAdapter(viewer)); |
129 |
} |
140 |
} |
130 |
|
141 |
|
|
|
142 |
/* |
143 |
* (non-Javadoc) |
144 |
* |
145 |
* @see org.eclipse.debug.internal.ui.views.variables.VariablesView#createActions() |
146 |
*/ |
147 |
protected void createActions() { |
148 |
super.createActions(); |
149 |
|
150 |
PasteWatchExpressionsAction paste = new PasteWatchExpressionsAction(this); |
151 |
configure(paste, IWorkbenchActionDefinitionIds.PASTE, |
152 |
PASTE_ACTION, ISharedImages.IMG_TOOL_PASTE); |
153 |
} |
154 |
|
155 |
/** |
156 |
* Configures the action to override the global action, and registers the |
157 |
* action with this view. |
158 |
* |
159 |
* @param action |
160 |
* action |
161 |
* @param defId |
162 |
* action definition id |
163 |
* @param globalId |
164 |
* global action id |
165 |
* @param imgId |
166 |
* image identifier |
167 |
*/ |
168 |
private void configure(IAction action, String defId, String globalId, |
169 |
String imgId) { |
170 |
setAction(defId, action); |
171 |
action.setActionDefinitionId(defId); |
172 |
getViewSite().getActionBars().setGlobalActionHandler(globalId, action); |
173 |
action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages() |
174 |
.getImageDescriptor(imgId)); |
175 |
} |
176 |
|
177 |
/** |
178 |
* Returns whether the given selection can be pasted into the expressions |
179 |
* view. |
180 |
* |
181 |
* @param selection |
182 |
* the selection to paste |
183 |
* @return whether the given selection can be pasted into the given target |
184 |
*/ |
185 |
public boolean canPaste() { |
186 |
String clipboardText = getClipboardText(); |
187 |
if (clipboardText != null && clipboardText.length() > 0) { |
188 |
return true; |
189 |
} |
190 |
return false; |
191 |
} |
192 |
|
193 |
/** |
194 |
* Pastes the selection into the given target |
195 |
* |
196 |
* @param selection |
197 |
* breakpoints |
198 |
* @return whether successful |
199 |
*/ |
200 |
public boolean performPaste() { |
201 |
String clipboardText = getClipboardText(); |
202 |
if (clipboardText != null && clipboardText.length() > 0) { |
203 |
IExpressionManager expressionManager = DebugPlugin.getDefault() |
204 |
.getExpressionManager(); |
205 |
IWatchExpression watchExpression = expressionManager |
206 |
.newWatchExpression(clipboardText); |
207 |
expressionManager.addExpression(watchExpression); |
208 |
watchExpression.setExpressionContext(getContext()); |
209 |
return true; |
210 |
} |
211 |
return false; |
212 |
} |
213 |
|
214 |
// TODO: duplicate code from WatchExpressionAction |
215 |
protected IDebugElement getContext() { |
216 |
IAdaptable object = DebugUITools.getDebugContext(); |
217 |
IDebugElement context = null; |
218 |
if (object instanceof IDebugElement) { |
219 |
context = (IDebugElement) object; |
220 |
} else if (object instanceof ILaunch) { |
221 |
context = ((ILaunch) object).getDebugTarget(); |
222 |
} |
223 |
return context; |
224 |
} |
225 |
|
226 |
protected String getClipboardText() { |
227 |
Clipboard clipboard = new Clipboard(Display.getDefault()); |
228 |
try { |
229 |
TextTransfer textTransfer = TextTransfer.getInstance(); |
230 |
return (String) clipboard.getContents(textTransfer); |
231 |
} finally { |
232 |
clipboard.dispose(); |
233 |
} |
234 |
} |
131 |
} |
235 |
} |