A little Levure-oriented question

Trevor DeVore lists at mangomultimedia.com
Wed Feb 21 15:01:53 EST 2018


On Wed, Feb 21, 2018 at 12:58 PM, Graham Samuel via use-livecode <
use-livecode at lists.runrev.com> wrote:

> But if there’s no code in the UI stack, how do the handlers in the SOS
> know what object has invoked them? I mean of course you can work out the
> caller, but it’s much easier to say
>
> on mouseUp
> doSomethingJustForMe(myCoordinates
> end mouseUp
>
> than working it all out later, isn’t it?
>
> Doubtless this is a dumb question, but I told you I was confused.
>

Not dumb at all. You are right that attaching the mouseUp handler to the
object that receives the mouse click is easier. Where you are mistaken is
in your belief that the UI stack does contain code and the logic is not
handled in a library. The UI stack does in fact have code, it just happens
to be in behaviors that are script only stacks. Let me provide an example
of an About window which would be organized in the following file system
structure in Levure:

app/
  ui/
    about/
      about.livecode
      behaviors/
        card.livecodescript

Now assume that the about.livecode stack file has a field that shows the
version information and a button named “Acknowledgements” that opens a PDF
when you click on it.

The card.livecodescript is a SOS that is assigned to the behavior property
of card 1 in the about.livecode stack file. Any code in that
card.livecodescript SOS acts as if it is the actual code assigned to the
script property of card 1. The code just happens to live outside of
about.livecode.

So card.livecodescript can contain our primary handlers that do all of the
work:

```
on preOpenCard
  ShowVersion
end preOpenCard


command ShowVersion
  # Display current version in field
  …
end ShowVersion


command uiShowAcknowledgements
  # Launch PDF
  …
end uiShowAcknowledgements
```

The “Acknowledgements” button can now call the `uiShowAcknowledgements`
handler in the card script (which is really the card.livecodescript SOS
that is assigned to the behavior of the card).

```
on mouseUp
  uiShowAcknowledgements
end mouseUp
```

In the example above, the code in the button is actually assigned to the
script property of the “Acknowledgements” button and is part of the
about.livecode stack file. Not in some behavior. The code for the card
script is stored in a SOS that is assigned to the behavior property of the
card. This code lives outside of about.livecode stack file.

Now, you could move the “Acknowledgements” button code into a SOS as well.
In that case you would create a new SOS, move the script in the button to
the SOS, and then assign the SOS to the behavior property of the button.
Here is what the new file structure would look like:

app/
  ui/
    about/
      about.livecode
      behaviors/
        card.livecodescript
        acknowledgement_button.livecodescript

You wouldn’t have to change the `on mouseUp` code at all because behavior
scripts act as if they are the actual script of the control they are
assigned to.

Hopefully that clarifies things a little bit.

-- 
Trevor DeVore
ScreenSteps
www.screensteps.com



More information about the use-livecode mailing list