|
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 |
*/ |