1 /**********************************************************************
2 Copyright (c) 2000, 2002 IBM Corp. and others.
3 All rights reserved. This program and the accompanying materials
4 are made available under the terms of the Common Public License v1.0
5 which accompanies this distribution, and is available at
6 http://www.eclipse.org/legal/cpl-v10.html
9 IBM Corporation - Initial implementation
10 Vicente Fernando - www.alfersoft.com.ar
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.xdebug.ui.actions;
14 import net.sourceforge.phpeclipse.xdebug.ui.XDebugUIPlugin;
15 import net.sourceforge.phpeclipse.xdebug.ui.php.model.PHPLineBreakpointAdapter;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.debug.core.DebugPlugin;
19 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.IRegion;
23 import org.eclipse.jface.text.TextSelection;
24 import org.eclipse.jface.text.source.IVerticalRulerInfo;
25 import org.eclipse.jface.viewers.ISelection;
26 import org.eclipse.ui.IWorkbenchPart;
27 import org.eclipse.ui.texteditor.IDocumentProvider;
28 import org.eclipse.ui.texteditor.ITextEditor;
30 public class ToggleBreakpointRulerAction extends Action {
32 static class EmptySelection implements ISelection {
34 public boolean isEmpty() {
39 private IVerticalRulerInfo fRuler;
40 private IWorkbenchPart fTargetPart;
41 private PHPLineBreakpointAdapter fBreakpointAdapter;
42 private static final ISelection EMPTY_SELECTION = new EmptySelection();
44 public ToggleBreakpointRulerAction( IWorkbenchPart part, IVerticalRulerInfo ruler ) {
45 super( "Toggle Breakpoint" ); //$NON-NLS-1$
49 setTargetPart( part );
50 fBreakpointAdapter = new PHPLineBreakpointAdapter();
51 // part.getSite().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp( this, ICDebugHelpContextIds.TOGGLE_BREAKPOINT_ACTION );
52 // setId( IInternalCDebugUIConstants.ACTION_TOGGLE_BREAKPOINT );
61 fBreakpointAdapter.toggleLineBreakpoints( getTargetPart(), getTargetSelection() );
63 catch( CoreException e ) {
64 XDebugUIPlugin.errorDialog( getTargetPart().getSite().getShell(),"Error", "Operation failed" , e.getStatus() );
69 * Returns this action's vertical ruler info.
71 * @return this action's vertical ruler
73 protected IVerticalRulerInfo getVerticalRulerInfo() {
77 private IWorkbenchPart getTargetPart() {
78 return this.fTargetPart;
81 private void setTargetPart( IWorkbenchPart targetPart ) {
82 this.fTargetPart = targetPart;
86 * Returns the current selection in the active part, possibly
87 * and empty selection, but never <code>null</code>.
89 * @return the selection in the active part, possibly empty
91 private ISelection getTargetSelection() {
92 IDocument doc = getDocument();
94 int line = getVerticalRulerInfo().getLineOfLastMouseButtonActivity();
96 IRegion region = doc.getLineInformation( line );
97 return new TextSelection( doc, region.getOffset(), region.getLength() );
99 catch( BadLocationException e ) {
100 DebugPlugin.log( e );
103 return EMPTY_SELECTION;
106 private IDocument getDocument() {
107 IWorkbenchPart targetPart = getTargetPart();
108 if ( targetPart instanceof ITextEditor ) {
109 ITextEditor textEditor = (ITextEditor)targetPart;
110 IDocumentProvider provider = textEditor.getDocumentProvider();
111 if ( provider != null )
112 return provider.getDocument( textEditor.getEditorInput() );
114 // else if ( targetPart instanceof DisassemblyView ) {
115 // DisassemblyView dv = (DisassemblyView)targetPart;
116 // IDocumentProvider provider = dv.getDocumentProvider();
117 // if ( provider != null )
118 // return provider.getDocument( dv.getInput() );