tom95 / Pheno

A morphic-based UI framework with a lot of Bootstrap-like widgets.
MIT License
7 stars 2 forks source link

Infinite loop in PHPluggableMenuItem >> #contents #60

Closed LinqLover closed 4 years ago

LinqLover commented 4 years ago

Steps to reproduce

PHToolBuilder new build: PluggableMenuItemSpec new

Behavior

image Btw, you don't need super in the selected statement ...

LinqLover commented 4 years ago

This is the ugly way to fix it:

PHPluggableMenuItem >> contents: aString withMarkers: aBool inverse: inverse 
    "Set the menu item entry. If aBool is true, parse aString for embedded markers."

    | markerIndex marker |
    self contentString: nil.    "get rid of old"
    aBool ifFalse: [^super contents: aString].
    self removeAllMorphs.   "get rid of old markers if updating"
    self hasIcon ifTrue: [ self icon: nil ].
    (aString notEmpty and: [aString first = $<]) 
        ifFalse: [^self
            perform: #contents:
            withArguments: {aString}
            inSuperclass: StringMorph].
    markerIndex := aString indexOf: $>.
    markerIndex = 0 ifTrue: [^super contents: aString].
    marker := (aString copyFrom: 1 to: markerIndex) asLowercase.
    (#('<on>' '<off>' '<yes>' '<no>') includes: marker) 
        ifFalse: [^super contents: aString].
    self contentString: aString.    "remember actual string"
    marker := (marker = '<on>' or: [marker = '<yes>']) ~= inverse 
                ifTrue: [self onImage]
                ifFalse: [self offImage].
    super contents:  (aString copyFrom: markerIndex + 1 to: aString size).
    "And set the marker"
    marker := ImageMorph new image: marker.
    marker position: self left + self layoutInset left @ (self top + ((self height / 2) - (marker height / 2))).
    self addMorphFront: marker