Lines 52-57
Link Here
|
52 |
import java.beans.PropertyChangeListener; |
52 |
import java.beans.PropertyChangeListener; |
53 |
import java.lang.reflect.InvocationTargetException; |
53 |
import java.lang.reflect.InvocationTargetException; |
54 |
import java.lang.reflect.Method; |
54 |
import java.lang.reflect.Method; |
|
|
55 |
import java.util.LinkedList; |
55 |
import java.util.List; |
56 |
import java.util.List; |
56 |
import javax.swing.Action; |
57 |
import javax.swing.Action; |
57 |
import javax.swing.ImageIcon; |
58 |
import javax.swing.ImageIcon; |
Lines 61-66
Link Here
|
61 |
import javax.swing.JPopupMenu; |
62 |
import javax.swing.JPopupMenu; |
62 |
import javax.swing.JSeparator; |
63 |
import javax.swing.JSeparator; |
63 |
import javax.swing.SwingUtilities; |
64 |
import javax.swing.SwingUtilities; |
|
|
65 |
import javax.swing.event.ChangeEvent; |
66 |
import javax.swing.event.ChangeListener; |
64 |
import javax.swing.event.PopupMenuEvent; |
67 |
import javax.swing.event.PopupMenuEvent; |
65 |
import javax.swing.event.PopupMenuListener; |
68 |
import javax.swing.event.PopupMenuListener; |
66 |
import org.netbeans.api.debugger.DebuggerManager; |
69 |
import org.netbeans.api.debugger.DebuggerManager; |
Lines 70-75
Link Here
|
70 |
import org.netbeans.spi.debugger.ui.AttachType; |
73 |
import org.netbeans.spi.debugger.ui.AttachType; |
71 |
import org.netbeans.spi.debugger.ui.Controller; |
74 |
import org.netbeans.spi.debugger.ui.Controller; |
72 |
import org.netbeans.spi.project.ActionProvider; |
75 |
import org.netbeans.spi.project.ActionProvider; |
|
|
76 |
import org.netbeans.spi.project.ui.support.BuildExecutionSupport; |
73 |
import org.netbeans.spi.project.ui.support.MainProjectSensitiveActions; |
77 |
import org.netbeans.spi.project.ui.support.MainProjectSensitiveActions; |
74 |
import org.openide.awt.Actions; |
78 |
import org.openide.awt.Actions; |
75 |
import org.openide.awt.DropDownButtonFactory; |
79 |
import org.openide.awt.DropDownButtonFactory; |
Lines 78-83
Link Here
|
78 |
import org.openide.util.ImageUtilities; |
82 |
import org.openide.util.ImageUtilities; |
79 |
import org.openide.util.NbBundle; |
83 |
import org.openide.util.NbBundle; |
80 |
import org.openide.util.RequestProcessor; |
84 |
import org.openide.util.RequestProcessor; |
|
|
85 |
import org.openide.util.WeakListeners; |
81 |
import org.openide.util.WeakSet; |
86 |
import org.openide.util.WeakSet; |
82 |
import org.openide.util.actions.Presenter; |
87 |
import org.openide.util.actions.Presenter; |
83 |
|
88 |
|
Lines 89-96
Link Here
|
89 |
|
94 |
|
90 |
private static WeakSet<AttachHistorySupport> ahs = null; |
95 |
private static WeakSet<AttachHistorySupport> ahs = null; |
91 |
|
96 |
|
92 |
private Action delegate; |
97 |
private final Action delegate; |
93 |
private AttachHistorySupport attachHistorySupport; |
98 |
private final DebugHistorySupport debugHistorySupport; |
|
|
99 |
private final AttachHistorySupport attachHistorySupport; |
94 |
|
100 |
|
95 |
/** Creates a new instance of DebugMainProjectAction */ |
101 |
/** Creates a new instance of DebugMainProjectAction */ |
96 |
public DebugMainProjectAction() { |
102 |
public DebugMainProjectAction() { |
Lines 98-103
Link Here
|
98 |
ActionProvider.COMMAND_DEBUG, |
104 |
ActionProvider.COMMAND_DEBUG, |
99 |
NbBundle.getMessage(DebugMainProjectAction.class, "LBL_DebugMainProjectAction_Name" ),ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debugProject.png", false)); // NOI18N |
105 |
NbBundle.getMessage(DebugMainProjectAction.class, "LBL_DebugMainProjectAction_Name" ),ImageUtilities.loadImageIcon("org/netbeans/modules/debugger/resources/debugProject.png", false)); // NOI18N |
100 |
delegate.putValue("iconBase","org/netbeans/modules/debugger/resources/debugProject.png"); //NOI18N |
106 |
delegate.putValue("iconBase","org/netbeans/modules/debugger/resources/debugProject.png"); //NOI18N |
|
|
107 |
debugHistorySupport = new DebugHistorySupport(); |
101 |
attachHistorySupport = new AttachHistorySupport(); |
108 |
attachHistorySupport = new AttachHistorySupport(); |
102 |
} |
109 |
} |
103 |
|
110 |
|
Lines 188-193
Link Here
|
188 |
|
195 |
|
189 |
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
196 |
@Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { |
190 |
JPopupMenu menu = (JPopupMenu)e.getSource(); |
197 |
JPopupMenu menu = (JPopupMenu)e.getSource(); |
|
|
198 |
debugHistorySupport.init(menu); |
191 |
attachHistorySupport.init(menu); |
199 |
attachHistorySupport.init(menu); |
192 |
menu.removePopupMenuListener(this); |
200 |
menu.removePopupMenuListener(this); |
193 |
} |
201 |
} |
Lines 197-202
Link Here
|
197 |
|
205 |
|
198 |
@Override public void popupMenuCanceled(PopupMenuEvent e) { |
206 |
@Override public void popupMenuCanceled(PopupMenuEvent e) { |
199 |
} |
207 |
} |
|
|
208 |
|
209 |
private static class DebugHistorySupport implements ActionListener, ChangeListener { |
210 |
|
211 |
private JPopupMenu menu; |
212 |
private JMenuItem[] items = new JMenuItem[0]; |
213 |
private final JSeparator separator1 = new JPopupMenu.Separator(); |
214 |
private final JSeparator separator2 = new JPopupMenu.Separator(); |
215 |
private final BuildExecutionSupportChangeSupport besc; |
216 |
private final LinkedList<BuildExecutionSupport.ActionItem> debugItems = new LinkedList<BuildExecutionSupport.ActionItem>(); |
217 |
|
218 |
private static final int MAX_ITEMS_COUNT = 7; |
219 |
private static final String DEBUG_ACTION_ITEM_PROP_NAME = "debug action item"; |
220 |
private static final RequestProcessor RP = new RequestProcessor(DebugHistorySupport.class.getName()); |
221 |
|
222 |
public DebugHistorySupport() { |
223 |
besc = new BuildExecutionSupportChangeSupport(); |
224 |
besc.addChangeListener(WeakListeners.change(this, besc)); |
225 |
} |
226 |
|
227 |
void init(JPopupMenu menu) { |
228 |
this.menu = menu; |
229 |
computeItems(); |
230 |
} |
231 |
|
232 |
private void computeItems() { |
233 |
boolean wasSeparator = items.length > 0; |
234 |
for (int i = 0; i < items.length; i++) { |
235 |
menu.remove(items[i]); |
236 |
} |
237 |
synchronized (debugItems) { |
238 |
if (debugItems.isEmpty()) { |
239 |
items = new JMenuItem[0]; |
240 |
} else { |
241 |
int n = debugItems.size(); |
242 |
items = new JMenuItem[n]; |
243 |
int i = 0; |
244 |
for (BuildExecutionSupport.ActionItem ai : debugItems) { |
245 |
String dispName = ai.getDisplayName(); |
246 |
items[i] = new JMenuItem(dispName); |
247 |
items[i].putClientProperty(DEBUG_ACTION_ITEM_PROP_NAME, ai); |
248 |
items[i].addActionListener(this); |
249 |
i++; |
250 |
} |
251 |
} |
252 |
} |
253 |
if (items.length == 0) { |
254 |
if (wasSeparator) { |
255 |
menu.remove(separator1); |
256 |
menu.remove(separator2); |
257 |
} |
258 |
} else { |
259 |
if (!wasSeparator) { |
260 |
menu.insert(separator1, 1); |
261 |
} |
262 |
int i; |
263 |
for (i = 0; i < items.length; i++) { |
264 |
menu.insert(items[i], i + 2); |
265 |
} |
266 |
menu.insert(separator2, i + 2); |
267 |
} |
268 |
} |
269 |
|
270 |
@Override |
271 |
public void actionPerformed(ActionEvent e) { |
272 |
JMenuItem item = (JMenuItem)e.getSource(); |
273 |
final BuildExecutionSupport.ActionItem ai = |
274 |
(BuildExecutionSupport.ActionItem) item.getClientProperty(DEBUG_ACTION_ITEM_PROP_NAME); |
275 |
RP.post(new Runnable() { |
276 |
@Override |
277 |
public void run() { |
278 |
ai.repeatExecution(); |
279 |
} |
280 |
}); |
281 |
} |
282 |
|
283 |
@Override |
284 |
public void stateChanged(ChangeEvent e) { |
285 |
BuildExecutionSupport.Item lastItem = BuildExecutionSupport.getLastFinishedItem(); |
286 |
if (lastItem instanceof BuildExecutionSupport.ActionItem) { |
287 |
BuildExecutionSupport.ActionItem ai = (BuildExecutionSupport.ActionItem) lastItem; |
288 |
String action = ai.getAction(); |
289 |
if (ActionProvider.COMMAND_DEBUG.equals(action)) { // Track debug items only |
290 |
boolean changed = false; |
291 |
synchronized (debugItems) { |
292 |
if (debugItems.isEmpty() || ai != debugItems.getFirst()) { |
293 |
debugItems.remove(ai); // Remove it if it's there |
294 |
debugItems.addFirst(ai); |
295 |
if (debugItems.size() > MAX_ITEMS_COUNT) { |
296 |
debugItems.removeLast(); |
297 |
} |
298 |
changed = true; |
299 |
} |
300 |
} |
301 |
if (changed) { |
302 |
computeItems(); |
303 |
} |
304 |
} |
305 |
} |
306 |
} |
307 |
} |
308 |
|
309 |
private static class BuildExecutionSupportChangeSupport { |
310 |
|
311 |
public void addChangeListener(ChangeListener listener) { |
312 |
BuildExecutionSupport.addChangeListener(listener); |
313 |
} |
314 |
|
315 |
public void removeChangeListener(ChangeListener listener) { |
316 |
BuildExecutionSupport.removeChangeListener(listener); |
317 |
} |
318 |
} |
200 |
|
319 |
|
201 |
// AttachHistorySupport ..................................................... |
320 |
// AttachHistorySupport ..................................................... |
202 |
|
321 |
|