blob: 975edde5ad248ab6c5ac5d88faef7afd1e51d7ff (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
/*******************************************************************************
* Copyright (c) 2010, 2013 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.internal.ui.actions.breakpointGroups;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.eclipse.core.resources.IMarkerDelta;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.IBreakpointsListener;
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.internal.ui.viewers.model.VirtualCopyToClipboardActionDelegate;
import org.eclipse.debug.ui.AbstractDebugView;
import org.eclipse.debug.ui.IDebugView;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.util.LocalSelectionTransfer;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IViewPart;
/**
* Copies breakpoint labels to the text clipboard and breakpoint objects
* to the breakpoint paste action.
*/
public class CopyBreakpointsActionDelegate extends VirtualCopyToClipboardActionDelegate implements IBreakpointsListener {
private long fStamp;
@Override
public void run(IAction action) {
super.run(action);
LocalSelectionTransfer.getTransfer().setSelection(getSelection());
fStamp = System.currentTimeMillis();
LocalSelectionTransfer.getTransfer().setSelectionSetTime(fStamp);
IAction pasteAction = ((AbstractDebugView)getView()).getAction(IDebugView.PASTE_ACTION);
// update the enablement of the paste action
// workaround since the clipboard does not suppot callbacks
if (pasteAction instanceof PasteBreakpointsAction) {
PasteBreakpointsAction pba = (PasteBreakpointsAction) pasteAction;
if (pba.getStructuredSelection() != null) {
pba.selectionChanged(pba.getStructuredSelection());
}
}
}
@Override
public void init(IViewPart view) {
super.init(view);
DebugPlugin.getDefault().getBreakpointManager().addBreakpointListener(this);
}
@Override
public void dispose() {
DebugPlugin.getDefault().getBreakpointManager().removeBreakpointListener(this);
super.dispose();
}
@Override
public void breakpointsAdded(IBreakpoint[] breakpoints) {
}
@Override
public void breakpointsRemoved(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
// remove deleted breakpoints from drag/drop clipboard
if (fStamp == LocalSelectionTransfer.getTransfer().getSelectionSetTime()) {
ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
if (selection instanceof IStructuredSelection) {
Set<IBreakpoint> removed = new HashSet<>();
Collections.addAll(removed, breakpoints);
boolean modified = false;
List<Object> remain = new ArrayList<>();
IStructuredSelection ss = (IStructuredSelection) selection;
Iterator<?> iterator = ss.iterator();
while (iterator.hasNext()) {
Object bp = iterator.next();
if (removed.contains(bp)) {
modified = true;
} else {
remain.add(bp);
}
}
if (modified) {
LocalSelectionTransfer.getTransfer().setSelection(new StructuredSelection(remain));
fStamp = System.currentTimeMillis();
LocalSelectionTransfer.getTransfer().setSelectionSetTime(fStamp);
}
}
}
}
@Override
public void breakpointsChanged(IBreakpoint[] breakpoints, IMarkerDelta[] deltas) {
}
}
|