Need help with ScrollPane and model...
Lex Spoon
lex at cc.gatech.edu
Wed Jun 13 06:05:16 UTC 2001
Stephane Ducasse <ducasse at iam.unibe.ch> wrote:
>
> The problem is that if later I changed the contents of the aTextMorph
> then I have to **explicitly** reset the scrollbar of the scrollPane.
>
> Is there any way using model and changed event to have this behavior
> automatically
>
Using PlugabbleTextMorph and the changed/update mechanism would seem to
make all this easier. Here's how to do it.
First, create a model object -- this technique doesn't really work from
raw workspace code. Suppose the model is an instance of
ReallyCoolStuff.
Second, add a method to ReallyCoolStuff that computes the string to be
displaed. For example, I'll copy your code:
reallyCoolAttributeDescription
| st |
st := ''.
Smalltalk classNames
do: [:each | st := st , each asString , ' '].
^st
Next, create and open the PluggableTextMorph:
> (PluggableTextMorph on: myReallyCoolStuff text: #reallyCoolAttributeDescription accept: nil) openInWorld
Finally, make sure that whenever your really cool stuff changes, that
you execute "self changed: #reallyCoolAttributeDescription" in order for
the PluggableTextMorph to get updated.
Here's a simple example of the whole process using arrays (I love this
example because arrays obviously don't have GUI code built in):
=============================
"create an array and open a text view of the first element"
myKewlArray := #('abc' 'def' 'ghi') copy.
(PluggableTextMorph on: myKewlArray text: #first accept: nil) openInWorld.
"modify the first element"
myKewlArray at: 1 put: 'blah blah'.
"cause the view(s) to actually update"
myKewlArray changed: #first.
=============================
This example is especially kewl if you execute the "openInWorld" line more
than once and thus create multiple views. Whenever you change
the array and send changed:, all the PluggableTextMorph's will update
in parallel.
-Lex
More information about the Squeak-dev
mailing list
|