Browse files

editor ruler option to toggle breakpoints

  • Loading branch information...
1 parent db1d61e commit f79dd99ca7d69bf6ecebcf7a5123beba596e3bbf @JPMoresmau committed Jan 19, 2010
View
2 ...src/net/sf/eclipsefp/haskell/debug/ui/internal/debug/HaskellBreakpointAdapterFactory.java
@@ -24,7 +24,7 @@ public Object getAdapter( final Object adaptableObject, final Class adapterType
return null;
}
- public Class[] getAdapterList() {
+ public Class<?>[] getAdapterList() {
return new Class[]{IToggleBreakpointsTarget.class};
}
View
21 ...va/src/net/sf/eclipsefp/haskell/debug/ui/internal/debug/HaskellLineBreakpointAdapter.java
@@ -3,6 +3,7 @@
import net.sf.eclipsefp.haskell.core.util.ResourceUtil;
import net.sf.eclipsefp.haskell.debug.core.internal.HaskellDebugCore;
import net.sf.eclipsefp.haskell.debug.core.internal.debug.HaskellBreakpoint;
+import net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.core.DebugPlugin;
@@ -29,7 +30,7 @@
* @return the editor being used to edit a PDA file, associated with the
* given part, or <code>null</code> if none
*/
- private ITextEditor getEditor(final IWorkbenchPart part) {
+ public static ITextEditor getEditor(final IWorkbenchPart part) {
if (part instanceof ITextEditor) {
ITextEditor editorPart = (ITextEditor) part;
IResource resource = (IResource) editorPart.getEditorInput().getAdapter(IResource.class);
@@ -42,12 +43,17 @@ private ITextEditor getEditor(final IWorkbenchPart part) {
public boolean canToggleLineBreakpoints( final IWorkbenchPart part,
final ISelection selection ) {
- return getEditor(part) != null;
+ if (getEditor(part) != null){
+ if (part instanceof HaskellEditor){
+ return ((HaskellEditor)part).isInOutline(selection);
+ }
+ return true;
+ }
+ return false;
}
public boolean canToggleMethodBreakpoints( final IWorkbenchPart part,
final ISelection selection ) {
- // TODO Auto-generated method stub
return false;
}
@@ -81,14 +87,13 @@ public void toggleLineBreakpoints( final IWorkbenchPart part, final ISelection s
}
public void toggleMethodBreakpoints( final IWorkbenchPart part, final ISelection selection )
- throws CoreException {
- // TODO Auto-generated method stub
-
+ {
+ // NOOP
}
public void toggleWatchpoints( final IWorkbenchPart part, final ISelection selection )
- throws CoreException {
- // TODO Auto-generated method stub
+ {
+ // NOOP
}
View
57 ...et/sf/eclipsefp/haskell/debug/ui/internal/debug/HaskellToggleBreakpointTargetFactory.java
@@ -0,0 +1,57 @@
+package net.sf.eclipsefp.haskell.debug.ui.internal.debug;
+
+import java.util.HashSet;
+import java.util.Set;
+import net.sf.eclipsefp.haskell.debug.core.internal.HaskellDebugCore;
+import net.sf.eclipsefp.haskell.debug.ui.internal.util.UITexts;
+import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
+import org.eclipse.debug.ui.actions.IToggleBreakpointsTargetFactory;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IWorkbenchPart;
+
+/**
+ * Not sure this is really needed in anything
+ * @author JP Moresmau
+ *
+ */
+public class HaskellToggleBreakpointTargetFactory implements
+ IToggleBreakpointsTargetFactory {
+
+ public IToggleBreakpointsTarget createToggleTarget( final String targetID ) {
+ if (HaskellDebugCore.ID_HASKELL_DEBUG_MODEL.equals( targetID )){
+ return new HaskellLineBreakpointAdapter();
+ }
+ return null;
+ }
+
+ public String getDefaultToggleTarget( final IWorkbenchPart part,
+ final ISelection selection ) {
+ if (HaskellLineBreakpointAdapter.getEditor( part )!=null){
+ return HaskellDebugCore.ID_HASKELL_DEBUG_MODEL;
+ }
+ return null;
+ }
+
+ public String getToggleTargetDescription( final String targetID ) {
+ if (HaskellDebugCore.ID_HASKELL_DEBUG_MODEL.equals( targetID )){
+ return UITexts.breakpoint_toggle_description;
+ }
+ return null;
+ }
+
+ public String getToggleTargetName( final String targetID ) {
+ if (HaskellDebugCore.ID_HASKELL_DEBUG_MODEL.equals( targetID )){
+ return UITexts.breakpoint_toggle;
+ }
+ return null;
+ }
+
+ public Set<String> getToggleTargets( final IWorkbenchPart part, final ISelection selection ) {
+ Set<String> ret=new HashSet<String>();
+ if (HaskellLineBreakpointAdapter.getEditor( part )!=null){
+ ret.add(HaskellDebugCore.ID_HASKELL_DEBUG_MODEL);
+ }
+ return ret;
+ }
+
+}
View
3 ...l.debug.ui/INTERNAL/java/src/net/sf/eclipsefp/haskell/debug/ui/internal/util/UITexts.java
@@ -42,6 +42,9 @@
public static String debug_editor_title;
public static String debug_editor_text;
+ public static String breakpoint_toggle;
+ public static String breakpoint_toggle_description;
+
private static final String BUNDLE_NAME
= UITexts.class.getPackage().getName() + ".uitexts"; //$NON-NLS-1$
View
3 ...g.ui/INTERNAL/java/src/net/sf/eclipsefp/haskell/debug/ui/internal/util/uitexts.properties
@@ -32,3 +32,6 @@ configuration_name={0} ({1} {2})
debug_editor_title=Force variable evaluation
debug_editor_text=Haskell variables cannot have values assigned to them. But by clicking OK you can force evaluation of the variable. Be aware that forcing evaluation of a variable instead of leaving Haskell lazy evaluation system decide when to do it can change the behavior of your code.
+
+breakpoint_toggle=Toggle breakpoint
+breakpoint_toggle_description=Toggle line breakpoint
View
4 net.sf.eclipsefp.haskell.debug.ui/plugin.properties
@@ -18,4 +18,6 @@ runGHCiShortcut_desc = Starts an interactive GHC session, loading this file and
adding the project source folders to GHCi's search path.
runHaskellShortcut_name = Run Haskell program
-runHaskellShortcut_desc = Executes the built executable from this project.
+runHaskellShortcut_desc = Executes the built executable from this project.
+
+toggle_breakpoint=Toggle Breakpoint
View
44 net.sf.eclipsefp.haskell.debug.ui/plugin.xml
@@ -120,4 +120,48 @@
modelId="net.sf.eclipsefp.haskell.debug">
</variableValueEditor>
</extension>
+ <extension
+ point="org.eclipse.debug.ui.toggleBreakpointsTargetFactories">
+ <toggleTargetFactory
+ class="net.sf.eclipsefp.haskell.debug.ui.internal.debug.HaskellToggleBreakpointTargetFactory"
+ id="net.sf.eclipsefp.haskell.debug.ui.internal.debug.HaskellToggleBreakpointTargetFactory">
+ <enablement>
+ <with variable="debugContext">
+ <iterate>
+ <or>
+ <test property="org.eclipse.debug.ui.getModelIdentifier" value="net.sf.eclipsefp.haskell.debug"/>
+ <test property="org.eclipse.debug.ui.getModelIdentifier" value=""/>
+ </or>
+ </iterate>
+ </with>
+ <instanceof value="net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor"/>
+ </enablement>
+ </toggleTargetFactory>
+ </extension>
+ <extension point="org.eclipse.ui.popupMenus">
+ <viewerContribution id="net.sf.eclipsefp.haskell.debug.ui.RulerPopupActions"
+ targetID="#TextRulerContext">
+
+ <action
+ id="net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor.toggleBreakpointAction" label="%toggle_breakpoint"
+ class="org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate"
+ menubarPath="debug">
+ </action>
+ </viewerContribution>
+ </extension>
+ <extension
+ point="org.eclipse.ui.editorActions">
+ <editorContribution
+ id="net.sf.eclipsefp.haskell.debug.ui.editorContribution1"
+ targetID="net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor">
+ <action
+ label="%toggle_breakpoint"
+ class="org.eclipse.debug.ui.actions.RulerToggleBreakpointActionDelegate"
+ style="push"
+ actionID="RulerDoubleClick"
+ id="net.sf.eclipsefp.haskell.ui.internal.editors.haskell.HaskellEditor.doubleClickBreakpointAction"/>
+ </editorContribution>
+ </extension>
+
+
</plugin>
View
2 net.sf.eclipsefp.haskell.ui/META-INF/MANIFEST.MF
@@ -31,7 +31,7 @@ Export-Package: net.sf.eclipsefp.common.ui.dialog,
net.sf.eclipsefp.haskell.ui;x-friends:="net.sf.eclipsefp.haskell.ui.test,net.sf.eclipsefp.haskell.debug.ui,net.sf.eclipsefp.haskell.debug.core",
net.sf.eclipsefp.haskell.ui.console;x-friends:="net.sf.eclipsefp.haskell.ui.test",
net.sf.eclipsefp.haskell.ui.dialog,
- net.sf.eclipsefp.haskell.ui.internal.editors.haskell;x-friends:="net.sf.eclipsefp.haskell.ui.test",
+ net.sf.eclipsefp.haskell.ui.internal.editors.haskell;x-friends:="net.sf.eclipsefp.haskell.ui.test,net.sf.eclipsefp.haskell.debug.ui",
net.sf.eclipsefp.haskell.ui.internal.editors.haskell.actions;x-friends:="net.sf.eclipsefp.haskell.ui.test",
net.sf.eclipsefp.haskell.ui.internal.editors.haskell.codeassist;x-friends:="net.sf.eclipsefp.haskell.ui.test",
net.sf.eclipsefp.haskell.ui.internal.editors.haskell.syntax;x-friends:="net.sf.eclipsefp.haskell.ui.test",
View
21 ...fp.haskell.ui/src/net/sf/eclipsefp/haskell/ui/internal/editors/haskell/HaskellEditor.java
@@ -38,6 +38,7 @@
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextOperationTarget;
+import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.Position;
import org.eclipse.jface.text.source.Annotation;
import org.eclipse.jface.text.source.ISourceViewer;
@@ -46,6 +47,7 @@
import org.eclipse.jface.text.source.projection.ProjectionSupport;
import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.widgets.Composite;
@@ -494,4 +496,23 @@ private void buildDefByName(){
}
}
}
+
+ /**
+ * is the start of the selection contained in an outline element
+ * useful to find if a selection for a breakpoint is in real code
+ */
+ public boolean isInOutline(final ISelection sel){
+ if (outline!=null && sel instanceof ITextSelection){
+ ITextSelection tsel=(ITextSelection)sel;
+ int line=tsel.getStartLine()+1;
+ for (OutlineDef od:outline){
+ // here we could filter out if inside some type of outlinedef we do not want breakpoints
+
+ if (od.getBlock().getStartLine()<=line && od.getBlock().getEndLine()>=line){
+ return true;
+ }
+ }
+ }
+ return false;
+ }
}

0 comments on commit f79dd99

Please sign in to comment.