View | Details | Raw Unified | Return to bug 369856 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.debug.ui/plugin.xml (+6 lines)
Lines 2660-2665 M4 = Platform-specific fourth key Link Here
2660
                  type="org.eclipse.debug.ui.contexts.ISuspendTrigger">
2660
                  type="org.eclipse.debug.ui.contexts.ISuspendTrigger">
2661
            </adapter>
2661
            </adapter>
2662
         </factory>
2662
         </factory>
2663
         <factory 
2664
            class="org.eclipse.debug.internal.ui.actions.breakpoints.DefaultEditBreakpointsTargetFactory"
2665
            adaptableType="org.eclipse.debug.core.model.IBreakpoint">
2666
            <adapter type="org.eclipse.debug.ui.actions.IEditBreakpointTarget"/>
2667
         </factory>
2668
         
2663
    </extension>
2669
    </extension>
2664
<!-- ========================================= -->
2670
<!-- ========================================= -->
2665
<!-- Contextual Launch                         -->
2671
<!-- Contextual Launch                         -->
(-)a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/ToggleBreakpointsTargetManager.java (-4 / +71 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2011 Wind River Systems and others.
2
 * Copyright (c) 2008, 2012 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
Lines 29-34 import org.eclipse.core.expressions.Expression; Link Here
29
import org.eclipse.core.expressions.ExpressionConverter;
29
import org.eclipse.core.expressions.ExpressionConverter;
30
import org.eclipse.core.expressions.ExpressionTagNames;
30
import org.eclipse.core.expressions.ExpressionTagNames;
31
import org.eclipse.core.expressions.IEvaluationContext;
31
import org.eclipse.core.expressions.IEvaluationContext;
32
import org.eclipse.core.resources.IMarker;
32
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.IAdaptable;
34
import org.eclipse.core.runtime.IAdaptable;
34
import org.eclipse.core.runtime.IAdapterManager;
35
import org.eclipse.core.runtime.IAdapterManager;
Lines 38-43 import org.eclipse.core.runtime.IStatus; Link Here
38
import org.eclipse.core.runtime.ListenerList;
39
import org.eclipse.core.runtime.ListenerList;
39
import org.eclipse.core.runtime.Platform;
40
import org.eclipse.core.runtime.Platform;
40
import org.eclipse.core.runtime.Status;
41
import org.eclipse.core.runtime.Status;
42
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
43
import org.eclipse.core.runtime.preferences.InstanceScope;
44
import org.eclipse.debug.core.DebugPlugin;
45
import org.eclipse.debug.core.model.IBreakpoint;
41
import org.eclipse.debug.internal.core.IConfigurationElementConstants;
46
import org.eclipse.debug.internal.core.IConfigurationElementConstants;
42
import org.eclipse.debug.internal.ui.DebugUIPlugin;
47
import org.eclipse.debug.internal.ui.DebugUIPlugin;
43
import org.eclipse.debug.ui.DebugUITools;
48
import org.eclipse.debug.ui.DebugUITools;
Lines 45-55 import org.eclipse.debug.ui.IDebugUIConstants; Link Here
45
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
50
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
46
import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetExtension;
51
import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetExtension;
47
import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetFactory;
52
import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetFactory;
53
import org.eclipse.jface.text.BadLocationException;
54
import org.eclipse.jface.text.IDocument;
55
import org.eclipse.jface.text.Position;
56
import org.eclipse.jface.text.source.IAnnotationModel;
57
import org.eclipse.jface.text.source.IVerticalRulerInfo;
48
import org.eclipse.jface.viewers.ISelection;
58
import org.eclipse.jface.viewers.ISelection;
49
import org.eclipse.jface.viewers.IStructuredSelection;
59
import org.eclipse.jface.viewers.IStructuredSelection;
50
import org.eclipse.jface.viewers.StructuredSelection;
60
import org.eclipse.jface.viewers.StructuredSelection;
61
import org.eclipse.ui.IEditorInput;
51
import org.eclipse.ui.IEditorPart;
62
import org.eclipse.ui.IEditorPart;
52
import org.eclipse.ui.IWorkbenchPart;
63
import org.eclipse.ui.IWorkbenchPart;
64
import org.eclipse.ui.texteditor.IDocumentProvider;
65
import org.eclipse.ui.texteditor.ITextEditor;
66
import org.eclipse.ui.texteditor.SimpleMarkerAnnotation;
53
67
54
/**
68
/**
55
 * Organizes the toggle breakpoints target factories contributed through the 
69
 * Organizes the toggle breakpoints target factories contributed through the 
Lines 82-88 public class ToggleBreakpointsTargetManager { Link Here
82
    
96
    
83
    /**
97
    /**
84
     * Acts as a proxy between the toggle breakpoints target manager and the factories 
98
     * Acts as a proxy between the toggle breakpoints target manager and the factories 
85
     * contributed to the extension point.  Only loads information from the plug-in xml 
99
     * contributed to the extension point.  Only loads information from the plug-in XML 
86
     * and only instantiates the specified factory if required (lazy loading).
100
     * and only instantiates the specified factory if required (lazy loading).
87
     */
101
     */
88
    private static class ToggleTargetFactory implements IToggleBreakpointsTargetFactory {
102
    private static class ToggleTargetFactory implements IToggleBreakpointsTargetFactory {
Lines 635-641 public class ToggleBreakpointsTargetManager { Link Here
635
            buffer.append(entry.getValue());
649
            buffer.append(entry.getValue());
636
            buffer.append('|');
650
            buffer.append('|');
637
        }
651
        }
638
        DebugUIPlugin.getDefault().getPluginPreferences().setValue(PREF_TARGETS, buffer.toString());
652
        IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(DebugUIPlugin.getUniqueIdentifier());
653
        if(prefs != null) {
654
        	prefs.put(PREF_TARGETS, buffer.toString());
655
        }
639
    }
656
    }
