Search code examples
smalltalksqueakgnu-smalltalk

How to remove an attachMorph of HandleMorph in smalltalk from self


i need your help i am creating a line from a spesific location to mouse location with this code. after click i am trying to remove this line but i have no idea how please help me remove the live after click what should i change ?

stk:=  (LineMorph from: 100@100 to: 1300@1300 color: Color red width: 2) openInWorld.
handle := HandleMorph new forEachPointDo:  [:newPoint | stk setVertices: {whiteBallinHole position. (newPoint-(10@10)). }.
stk on: #mouseDown send: #value: to:[:evt|
    evt redButtonPressed ifTrue:[  self handlesMouseDown:  evt.

"DELETE THE STICK AFTER MOUSE CLICK THIS DOSNT WORK PLEASE HELP"

stk color: Color transparent.
stk delete.

""

 ].
    ].
    ]. 
    " (self  currentHand attachMorph: handle)."
    " self currentHand addMorph:handle. "
    self currentHand attachMorph:handle. 

Solution

  • The code is a bit of a mess. One thing that is out of place is

    self handlesMouseDown: evt.
    

    That is supposed to return true if you want to receive mouseDown: messages. In a workspace, that self does not exist. And the result is never used. Just delete it. The resulting code would be something like

    whiteBallinHole := CircleMorph new openInWorld .
    stk := (LineMorph 
        from: 100@100 to: 1300@1300 
        color: Color red 
        width: 4) openInWorld.
    handle := HandleMorph new forEachPointDo: [ :newPoint | 
    stk setVertices: {whiteBallinHole center. (newPoint-(10@10)). }.
    stk on: #mouseDown send: #value: to: [:evt|
        evt redButtonPressed ifTrue:[
            stk color: Color transparent.
            stk delete]]].
    self currentHand attachMorph: handle.