Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 80654
Collapse All | Expand All

(-)Ant Editor/org/eclipse/ant/internal/ui/editor/actions/AntEditorActionMessages.properties (+1 lines)
Lines 18-23 Link Here
18
18
19
TogglePresentation.label=Show Source of Selected Element Only
19
TogglePresentation.label=Show Source of Selected Element Only
20
TogglePresentation.tooltip=Show Source of Selected Element Only
20
TogglePresentation.tooltip=Show Source of Selected Element Only
21
ToggleLineBreakpointAction.0=Breakpoint cannot be set at the given position
21
22
22
Projection.Toggle.label= &Enable Folding
23
Projection.Toggle.label= &Enable Folding
23
Projection.Toggle.tooltip= Toggles Folding
24
Projection.Toggle.tooltip= Toggles Folding
(-)Ant Editor/org/eclipse/ant/internal/ui/editor/actions/ToggleLineBreakpointAction.java (-2 / +60 lines)
Lines 12-23 Link Here
12
12
13
import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
13
import org.eclipse.ant.internal.ui.debug.IAntDebugConstants;
14
import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint;
14
import org.eclipse.ant.internal.ui.debug.model.AntLineBreakpoint;
15
import org.eclipse.ant.internal.ui.editor.AntEditor;
16
import org.eclipse.ant.internal.ui.model.AntElementNode;
17
import org.eclipse.ant.internal.ui.model.AntModel;
18
import org.eclipse.ant.internal.ui.model.AntTaskNode;
15
import org.eclipse.core.resources.IResource;
19
import org.eclipse.core.resources.IResource;
16
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.CoreException;
17
import org.eclipse.debug.core.DebugPlugin;
21
import org.eclipse.debug.core.DebugPlugin;
18
import org.eclipse.debug.core.model.IBreakpoint;
22
import org.eclipse.debug.core.model.IBreakpoint;
19
import org.eclipse.debug.core.model.ILineBreakpoint;
23
import org.eclipse.debug.core.model.ILineBreakpoint;
20
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
24
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
25
import org.eclipse.jface.action.IStatusLineManager;
26
import org.eclipse.jface.text.BadLocationException;
27
import org.eclipse.jface.text.IDocument;
28
import org.eclipse.jface.text.IRegion;
21
import org.eclipse.jface.text.ITextSelection;
29
import org.eclipse.jface.text.ITextSelection;
22
import org.eclipse.jface.viewers.ISelection;
30
import org.eclipse.jface.viewers.ISelection;
23
import org.eclipse.swt.widgets.Display;
31
import org.eclipse.swt.widgets.Display;
Lines 33-54 Link Here
33
	 */
41
	 */
34
	public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