640
657
641
    /**
658
    /**
Lines 645-651 public class ToggleBreakpointsTargetManager { Link Here
645
     */
662
     */
646
    private void loadPreferredTargets() {
663
    private void loadPreferredTargets() {
647
        fPreferredTargets = new HashMap();
664
        fPreferredTargets = new HashMap();
648
        String preferenceValue = DebugUIPlugin.getDefault().getPluginPreferences().getString(PREF_TARGETS);
665
        String preferenceValue = Platform.getPreferencesService().getString(
666
        		DebugUIPlugin.getUniqueIdentifier(), 
667
        		PREF_TARGETS, 
668
        		null, 
669
        		null);
670
        if(preferenceValue == null) {
671
        	return;
672
        }
649
        StringTokenizer entryTokenizer = new StringTokenizer(preferenceValue,"|"); //$NON-NLS-1$
673
        StringTokenizer entryTokenizer = new StringTokenizer(preferenceValue,"|"); //$NON-NLS-1$
650
        while (entryTokenizer.hasMoreTokens()){
674
        while (entryTokenizer.hasMoreTokens()){
651
            String token = entryTokenizer.nextToken();
675
            String token = entryTokenizer.nextToken();
Lines 744-747 public class ToggleBreakpointsTargetManager { Link Here
744
        }
768
        }
745
    }
769
    }
746
    
770
    
771
    /**
772
     * Attempts to resolve the {@link IBreakpoint} from the {@link IMarker} at the current location in the editor on the vertical ruler.
773
     * <br><br>
774
     * Returns <code>null</code> if the breakpoint cannot be resolved.
775
     * @param editor the backing editor
776
     * @param info the current {@link IVerticalRulerInfo}
777
     * @return the {@link IBreakpoint} backing the marker on the ruler or <code>null</code>
778
     * @since 3.8
779
     */
780
    public static IBreakpoint getBeakpointFromEditor(ITextEditor editor, IVerticalRulerInfo info) {
781
    	IDocumentProvider provider = editor.getDocumentProvider();
782
    	if(provider == null) {
783
    		return null;
784
    	}
785
    	IEditorInput input = editor.getEditorInput();
786
    	IAnnotationModel annotationModel = provider.getAnnotationModel(input);
787
		if (annotationModel != null) {
788
			IDocument document = provider.getDocument(input);
789
			Iterator iterator = annotationModel.getAnnotationIterator();
790
			while (iterator.hasNext()) {
791
				Object object = iterator.next();
792
				if (object instanceof SimpleMarkerAnnotation) {
793
					SimpleMarkerAnnotation markerAnnotation = (SimpleMarkerAnnotation) object;
794
					IMarker marker = markerAnnotation.getMarker();
795
					try {
796
						if (marker.isSubtypeOf(IBreakpoint.BREAKPOINT_MARKER)) {
797
							Position position = annotationModel.getPosition(markerAnnotation);
798
							int line = document.getLineOfOffset(position.getOffset());
799
							if (line == info.getLineOfLastMouseButtonActivity()) {
800
								IBreakpoint breakpoint = DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker);
801
								if (breakpoint != null) {
802
									return breakpoint;
803
								}
804
							}
805
						}
806
					} catch (CoreException e) {
807
					} catch (BadLocationException e) {
808
					}
809
				}
810
			}
811
		}
812
    	return null;
813
    }
