Dynamic descriptions

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

Dynamic descriptions

Jason Johnson-5
Hi all,

I'm using Magritte to model some objects of mine and basically if the
user edits the object I want the description to be the same, just the
"unique key" to become read only.  If they add then of course all
fields are modify-able.

I have done this by overriding #description on instance side to do
something like:

MyObject>>description
   |result|

  result :=  self class description.

  ^ someField
      ifNil: [ result ]          "new instance"
      ifNotNil: [
        result collect: [e|
            e label = 'Name Im interested in'
                ifTrue: [ e beReadonly; yourself ]
                ifFalse: [ e ] ] ]

Now of course what happens is, if I click edit first then the fields
are always read only and vice versa if I click new first, due to
caching.  That is, it works perfectly.... the first use, and from then
on #description is called.  Before I fought with this anymore I
thought I would check if there is a simpler way to do what I'm trying
to do.

Thanks in advance,
Jason

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic descriptions

Lukas Renggli-2
> Now of course what happens is, if I click edit first then the fields
> are always read only and vice versa if I click new first, due to
> caching.  That is, it works perfectly.... the first use, and from then
> on #description is called.  Before I fought with this anymore I
> thought I would check if there is a simpler way to do what I'm trying
> to do.

No, that's the usual way to do.

Since the description are cached, you have to make a copy before  
changing it:

         e copy beReadonly; yourself

Cheers,
Lukas

--
Lukas Renggli
http://www.lukas-renggli.ch


_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki
Reply | Threaded
Open this post in threaded view
|

Re: Dynamic descriptions

Jason Johnson-5
Ah, nice.  I should have thought of that. :)  Thanks for your help.

On Nov 19, 2007 10:24 PM, Lukas Renggli <[hidden email]> wrote:

> > Now of course what happens is, if I click edit first then the fields
> > are always read only and vice versa if I click new first, due to
> > caching.  That is, it works perfectly.... the first use, and from then
> > on #description is called.  Before I fought with this anymore I
> > thought I would check if there is a simpler way to do what I'm trying
> > to do.
>
> No, that's the usual way to do.
>
> Since the description are cached, you have to make a copy before
> changing it:
>
>          e copy beReadonly; yourself
>
> Cheers,
> Lukas
>
> --
> Lukas Renggli
> http://www.lukas-renggli.ch
>
>
> _______________________________________________
> SmallWiki, Magritte, Pier and Related Tools ...
> https://www.iam.unibe.ch/mailman/listinfo/smallwiki
>

_______________________________________________
SmallWiki, Magritte, Pier and Related Tools ...
https://www.iam.unibe.ch/mailman/listinfo/smallwiki