Tools__BreakpointService.st
changeset 10182 9ce79271722f
parent 10071 1bf516aac0b8
child 10208 5f0f44bd199a
--- a/Tools__BreakpointService.st	Tue Jul 05 23:27:33 2011 +0200
+++ b/Tools__BreakpointService.st	Tue Jul 05 23:27:49 2011 +0200
@@ -66,25 +66,24 @@
 
 !BreakpointService methodsFor:'event handling'!
 
-buttonPress: button x:x y:y in: view
-
-    codeView methodHolder value isNil ifTrue:[^false].
-
+buttonPress:button x:x y:y in:view 
+    codeView methodHolder value isNil ifTrue:[
+        ^ false
+    ].
     view == gutterView ifTrue:[
         button == 1 ifTrue:[
-            self setOrToggleBreakpointAtLine: (textView yVisibleToLineNr:y).
-            ^true.
+            self setOrToggleBreakpointAtLine:(textView yVisibleToLineNr:y).
+            ^ true.
         ].
         button == 3 ifTrue:[
-            
-            ^true.
+            ^ true.
         ]
-
     ].
-    ^false
+    ^ false
 
     "Created: / 17-06-2011 / 13:05:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Modified: / 28-06-2011 / 08:31:39 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 05-07-2011 / 21:33:29 / cg"
 ! !
 
 !BreakpointService methodsFor:'initialization'!
@@ -99,13 +98,48 @@
 
 !BreakpointService methodsFor:'private'!
 
-breakpointAtLine:line
+breakpointAtLine:line 
+    |pos|
 
-    | pos |    
     pos := textView characterPositionOfLine:line col:1.
     ^ breakpoints ? #() detect:[:each | each position = pos ] ifNone:[ nil ]
 
     "Modified: / 17-06-2011 / 13:59:17 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 05-07-2011 / 21:33:23 / cg"
+!
+
+recompile
+    "recompile the current method for changed breakpoints"
+
+    |method|
+
+    method := codeView methodHolder value.
+    (method notNil and:[method hasPrimitiveCode not]) ifTrue:[
+        "/ be careful: if the text has been edited/modified, do not compile
+        textView modified ifTrue:[
+            self halt
+        ] ifFalse:[
+            "/ prepare to get reachable bpts
+            breakpoints do:[:bp | bp isReached:false].
+
+            ByteCodeCompilerWithBreakpointSupport new
+                breakpoints:breakpoints;
+
+                compile:method source
+                forClass:method mclass 
+                inCategory:method category 
+                notifying:nil
+                install:true 
+                skipIfSame:false 
+                silent:true 
+                foldConstants:true
+                ifFail:[ self halt ].
+
+            breakpoints := breakpoints select:[:bp | bp isReached]
+        ]
+    ]
+
+    "Created: / 05-07-2011 / 21:33:13 / cg"
 !
 
 setOrToggleBreakpointAtLine:line 
@@ -113,51 +147,58 @@
 
     pos := textView characterPositionOfLine:line col:1.
     bpnt := self breakpointAtLine:line.
-    bpnt isNil 
-        ifTrue:
-            [ breakpoints add:((Breakpoint new)
-                        position:pos;
-                        line:line) ]
-        ifFalse:[ bpnt toggle. ].
+    bpnt isNil ifTrue:[
+        breakpoints add:((Breakpoint new)
+                    position:pos;
+                    line:line).
+        self recompile.
+    ] ifFalse:[
+        bpnt toggle.
+    ].
     gutterView redrawLine:line.
 
     "Created: / 17-06-2011 / 13:45:22 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-07-2011 / 21:32:49 / cg"
 ! !
 
 !BreakpointService methodsFor:'redrawing'!
 
-drawLine:lineNo in: view atX:x y:y width: w height:h from:startCol to:endColOrNil with:fg and:bg
-
+drawLine:lineNo in:view atX:x y:y width:w height:h from:startCol to:endColOrNil with:fg and:bg 
     "Called by both gutterView and textView (well, not yet) to
      allow services to draw custom things on text view.
      Ask JV what the args means if unsure (I'm lazy to document
      them, now it is just an experiment...)"
-
-    | bpnt icon dx dy |
-
-    codeView methodHolder value isNil ifTrue:[^self].
-
-    view == gutterView ifTrue:[
+    
+    |bpnt icon dx dy|
 
-    bpnt := self breakpointAtLine: lineNo.
-    bpnt isNil ifTrue:[^self].
-    icon := bpnt icon.
-    icon isNil ifTrue:[^self].
-
-    dx := ((w - icon width)  / 2) rounded.
-    dy := ((h - icon height) / 2) rounded.
-
-    icon displayOn: view x: x+dx y: y-h+dy+4"TODO: Magic constant".
-
+    codeView methodHolder value isNil ifTrue:[
+        ^ self
+    ].
+    view == gutterView ifTrue:[
+        bpnt := self breakpointAtLine:lineNo.
+        bpnt isNil ifTrue:[
+            ^ self
+        ].
+        icon := bpnt icon.
+        icon isNil ifTrue:[
+            ^ self
+        ].
+        dx := ((w - icon width) / 2) rounded.
+        dy := ((h - icon height) / 2) rounded.
+        icon 
+            displayOn:view
+            x:x + dx
+            y:y - h + dy + 4. "TODO: Magic constant"
     ].
 
     "Created: / 17-06-2011 / 13:52:52 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified (format): / 05-07-2011 / 22:14:33 / cg"
 ! !
 
 !BreakpointService class methodsFor:'documentation'!
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libtool/Tools__BreakpointService.st,v 1.2 2011-07-03 17:50:05 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Tools__BreakpointService.st,v 1.3 2011-07-05 21:27:49 cg Exp $'
 !
 
 version_SVN