42
	public void toggleLineBreakpoints(IWorkbenchPart part, ISelection selection) throws CoreException {
35
		ITextSelection textSelection = (ITextSelection) selection;
43
		ITextSelection textSelection = (ITextSelection) selection;
36
		int lineNumber = textSelection.getStartLine();
37
		IEditorPart editorPart = (IEditorPart)part;
44
		IEditorPart editorPart = (IEditorPart)part;
38
		IEditorInput editorInput = editorPart.getEditorInput();
45
		IEditorInput editorInput = editorPart.getEditorInput();
46
		
39
		IResource resource= null;
47
		IResource resource= null;
40
		if (editorInput instanceof IFileEditorInput) {
48
		if (editorInput instanceof IFileEditorInput) {
41
			resource= ((IFileEditorInput)editorInput).getFile();
49
			resource= ((IFileEditorInput)editorInput).getFile();
42
		}
50
		}
43
		if (resource == null) {
51
		if (resource == null) {
44
			Display.getCurrent().beep();
52
			Display.getCurrent().beep();
53
			return;
54
		}
55
		
56
		int lineNumber= getLineNumber(editorPart, textSelection);
57
		if (lineNumber == -1) {
58
			IStatusLineManager statusLine = editorPart.getEditorSite().getActionBars().getStatusLineManager();
59
			statusLine.setErrorMessage(AntEditorActionMessages.getString("ToggleLineBreakpointAction.0")); //$NON-NLS-1$
60
			Display.getCurrent().beep();
61
			return;
45
		}
62
		}
46
		IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
63
		IBreakpoint[] breakpoints = DebugPlugin.getDefault().getBreakpointManager().getBreakpoints(IAntDebugConstants.ID_ANT_DEBUG_MODEL);
47
		for (int i = 0; i < breakpoints.length; i++) {
64
		for (int i = 0; i < breakpoints.length; i++) {
48
			IBreakpoint breakpoint = breakpoints[i];
65
			IBreakpoint breakpoint = breakpoints[i];
49
			if (resource.equals(breakpoint.getMarker().getResource())) {
66
			if (resource.equals(breakpoint.getMarker().getResource())) {
50
				if (((ILineBreakpoint)breakpoint).getLineNumber() == (lineNumber + 1)) {
67
				if (((ILineBreakpoint)breakpoint).getLineNumber() == (lineNumber + 1)) {
51
					// remove
52
					breakpoint.delete();
68
					breakpoint.delete();
53
					return;
69
					return;
54
				}
70
				}
Lines 59-64 Link Here
59
		DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
75
		DebugPlugin.getDefault().getBreakpointManager().addBreakpoint(lineBreakpoint);
60
	}
76
	}
61
	
77
	
78
	private int getLineNumber(IEditorPart editorPart, ITextSelection textSelection) {
79
		int lineNumber= textSelection.getStartLine();
80
		if (editorPart instanceof AntEditor) {
81
			AntEditor editor= (AntEditor) editorPart;
82
			AntModel model= editor.getAntModel();
83
			IDocument doc= editor.getDocumentProvider().getDocument(editor.getEditorInput());
84
			lineNumber= getValidLineNumberFromModel(model, doc, lineNumber);
85
			
86
		}
87
		return lineNumber;
88
	}
89
90
	private int getValidLineNumberFromModel(AntModel model, IDocument doc, int lineNumber) {
91
		try {
92
			AntElementNode node= model.getNode(doc.getLineOffset(lineNumber), false);
93
			if (node == null) {
94
				return -1;
95
			}
96
			if (node instanceof AntTaskNode) {
97
				//TODO return the last line of the task
98
				return doc.getLineOfOffset(node.getOffset());// + node.getLength());
99
			} 
100
			IRegion lineInfo;
101
			try {
102
				lineInfo= doc.getLineInformation(lineNumber);
103
			} catch (BadLocationException e) {
104
				return lineNumber;
105
			}
106
			int startOffset= lineInfo.getOffset();
107
			int endOffset= startOffset + lineInfo.getLength();
108
			
109
			node= node.getNode(startOffset, endOffset);
110
			if (node instanceof AntTaskNode) {
111
				//TODO return the last line of the task
112
				return doc.getLineOfOffset(node.getOffset());// + node.getLength());
113
			} 
114
			return getValidLineNumberFromModel(model, doc, lineNumber + 1);
115
		} catch (BadLocationException e) {
116
			return lineNumber;
117
		}
118
	}
119
62
	/* (non-Javadoc)
120
	/* (non-Javadoc)
63
	 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
121
	 * @see org.eclipse.debug.ui.actions.IToggleBreakpointsTarget#canToggleLineBreakpoints(org.eclipse.ui.IWorkbenchPart, org.eclipse.jface.viewers.ISelection)
64
	 */
122
	 */
(-)Ant Tools Support/org/eclipse/ant/internal/ui/model/AntElementNode.java (+28 lines)
Lines 471-476 Link Here
471
		return null;
471
		return null;
472
	}
472
	}
473
	
473
	
474
	/**
475
	 * Returns the node with the narrowest source range that is fully contained between
476
     * the start and end offset.
477
	 * It may be this node or one of its children or <code>null</code> if the range is not in the source range of this node.
478
	 * @param startOffset The start offset
479
	 * @param endOffset The end offset
480
	 * @return the node that includes the range in its source range or <code>null</code>
481
	 */
482
	public AntElementNode getNode(int startOffset, int endOffset) {
483
		if (fChildNodes != null) {
484
			for (Iterator iter = fChildNodes.iterator(); iter.hasNext(); ) {
485
				AntElementNode node = (AntElementNode) iter.next();
486
				AntElementNode containingNode= node.getNode(startOffset, endOffset);
487
				if (containingNode != null) {
488
					return containingNode;
489
				}
490
			}
491
		}
492
		if (fLength == -1 && fOffset <= startOffset && !isExternal()) { //this is still an open element
493
			return this;
494
		}
495
		if (startOffset <= fOffset  && (fOffset + fLength - 2) <= endOffset) {
496
			return this;
497
		}
498
		
499
		return null;
500
	}
501
	
474
	public Image getImage() {
502
	public Image getImage() {
475
		int flags = 0;
503
		int flags = 0;
476
		
504
		

Return to bug 80654