747
}
814
}
(-)a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/DefaultEditBreakpointsTargetFactory.java (+44 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 Wind River 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
 *     Wind River Systems - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.internal.ui.actions.breakpoints;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.IAdapterFactory;
15
import org.eclipse.debug.core.model.IBreakpoint;
16
import org.eclipse.debug.ui.actions.IEditBreakpointTarget;
17
import org.eclipse.ui.IWorkbenchPart;
18
import org.eclipse.ui.dialogs.PreferencesUtil;
19
20
/**
21
 * Default action implementation to edit breakpoint properties.
22
 * @since 3.8
23
 */
24
public class DefaultEditBreakpointsTargetFactory implements IAdapterFactory {
25
26
    private final static IEditBreakpointTarget fgEditBreakpointsTarget = 
27
        new IEditBreakpointTarget() {
28
            public void editBreakpointProperties(IWorkbenchPart part, IBreakpoint breakpoint) throws CoreException {
29
                PreferencesUtil.createPropertyDialogOn(
30
                    part.getSite().getShell(), breakpoint, null, null, null, 0).open();        
31
            }
32
        };
33
        
34
    public Class[] getAdapterList() {
35
        return new Class[] { IEditBreakpointTarget.class };
36
    }
37
38
    public Object getAdapter(Object adaptableObject, Class adapterType) {
39
        if (adaptableObject instanceof IBreakpoint && IEditBreakpointTarget.class.equals(adapterType)) {
40
            return fgEditBreakpointsTarget;
41
        }
42
        return null;
43
    }
44
}
(-)a/org.eclipse.debug.ui/ui/org/eclipse/debug/internal/ui/actions/breakpoints/RulerCreateBreakpointInteractiveAction.java (+209 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2009 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *     Wind River Systems - added support for IToggleBreakpointsTargetFactory
11
 *******************************************************************************/
12
package org.eclipse.debug.internal.ui.actions.breakpoints;
13
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.debug.internal.ui.DebugUIPlugin;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.internal.ui.actions.IToggleBreakpointsTargetManagerListener;
18
import org.eclipse.debug.internal.ui.actions.ToggleBreakpointsTargetManager;
19
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
20
import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetExtension2;
21
import org.eclipse.jface.action.Action;
22
import org.eclipse.jface.text.BadLocationException;
23
import org.eclipse.jface.text.IDocument;
24
import org.eclipse.jface.text.IRegion;
25
import org.eclipse.jface.text.ITextSelection;
26
import org.eclipse.jface.text.TextSelection;
27
import org.eclipse.jface.text.source.IVerticalRulerInfo;
28
import org.eclipse.jface.viewers.ISelection;
29
import org.eclipse.jface.viewers.ISelectionProvider;
30
import org.eclipse.ui.IWorkbenchPart;
31
import org.eclipse.ui.texteditor.IDocumentProvider;
32
import org.eclipse.ui.texteditor.ITextEditor;
33
import org.eclipse.ui.texteditor.IUpdate;
34
35
/**
36
 * Action to interactively create a breakpoint from vertical ruler of a 
37
 * workbench part containing a document. The part must provide an 
38
 * <code>IToggleBreakpointsTargetExtension2</code> adapter.
39
 * <p>
40
 * Clients may instantiate this class. 
41
 * </p>
42
 * @since 3.8
43
 * @see org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate
44
 */
45
public class RulerCreateBreakpointInteractiveAction extends Action implements IUpdate {
46
	
47
	private IWorkbenchPart fPart;
48
	private IDocument fDocument;
49
	private IVerticalRulerInfo fRulerInfo;
50
	private IToggleBreakpointsTargetManagerListener fListener = new IToggleBreakpointsTargetManagerListener() {
51
	    public void preferredTargetsChanged() {
52
	        update();	        
53
	    }
54
	};
55
56
	/**
57
	 * Constructs a new action to toggle a breakpoint in the given
58
	 * part containing the given document and ruler.
59
	 * 
60
	 * @param part the part in which to toggle the breakpoint - provides
61
	 *  an <code>IToggleBreakpointsTarget</code> adapter
62
	 * @param document the document breakpoints are being set in or
63
	 * <code>null</code> when the document should be derived from the
64
	 * given part
65
	 * @param rulerInfo specifies location the user has double-clicked
66
	 */
67
	public RulerCreateBreakpointInteractiveAction(IWorkbenchPart part, IDocument document, IVerticalRulerInfo rulerInfo) {
68
		super(ActionMessages.ToggleBreakpointAction_0);
69
		fPart = part;
70
		fDocument = document;
71
		fRulerInfo = rulerInfo;
72
		ToggleBreakpointsTargetManager.getDefault().addChangedListener(fListener);
73
	}
74
	
75
	/*
76
	 *  (non-Javadoc)
77
	 * @see org.eclipse.jface.action.IAction#run()
78
	 */
79
	public void run() {
80
		IDocument document= getDocument();
81
		if (document == null) {
82
			return;
83
		}
84
85
		int line = fRulerInfo.getLineOfLastMouseButtonActivity();
86
		
87
		// Test if line is valid
88
		if (line == -1)
89
			return;
90
91
		try {
92
			ITextSelection selection = getTextSelection(document, line);
93
			IToggleBreakpointsTarget toggleTarget = 
94
			    ToggleBreakpointsTargetManager.getDefault().getToggleBreakpointsTarget(fPart, selection);
95
			if (toggleTarget instanceof IToggleBreakpointsTargetExtension2) {
96
                IToggleBreakpointsTargetExtension2 extension = (IToggleBreakpointsTargetExtension2) toggleTarget;
97
                if (extension.canCreateBreakpointsInteractive(fPart, selection)) {
98
                    extension.createBreakpointsInteractive(fPart, selection);
99
                }                    
100
            } 
101
		} catch (BadLocationException e) {
102
			reportException(e);
103
		} catch (CoreException e) {
104
			reportException(e);
105
		}
106
	}
107
	
108
	/**
109
	 * Report an error to the user.
110
	 * 
111
	 * @param e underlying exception
112
	 */
113
	private void reportException(Exception e) {
114
		DebugUIPlugin.errorDialog(fPart.getSite().getShell(), ActionMessages.ToggleBreakpointAction_1, ActionMessages.ToggleBreakpointAction_2, e); //
115
	}
116
	
117
	/**
118
	 * Disposes this action. Clients must call this method when
119
	 * this action is no longer needed.
120
	 */
121
	public void dispose() {
122
		fDocument = null;
123
		fPart = null;
124
		fRulerInfo = null;
125
	    ToggleBreakpointsTargetManager.getDefault().removeChangedListener(fListener);
126
	}
127
128
	/**
129
	 * Returns the document on which this action operates.
130
	 * 
131
	 * @return the document or <code>null</code> if none
132
	 */
133
	private IDocument getDocument() {
134
		if (fDocument != null)
135
			return fDocument;
136
		
137
		if (fPart instanceof ITextEditor) {
138
			ITextEditor editor= (ITextEditor)fPart;
139
			IDocumentProvider provider = editor.getDocumentProvider();
140
			if (provider != null)
141
				return provider.getDocument(editor.getEditorInput());
142
		}
143
		
144
		IDocument doc = (IDocument) fPart.getAdapter(IDocument.class);
145
		if (doc != null) {
146
			return doc;
147
		}
148
		
149
		return null;
150
	}
151
	
152
	/* (non-Javadoc)
153
	 * @see org.eclipse.ui.texteditor.IUpdate#update()
154
	 */
155
	public void update() {
156
		IDocument document= getDocument();
157
		if (document != null) {
158
		    int line = fRulerInfo.getLineOfLastMouseButtonActivity();
159
		    if (line > -1) {
160
		        try {
161
		            ITextSelection selection = getTextSelection(document, line);
162
                   
163
                    IToggleBreakpointsTarget adapter = 
164
                        ToggleBreakpointsTargetManager.getDefault().getToggleBreakpointsTarget(fPart, selection);
165
                    if (adapter == null) {
166
                        setEnabled(false);
167
                        return;
168
                    }
169
                    if (adapter instanceof IToggleBreakpointsTargetExtension2) {
170
                        IToggleBreakpointsTargetExtension2 extension = (IToggleBreakpointsTargetExtension2) adapter;
171
                        if (extension.canCreateBreakpointsInteractive(fPart, selection)) {
172
                            setEnabled(true);
173
                            return;
174
                        }
175
                    }
176
                } catch (BadLocationException e) {
177
                    reportException(e);
178
                }
179
			}
180
		}
181
		setEnabled(false);
182
	}
183
184
	/**
185
	 * Determines the text selection for the breakpoint action.  If clicking on the ruler inside
186
	 * the highlighted text, return the text selection for the highlighted text.  Otherwise, 
187
	 * return a text selection representing the start of the line.
188
	 * 
189
	 * @param document	The IDocument backing the Editor.
190
	 * @param line	The line clicked on in the ruler.
191
	 * @return	An ITextSelection as described.
192
	 * @throws BadLocationException	If underlying operations throw.
193
	 */
194
	private ITextSelection getTextSelection(IDocument document, int line) throws BadLocationException {
195
		IRegion region = document.getLineInformation(line);
196
		ITextSelection textSelection = new TextSelection(document, region.getOffset(), 0);
197
		ISelectionProvider provider = fPart.getSite().getSelectionProvider();
198
		if (provider != null){
199
			ISelection selection = provider.getSelection();
200
			if (selection instanceof ITextSelection
201
					&& ((ITextSelection) selection).getStartLine() <= line
202
					&& ((ITextSelection) selection).getEndLine() >= line) {
203
				textSelection = (ITextSelection) selection;
204
			} 
205
		}
206
		return textSelection;
207
	}
208
209
}
(-)a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IEditBreakpointTarget.java (+33 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2012 Wind River 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
 *     Wind River Systems - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.ui.actions;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.debug.core.model.IBreakpoint;
15
import org.eclipse.ui.IWorkbenchPart;
16
17
/**
18
 * Allows the UI to edit a breakpoint(s) properties.  The implementation of this 
19
 * interface is to be registered as an adapter to a breakpoint.   
20
 * 
21
 * @since 3.8
22
 */
23
public interface IEditBreakpointTarget {
24
    
25
    /**
26
     * Opens a dialog to edit the given breakpoint properties. 
27
     * @param part Workbench part where this action target is invoked from.
28
     * @param breakpoint Breakpoint to be edited. 
29
     * @throws CoreException if unable to edit breakpoint properties.  Should not 
30
     * be thrown if user cancels the edit action.
31
     */
32
    public void editBreakpointProperties(IWorkbenchPart part, IBreakpoint breakpoint) throws CoreException;
33
}
(-)a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/IToggleBreakpointsTargetExtension2.java (+61 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2005 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.ui.actions;
12
13
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.ui.IWorkbenchPart;
16
17
/**
18
 * Second extension interface for {@link org.eclipse.debug.ui.actions.IToggleBreakpointsTarget}.
19
 * This interface provides the ability open edit a breakpoint's properties and 
20
 * to create a breakpoint in the given context with additional user input 
21
 * (such as using a dialog or a wizard).
22
 * <p>
23
 * Clients implementing <code>IToggleBreakpointsTarget</code> may optionally
24
 * implement this interface.
25
 * </p>
26
 * @since 3.8
27
 * @see org.eclipse.debug.ui.actions.ToggleBreakpointAction
28
 */
29
public interface IToggleBreakpointsTargetExtension2 extends IToggleBreakpointsTargetExtension {
30
31
    /**
32
     * Returns whether the toggle target can create a a breakpoint at the 
33
     * given location.  If the implementation does not support creating the 
34
     * breakpoint interactively then it should return <code>false</code>.
35
     * <p>
36
     * The selection varies depending on the given part. For example,
37
     * a text selection is provided for text editors, and a structured
38
     * selection is provided for tree views, and may be a multi-selection.
39
     * </p>
40
     * @param part the part on which the action has been invoked  
41
     * @param selection selection on which line breakpoints should be toggled
42
     * @return Returns <code>true</code> if toggle target is able interactively
43
     * create a breakpoint(s) at the given location.
44
     */
45
    public boolean canCreateBreakpointsInteractive(IWorkbenchPart part, ISelection selection);
46
47
	/**
48
     * Creates new breakpoints interactively.  The implementation should allows
49
     * the user to edit all of the breakpoint's settings prior to creating the 
50
     * breakpoint.  
51
     * <p>
52
     * The selection varies depending on the given part. For example,
53
     * a text selection is provided for text editors, and a structured
54
     * selection is provided for tree views, and may be a multi-selection.
55
     * </p>
56
     * @param part the part on which the action has been invoked  
57
     * @param selection selection on which line breakpoints should be toggled
58
     * @throws CoreException if unable to perform the action 
59
     */
60
    public void createBreakpointsInteractive(IWorkbenchPart part, ISelection selection) throws CoreException;
61
}
(-)a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerBreakpointAction.java (-39 / +4 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2006 IBM Corporation and others.
2
 * Copyright (c) 2005, 2012 IBM Corporation 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 10-34 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.debug.ui.actions;
11
package org.eclipse.debug.ui.actions;
12
12
13
import java.util.Iterator;
14
15
import org.eclipse.core.resources.IMarker;
16
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.debug.core.DebugPlugin;
18
import org.eclipse.debug.core.model.IBreakpoint;
13
import org.eclipse.debug.core.model.IBreakpoint;
14
import org.eclipse.debug.internal.ui.actions.ToggleBreakpointsTargetManager;
19
import org.eclipse.jface.action.Action;
15
import org.eclipse.jface.action.Action;
20
import org.eclipse.jface.text.BadLocationException;
21
import org.eclipse.jface.text.IDocument;
22
import org.eclipse.jface.text.Position;
23
import org.eclipse.jface.text.source.IAnnotationModel;
24
import org.eclipse.jface.text.source.IVerticalRulerInfo;
16
import org.eclipse.jface.text.source.IVerticalRulerInfo;
25
import org.eclipse.ui.texteditor.ITextEditor;
17
import org.eclipse.ui.texteditor.ITextEditor;
26
import org.eclipse.ui.texteditor.SimpleMarkerAnnotation;
27
18
28
/**
19
/**
29
 * Abstract action that works on breakpoints in the vertical ruler.
20
 * Abstract action that works on breakpoints in the vertical ruler.
30
 * <p>
21
 * <p>
31
 * This class may be subclassed.
22
 * This class may be sub-classed.
32
 * </p>
23
 * </p>
33
 * @since 3.2
24
 * @since 3.2
34
 */
25
 */
Lines 56-88 public abstract class RulerBreakpointAction extends Action { Link Here
56
	 * @return breakpoint associated with activity in the ruler or <code>null</code>
47
	 * @return breakpoint associated with activity in the ruler or <code>null</code>
57
	 */
48
	 */
58
	protected IBreakpoint getBreakpoint() {
49
	protected IBreakpoint getBreakpoint() {
59
		IAnnotationModel annotationModel = fEditor.getDocumentProvider().getAnnotationModel(fEditor.getEditorInput());
50
		return ToggleBreakpointsTargetManager.getBeakpointFromEditor(fEditor, fRulerInfo);
60
		IDocument document = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
61
		if (annotationModel != null) {
62
			Iterator iterator = annotationModel.getAnnotationIterator();
63
			while (iterator.hasNext()) {
64
				Object object = iterator.next();
65
				if (object instanceof SimpleMarkerAnnotation) {
66
					SimpleMarkerAnnotation markerAnnotation = (SimpleMarkerAnnotation) object;
67
					IMarker marker = markerAnnotation.getMarker();
68
					try {
69
						if (marker.isSubtypeOf(IBreakpoint.BREAKPOINT_MARKER)) {
70
							Position position = annotationModel.getPosition(markerAnnotation);
71
							int line = document.getLineOfOffset(position.getOffset());
72
							if (line == fRulerInfo.getLineOfLastMouseButtonActivity()) {
73
								IBreakpoint breakpoint = DebugPlugin.getDefault().getBreakpointManager().getBreakpoint(marker);
74
								if (breakpoint != null) {
75
									return breakpoint;
76
								}
77
							}
78
						}
79
					} catch (CoreException e) {
80
					} catch (BadLocationException e) {
81
					}
82
				}
83
			}
84
		}
85
		return null;
86
	}
51
	}
87
	
52
	
88
	/**
53
	/**
(-)a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerCreateBreakpointInteractiveActionDelegate.java (+97 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2012 IBM Corporation 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.debug.ui.actions;
12
13
import org.eclipse.debug.internal.ui.actions.breakpoints.RulerCreateBreakpointInteractiveAction;
14
import org.eclipse.jface.action.IAction;
15
import org.eclipse.jface.text.source.IVerticalRulerInfo;
16
import org.eclipse.ui.IActionDelegate2;
17
import org.eclipse.ui.IEditorPart;
18
import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
19
import org.eclipse.ui.texteditor.ITextEditor;
20
21
/**
22
 * Creates a breakpoint interactively, that is with user input as well as context 
23
 * information gathered from editor location. This action delegate can be 
24
 * contributed to an editor with the <code>editorActions</code> extension point.
25
 * This action is as a factory that creates another action that performs the
26
 * actual breakpoint toggling. The created action acts on the editor's
27
 * <code>IToggleBreakpointsTagretExtension2</code> to create the breakpoint.
28
 * <p>
29
 * This action should be be contributed to a vertical ruler context menu via the
30
 * <code>popupMenus</code> extension point, by referencing the ruler's context
31
 * menu identifier in the <code>targetID</code> attribute.
32
 * <pre>
33
 * &lt;extension point="org.eclipse.ui.popupMenus"&gt;
34
 *   &lt;viewerContribution
35
 *     targetID="example.rulerContextMenuId"
36
 *     id="example.RulerPopupActions"&gt;
37
 *       &lt;action
38
 *         label="Toggle Breakpoint"
39
 *         class="org.eclipse.debug.ui.actions.RulerCreateBreakpointInteractiveActionDelegate"
40
 *         menubarPath="additions"
41
 *         id="example.rulerContextMenu.createBreakpointAction"&gt;
42
 *       &lt;/action&gt;
43
 *   &lt;/viewerContribution&gt;
44
 * </pre>
45
 * </p>
46
 * <p>
47
 * Clients may refer to this class as an action delegate in plug-in XML. 
48
 * </p>
49
 * @see IToggleBreakpointsTargetExtension2
50
 * @since 3.8
51
 * @noextend This class is not intended to be sub-classed by clients.
52
 * @noinstantiate This class is not intended to be instantiated by clients.
53
 */
54
public class RulerCreateBreakpointInteractiveActionDelegate extends AbstractRulerActionDelegate implements IActionDelegate2 {
55
	
56
	private IEditorPart fEditor = null;
57
	private RulerCreateBreakpointInteractiveAction fDelegate = null;
58
59
	/* (non-Javadoc)
60
	 * @see org.eclipse.ui.texteditor.AbstractRulerActionDelegate#createAction(org.eclipse.ui.texteditor.ITextEditor, org.eclipse.jface.text.source.IVerticalRulerInfo)
61
	 */
62
	protected IAction createAction(ITextEditor editor, IVerticalRulerInfo rulerInfo) {
63
		fDelegate = new RulerCreateBreakpointInteractiveAction(editor, null, rulerInfo);
64
		return fDelegate;
65
	}
66
67
	/* (non-Javadoc)
68
	 * @see org.eclipse.ui.IEditorActionDelegate#setActiveEditor(org.eclipse.jface.action.IAction, org.eclipse.ui.IEditorPart)
69
	 */
70
	public void setActiveEditor(IAction callerAction, IEditorPart targetEditor) {
71
		if (fEditor != null) {
72
			if (fDelegate != null) {
73
				fDelegate.dispose();
74
				fDelegate = null;
75
			}
76
		}
77
		fEditor = targetEditor;
78
		super.setActiveEditor(callerAction, targetEditor);
79
	}
80
81
	/* (non-Javadoc)
82
	 * @see org.eclipse.ui.IActionDelegate2#init(org.eclipse.jface.action.IAction)
83
	 */
84
	public void init(IAction action) {
85
	}
86
87
	/* (non-Javadoc)
88
	 * @see org.eclipse.ui.IActionDelegate2#dispose()
89
	 */
90
	public void dispose() {
91
		if (fDelegate != null) {
92
			fDelegate.dispose();
93
		}
94
		fDelegate = null;
95
		fEditor = null;
96
	}
97
}
(-)a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/RulerToggleBreakpointActionDelegate.java (-13 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2005, 2008 IBM Corporation and others.
2
 * Copyright (c) 2005, 2012 IBM Corporation 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 10-21 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.debug.ui.actions;
11
package org.eclipse.debug.ui.actions;
12
12
13
import org.eclipse.swt.widgets.Event;
14
15
import org.eclipse.jface.action.IAction;
13
import org.eclipse.jface.action.IAction;
16
17
import org.eclipse.jface.text.source.IVerticalRulerInfo;
14
import org.eclipse.jface.text.source.IVerticalRulerInfo;
18
19
import org.eclipse.ui.IActionDelegate2;
15
import org.eclipse.ui.IActionDelegate2;
20
import org.eclipse.ui.IEditorPart;
16
import org.eclipse.ui.IEditorPart;
21
import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
17
import org.eclipse.ui.texteditor.AbstractRulerActionDelegate;
Lines 68-74 import org.eclipse.ui.texteditor.ITextEditor; Link Here
68
 * Clients may refer to this class as an action delegate in plug-in XML. 
64
 * Clients may refer to this class as an action delegate in plug-in XML. 
69
 * </p>
65
 * </p>
70
 * @since 3.1
66
 * @since 3.1
71
 * @noextend This class is not intended to be subclassed by clients.
67
 * @noextend This class is not intended to be sub-classed by clients.
72
 * @noinstantiate This class is not intended to be instantiated by clients.
68
 * @noinstantiate This class is not intended to be instantiated by clients.
73
 */
69
 */
74
public class RulerToggleBreakpointActionDelegate extends AbstractRulerActionDelegate implements IActionDelegate2 {
70
public class RulerToggleBreakpointActionDelegate extends AbstractRulerActionDelegate implements IActionDelegate2 {
Lines 114-124 public class RulerToggleBreakpointActionDelegate extends AbstractRulerActionDele Link Here
114
		fDelegate = null;
110
		fDelegate = null;
115
		fEditor = null;
111
		fEditor = null;
116
	}
112
	}
117
118
	/* (non-Javadoc)
119
	 * @see org.eclipse.ui.IActionDelegate2#runWithEvent(org.eclipse.jface.action.IAction, org.eclipse.swt.widgets.Event)
120
	 */
121
	public void runWithEvent(IAction action, Event event) {
122
		run(action);
123
	}
124
}
113
}
(-)a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/actions/ToggleBreakpointAction.java (-2 / +68 lines)
Lines 12-17 Link Here
12
package org.eclipse.debug.ui.actions;
12
package org.eclipse.debug.ui.actions;
13
13
14
import org.eclipse.core.runtime.CoreException;
14
import org.eclipse.core.runtime.CoreException;
15
import org.eclipse.debug.core.model.IBreakpoint;
15
import org.eclipse.debug.internal.ui.DebugUIPlugin;
16
import org.eclipse.debug.internal.ui.DebugUIPlugin;
16
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.internal.ui.actions.ActionMessages;
17
import org.eclipse.debug.internal.ui.actions.IToggleBreakpointsTargetManagerListener;
18
import org.eclipse.debug.internal.ui.actions.IToggleBreakpointsTargetManagerListener;
Lines 25-30 import org.eclipse.jface.text.TextSelection; Link Here
25
import org.eclipse.jface.text.source.IVerticalRulerInfo;
26
import org.eclipse.jface.text.source.IVerticalRulerInfo;
26
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.ISelection;
27
import org.eclipse.jface.viewers.ISelectionProvider;
28
import org.eclipse.jface.viewers.ISelectionProvider;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.widgets.Event;
28
import org.eclipse.ui.IWorkbenchPart;
31
import org.eclipse.ui.IWorkbenchPart;
29
import org.eclipse.ui.texteditor.IDocumentProvider;
32
import org.eclipse.ui.texteditor.IDocumentProvider;
30
import org.eclipse.ui.texteditor.ITextEditor;
33
import org.eclipse.ui.texteditor.ITextEditor;
Lines 71-81 public class ToggleBreakpointAction extends Action implements IUpdate { Link Here
71
		fRulerInfo = rulerInfo;
74
		fRulerInfo = rulerInfo;
72
		ToggleBreakpointsTargetManager.getDefault().addChangedListener(fListener);
75
		ToggleBreakpointsTargetManager.getDefault().addChangedListener(fListener);
73
	}
76
	}
77
	
74
	/*
78
	/*
75
	 *  (non-Javadoc)
79
	 *  (non-Javadoc)
76
	 * @see org.eclipse.jface.action.IAction#run()
80
	 * @see org.eclipse.jface.action.IAction#run()
77
	 */
81
	 */
78
	public void run() {
82
	public void run() {
83
	    run(false, false);
84
	}	    
85
	
86
	public void runWithEvent(Event event) {
87
	    run( (event.stateMask & SWT.MOD1) > 0, (event.stateMask & SWT.MOD2) > 0);
88
	}
89
	
90
	private void run(boolean mod1, boolean mod2) {
91
79
		IDocument document= getDocument();
92
		IDocument document= getDocument();
80
		if (document == null) {
93
		if (document == null) {
81
			return;
94
			return;
Lines 88-93 public class ToggleBreakpointAction extends Action implements IUpdate { Link Here
88
			return;
101
			return;
89
102
90
		try {
103
		try {
104
            //Ctrl+click to enable / disable
105
	        if(mod1) {
106
	            toggleBreakpointEnable();
107
	            return;
108
	        }
109
	        
110
	        // Shift+click to edit breakpoint properties (if breakpoint already exists).
111
	        if (mod2) {
112
                if (tryEditBreakpointProperties()) {
113
                    return;
114
                }
115
	        }	        
116
	        
91
			ITextSelection selection = getTextSelection(document, line);
117
			ITextSelection selection = getTextSelection(document, line);
92
			IToggleBreakpointsTarget toggleTarget = 
118
			IToggleBreakpointsTarget toggleTarget = 
93
			    ToggleBreakpointsTargetManager.getDefault().getToggleBreakpointsTarget(fPart, selection);
119
			    ToggleBreakpointsTargetManager.getDefault().getToggleBreakpointsTarget(fPart, selection);
Lines 95-101 public class ToggleBreakpointAction extends Action implements IUpdate { Link Here
95
			    return;
121
			    return;
96
			}
122
			}
97
123
98
			if (toggleTarget instanceof IToggleBreakpointsTargetExtension) {
124
			// Shift+click to open a dialog to create a BP (if possible), otherwise do nothing.
125
			if (mod2) {
126
	            if (toggleTarget instanceof IToggleBreakpointsTargetExtension2) {
127
	                IToggleBreakpointsTargetExtension2 extension = (IToggleBreakpointsTargetExtension2) toggleTarget;
128
	                if (extension.canCreateBreakpointsInteractive(fPart, selection)) {
129
	                    extension.createBreakpointsInteractive(fPart, selection);
130
	                }                    
131
	            }
132
	            return;
133
			}
134
            if (toggleTarget instanceof IToggleBreakpointsTargetExtension) {
99
			    IToggleBreakpointsTargetExtension extension = (IToggleBreakpointsTargetExtension) toggleTarget;
135
			    IToggleBreakpointsTargetExtension extension = (IToggleBreakpointsTargetExtension) toggleTarget;
100
				if (extension.canToggleBreakpoints(fPart, selection)) {
136
				if (extension.canToggleBreakpoints(fPart, selection)) {
101
					extension.toggleBreakpoints(fPart, selection);
137
					extension.toggleBreakpoints(fPart, selection);
Lines 116-121 public class ToggleBreakpointAction extends Action implements IUpdate { Link Here
116
		}
152
		}
117
	}
153
	}
118
	
154
	
155
	private void toggleBreakpointEnable() {
156
        if(fPart instanceof ITextEditor) {
157
            IBreakpoint bp = ToggleBreakpointsTargetManager.getBeakpointFromEditor((ITextEditor) fPart, fRulerInfo);
158
            if(bp != null) {
159
                try {
160
                    bp.setEnabled(!bp.isEnabled());
161
                } catch (CoreException e) {
162
                    DebugUIPlugin.log(e);
163
                }
164
            }
165
        }	    
166
	}
167
168
    private boolean tryEditBreakpointProperties() {
169
        if(fPart instanceof ITextEditor) {
170
            IBreakpoint bp = ToggleBreakpointsTargetManager.getBeakpointFromEditor((ITextEditor) fPart, fRulerInfo);
171
            if(bp != null) {
172
                try {
173
                    IEditBreakpointTarget editTarget = (IEditBreakpointTarget)bp.getAdapter(IEditBreakpointTarget.class);
174
                    if (editTarget != null) {
175
                        editTarget.editBreakpointProperties(fPart, bp);
176
                    }
177
                } catch (CoreException e) {
178
                    DebugUIPlugin.log(e);
179
                }
180
                return true;
181
            }
182
        }       
183
        return false;
184
    }
185
	
119
	/**
186
	/**
120
	 * Report an error to the user.
187
	 * Report an error to the user.
121
	 * 
188
	 * 
122
- 

Return to bug 369856