Bloc consideration - TextActions

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Bloc consideration - TextActions

Ben Coman
This is may not be worth investigating much in Morphic, but tips are welcome. 
Mainly this is a use case for consideration with the TextAction equivalent in Bloc.

For the #text: of a TextEntryDialogWindow
I wanted clickable link similar to the bottom of ```WelcomeHelp open```
which would open a link in a web browser using https://github.com/seandenigris/Pharo-Web-Browser.

Experimenting in Playground, this[1] looked promising...
```
linkText := 'https://exercism.io/my/settings' asText
addAttribute: (TextAction new actOnClickBlock: [
self inform: 'STUB: Invoke web browser here']);
      addAttribute: (TextColor new color: Color cyan).
requestText := 'Enter your Exercism token (from ' asText, linkText, '):'.
requestText inspect.
```
where clicking on the link displays the information message.

But this[2] didn't work... 
```UIManager default request: requestText```
or to be more explicit, diving in a few calls down and simplifying, neither did this...
```(TextEntryDialogWindow new text: requestText) openInWorld```

I tracked it down to [2] having a locked TextMorph for requestText. 
(observed using the following instrumentation...)
    TextMorph isLocked
    (text asString includesSubstring: 'Enter your Exercism token')
    ifTrue: [ Transcript show: (super isLocked ifTrue: 'x' ifFalse:'.')].
    ^ super isLocked 
and confirmed with this experiment... 
```
tm1 := TextMorph new newContents: requestText.
tm2 := tm1 copy lock.

tm1 openInWorld.
"Test clicking the text - action is invoked"
tm1 delete.

tm2 openInWorld.
"Test clicking the text - action not invoked"
tm2 delete.
```

This is due to #isLocked call here...:
```
Morph>>rejectsEvent: anEvent
"Return true to reject the given event.
Rejecting an event means neither the receiver nor any of it's submorphs will be given any chance to handle it.
If the event is a mouse wheel event then only reject if the receiver is not visible."
(anEvent isMouse and: [anEvent isMouseWheel])
ifTrue: [^self visible not].
^self isLocked or: [self visible not]
```

Now the functional paradox here is that:
* an unlocked TextMorph is editable, which you don't want for a static UI label;
* but a locked TextMorph doesn't pass events through to trigger the TextAction.
Thus it you can't have a clickable link in a static UI label.
Yet that is almost an essential feature in today's "linked" world
and I hope Bloc will provide a facility for actions within static/locked text.

cheers -ben

P.S. Any tips on getting this to work in Pharo 6.1 would be appreciated.
 
Reply | Threaded
Open this post in threaded view
|

Re: Bloc consideration - TextActions

Ben Coman
On Fri, 7 Sep 2018 at 14:52, Ben Coman <[hidden email]> wrote:
This is may not be worth investigating much in Morphic, but tips are welcome. 
Mainly this is a use case for consideration with the TextAction equivalent in Bloc.

For the #text: of a TextEntryDialogWindow
I wanted clickable link similar to the bottom of ```WelcomeHelp open```
which would open a link in a web browser using https://github.com/seandenigris/Pharo-Web-Browser.

Experimenting in Playground, this[1] looked promising...
```
linkText := 'https://exercism.io/my/settings' asText
addAttribute: (TextAction new actOnClickBlock: [
self inform: 'STUB: Invoke web browser here']);
      addAttribute: (TextColor new color: Color cyan).
requestText := 'Enter your Exercism token (from ' asText, linkText, '):'.
requestText inspect.
```
where clicking on the link displays the information message.

But this[2] didn't work... 
```UIManager default request: requestText```
or to be more explicit, diving in a few calls down and simplifying, neither did this...
```(TextEntryDialogWindow new text: requestText) openInWorld```

I tracked it down to [2] having a locked TextMorph for requestText. 
(observed using the following instrumentation...)
    TextMorph isLocked
    (text asString includesSubstring: 'Enter your Exercism token')
    ifTrue: [ Transcript show: (super isLocked ifTrue: 'x' ifFalse:'.')].
    ^ super isLocked 
and confirmed with this experiment... 
```
tm1 := TextMorph new newContents: requestText.
tm2 := tm1 copy lock.

tm1 openInWorld.
"Test clicking the text - action is invoked"
tm1 delete.

tm2 openInWorld.
"Test clicking the text - action not invoked"
tm2 delete.
```

This is due to #isLocked call here...:
```
Morph>>rejectsEvent: anEvent
"Return true to reject the given event.
Rejecting an event means neither the receiver nor any of it's submorphs will be given any chance to handle it.
If the event is a mouse wheel event then only reject if the receiver is not visible."
(anEvent isMouse and: [anEvent isMouseWheel])
ifTrue: [^self visible not].
^self isLocked or: [self visible not]
```

Now the functional paradox here is that:
* an unlocked TextMorph is editable, which you don't want for a static UI label;
* but a locked TextMorph doesn't pass events through to trigger the TextAction.
Thus it you can't have a clickable link in a static UI label.
Yet that is almost an essential feature in today's "linked" world
and I hope Bloc will provide a facility for actions within static/locked text.

cheers -ben

P.S. Any tips on getting this to work in Pharo 6.1 would be appreciated.

Considering...
    TextMorph >> enabled
        ^super enabled and: [ self isLocked not ]

a reasonable workaround might be... 
    TextMorph subclass: #StaticTextMorph
        instanceVariableNames: ''
        classVariableNames: ''
        package: 'ExercismTools'

StaticTextMorph >> enabled
^false

then...
    stm1 := StaticTextMorph new newContents: requestText.
    stm1 openInWorld

allows the link to be clicked while preventing edits.

P.S. btw "TextMorph >> enabled:" seems suspect, since its visual only and doesn't prevent editing (if I guess correctly the expected functionality of enabled)