X-Git-Url: http://git.phpeclipse.com diff --git a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/actions/PHPManageBreakpointRulerAction.java b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/actions/PHPManageBreakpointRulerAction.java index 5b1c7ef..585a9c3 100644 --- a/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/actions/PHPManageBreakpointRulerAction.java +++ b/net.sourceforge.phpeclipse.debug.ui/src/net/sourceforge/phpdt/internal/debug/ui/actions/PHPManageBreakpointRulerAction.java @@ -1,14 +1,14 @@ /********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - IBM Corporation - Initial implementation - Vicente Fernando - www.alfersoft.com.ar -**********************************************************************/ + Copyright (c) 2000, 2002 IBM Corp. and others. + All rights reserved. This program and the accompanying materials + are made available under the terms of the Common Public License v1.0 + which accompanies this distribution, and is available at + http://www.eclipse.org/legal/cpl-v10.html + + Contributors: + IBM Corporation - Initial implementation + Vicente Fernando - www.alfersoft.com.ar + **********************************************************************/ package net.sourceforge.phpdt.internal.debug.ui.actions; import java.util.ArrayList; @@ -43,91 +43,102 @@ import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.IUpdate; -public class PHPManageBreakpointRulerAction extends Action implements IUpdate { - +public class PHPManageBreakpointRulerAction extends Action implements IUpdate { + private IVerticalRulerInfo fRuler; + private ITextEditor fTextEditor; + private String fMarkerType; + private List fMarkers; private String fAddLabel; + private String fRemoveLabel; - - public PHPManageBreakpointRulerAction(IVerticalRulerInfo ruler, ITextEditor editor) { - fRuler= ruler; - fTextEditor= editor; - fMarkerType= IBreakpoint.BREAKPOINT_MARKER; - fAddLabel= PHPDebugUiMessages.getString("PHPManageBreakpointRulerAction.ToggleBreakpoint"); //$NON-NLS-1$ - fRemoveLabel= PHPDebugUiMessages.getString("PHPManageBreakpointRulerAction.ToggleBreakpoint"); //$NON-NLS-1$ + + public PHPManageBreakpointRulerAction(IVerticalRulerInfo ruler, + ITextEditor editor) { + fRuler = ruler; + fTextEditor = editor; + fMarkerType = IBreakpoint.BREAKPOINT_MARKER; + fAddLabel = PHPDebugUiMessages + .getString("PHPManageBreakpointRulerAction.ToggleBreakpoint"); //$NON-NLS-1$ + fRemoveLabel = PHPDebugUiMessages + .getString("PHPManageBreakpointRulerAction.ToggleBreakpoint"); //$NON-NLS-1$ } - - /** - * Returns the resource for which to create the marker, - * or null if there is no applicable resource. - * + + /** + * Returns the resource for which to create the marker, or null + * if there is no applicable resource. + * * @return the resource for which to create the marker or null */ protected IResource getResource() { - IEditorInput input= fTextEditor.getEditorInput(); - - IResource resource= (IResource) input.getAdapter(IFile.class); - + IEditorInput input = fTextEditor.getEditorInput(); + + IResource resource = (IResource) input.getAdapter(IFile.class); + if (resource == null) { - resource= (IResource) input.getAdapter(IResource.class); + resource = (IResource) input.getAdapter(IResource.class); } - + return resource; } - + /** * Checks whether a position includes the ruler's line of activity. - * - * @param position the position to be checked - * @param document the document the position refers to + * + * @param position + * the position to be checked + * @param document + * the document the position refers to * @return true if the line is included by the given position */ protected boolean includesRulerLine(Position position, IDocument document) { if (position != null) { try { - int markerLine= document.getLineOfOffset(position.getOffset()); - int line= fRuler.getLineOfLastMouseButtonActivity(); + int markerLine = document.getLineOfOffset(position.getOffset()); + int line = fRuler.getLineOfLastMouseButtonActivity(); if (line == markerLine) { return true; } } catch (BadLocationException x) { } } - + return false; } - + /** * Returns this action's vertical ruler info. - * + * * @return this action's vertical ruler */ protected IVerticalRulerInfo getVerticalRulerInfo() { return fRuler; } - + /** * Returns this action's editor. - * + * * @return this action's editor */ protected ITextEditor getTextEditor() { return fTextEditor; } - + /** - * Returns the AbstractMarkerAnnotationModel of the editor's input. - * + * Returns the AbstractMarkerAnnotationModel of the editor's + * input. + * * @return the marker annotation model */ protected AbstractMarkerAnnotationModel getAnnotationModel() { - IDocumentProvider provider= fTextEditor.getDocumentProvider(); - IAnnotationModel model= provider.getAnnotationModel(fTextEditor.getEditorInput()); + IDocumentProvider provider = fTextEditor.getDocumentProvider(); + IAnnotationModel model = provider.getAnnotationModel(fTextEditor + .getEditorInput()); if (model instanceof AbstractMarkerAnnotationModel) { return (AbstractMarkerAnnotationModel) model; } @@ -136,19 +147,19 @@ public class PHPManageBreakpointRulerAction extends Action implements IUpdate { /** * Returns the IDocument of the editor's input. - * + * * @return the document of the editor's input */ protected IDocument getDocument() { - IDocumentProvider provider= fTextEditor.getDocumentProvider(); + IDocumentProvider provider = fTextEditor.getDocumentProvider(); return provider.getDocument(fTextEditor.getEditorInput()); } - + /** * @see IUpdate#update() */ public void update() { - fMarkers= getMarkers(); + fMarkers = getMarkers(); setText(fMarkers.isEmpty() ? fAddLabel : fRemoveLabel); } @@ -162,70 +173,85 @@ public class PHPManageBreakpointRulerAction extends Action implements IUpdate { removeMarkers(fMarkers); } } - + protected List getMarkers() { - List breakpoints= new ArrayList(); - - IResource resource= getResource(); - IDocument document= getDocument(); - AbstractMarkerAnnotationModel model= getAnnotationModel(); - + List breakpoints = new ArrayList(); + + IResource resource = getResource(); + IDocument document = getDocument(); + AbstractMarkerAnnotationModel model = getAnnotationModel(); + if (model != null) { try { - - IMarker[] markers= null; + + IMarker[] markers = null; if (resource instanceof IFile) - markers= resource.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE); + markers = resource.findMarkers( + IBreakpoint.BREAKPOINT_MARKER, true, + IResource.DEPTH_INFINITE); else { - IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); - markers= root.findMarkers(IBreakpoint.BREAKPOINT_MARKER, true, IResource.DEPTH_INFINITE); + IWorkspaceRoot root = ResourcesPlugin.getWorkspace() + .getRoot(); + markers = root.findMarkers(IBreakpoint.BREAKPOINT_MARKER, + true, IResource.DEPTH_INFINITE); } - + if (markers != null) { - IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager(); - int iFe =0; - for (iFe= 0; iFe < markers.length; iFe++) { - IBreakpoint breakpoint= breakpointManager.getBreakpoint(markers[iFe]); - if (breakpoint != null && breakpointManager.isRegistered(breakpoint) && - includesRulerLine(model.getMarkerPosition(markers[iFe]), document)) + IBreakpointManager breakpointManager = DebugPlugin + .getDefault().getBreakpointManager(); + int iFe = 0; + for (iFe = 0; iFe < markers.length; iFe++) { + IBreakpoint breakpoint = breakpointManager + .getBreakpoint(markers[iFe]); + if (breakpoint != null + && breakpointManager.isRegistered(breakpoint) + && includesRulerLine(model + .getMarkerPosition(markers[iFe]), + document)) breakpoints.add(markers[iFe]); } } } catch (CoreException x) { System.out.println(x.getStatus()); -// JDIDebugUIPlugin.log(x.getStatus()); + // JDIDebugUIPlugin.log(x.getStatus()); } } return breakpoints; } - + protected void addMarker() { - //IResource resource= getResource(); - IEditorInput editorInput= getTextEditor().getEditorInput(); - IDocument document= getDocument(); - //IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager(); + // IResource resource= getResource(); + IEditorInput editorInput = getTextEditor().getEditorInput(); + IDocument document = getDocument(); + // IBreakpointManager breakpointManager= + // DebugPlugin.getDefault().getBreakpointManager(); - int rulerLine= getVerticalRulerInfo().getLineOfLastMouseButtonActivity(); + int rulerLine = getVerticalRulerInfo() + .getLineOfLastMouseButtonActivity(); // create the marker try { - // Falta verificar si la ubicación del Breakpoint es válida - int lineNumber= rulerLine + 1; + // Falta verificar si la ubicaci�n del Breakpoint es v�lida + int lineNumber = rulerLine + 1; if (lineNumber > 0) { - if (PHPDebugModel.lineBreakpointExists(lineNumber)==null) { -// Map attributes = new HashMap(10); - IRegion line= document.getLineInformation(lineNumber - 1); - int start= line.getOffset(); - int lenline= line.getLength(); - //int end= start + ((lenline > 0)?lenline:0); - int end= start + lenline; - - //PHPDebugModel.createLineBreakpoint(getResource(), lineNumber, start, end, 0, true, attributes); - PHPDebugModel.createLineBreakpoint(((IFileEditorInput) editorInput).getFile(), lineNumber, start, end, 0, true, null); -// PHPDebugModel.createLineBreakpoint(((IFileEditorInput) editorInput).getFile(), lineNumber, 0, true, attributes); - + if (PHPDebugModel.lineBreakpointExists(lineNumber) == null) { + // Map attributes = new HashMap(10); + IRegion line = document.getLineInformation(lineNumber - 1); + int start = line.getOffset(); + int lenline = line.getLength(); + // int end= start + ((lenline > 0)?lenline:0); + int end = start + lenline; + + // PHPDebugModel.createLineBreakpoint(getResource(), + // lineNumber, start, end, 0, true, attributes); + PHPDebugModel.createLineBreakpoint( + ((IFileEditorInput) editorInput).getFile(), + lineNumber, start, end, 0, true, null); + // PHPDebugModel.createLineBreakpoint(((IFileEditorInput) + // editorInput).getFile(), lineNumber, 0, true, attributes); + } } } catch (DebugException e) { @@ -236,13 +262,15 @@ public class PHPManageBreakpointRulerAction extends Action implements IUpdate { System.out.println("Error"); } } - + protected void removeMarkers(List markers) { - IBreakpointManager breakpointManager= DebugPlugin.getDefault().getBreakpointManager(); + IBreakpointManager breakpointManager = DebugPlugin.getDefault() + .getBreakpointManager(); try { - Iterator e= markers.iterator(); + Iterator e = markers.iterator(); while (e.hasNext()) { - IBreakpoint breakpoint= breakpointManager.getBreakpoint((IMarker) e.next()); + IBreakpoint breakpoint = breakpointManager + .getBreakpoint((IMarker) e.next()); breakpointManager.removeBreakpoint(breakpoint, true); } } catch (CoreException e) { @@ -250,7 +278,7 @@ public class PHPManageBreakpointRulerAction extends Action implements IUpdate { } public IResource getUnderlyingResource(String fName) { - IResource parentResource = getResource(); //fParent.getUnderlyingResource(); + IResource parentResource = getResource(); // fParent.getUnderlyingResource(); if (parentResource == null) { return null; } @@ -259,7 +287,7 @@ public class PHPManageBreakpointRulerAction extends Action implements IUpdate { IContainer folder = (IContainer) parentResource; IResource resource = folder.findMember(fName); if (resource == null) { - //throw newNotPresentException(); + // throw newNotPresentException(); return null; } else { return resource;