[squeak-dev] Re: Undoable environment ?

Bert Freudenberg bert at freudenbergs.de
Wed Apr 30 14:42:09 UTC 2008


On 30.04.2008, at 16:22, itsme213 wrote:

> "Gary Chambers" <gazzaguru2 at btinternet.com> wrote in message
>
>>> A>>setFoo: aFoo
>>>    Undoable newOn: [ foo := aFoo ]
>
>> Have a look at the Command and CommandHistory clasees. Worked well  
>> for our
>> Report Builder...
>
> I am hoping to find a way for Undoable to dynamically extend a few
> primitives (e.g. assiging to an instVar or indexedVar, probably  
> adding or
> removing indexedVars, others??).
>
> ========== e.g. currently:
>
> Object>> instVarAt: anInteger put: anObject
> <primitive: 74>
> ^self basicAt: anInteger - self class instSize put: anObject
>
> ========== Dynamically change to:
>
> Object>> instVarAt: anInteger put: anObject
>  self recordIVarChange: anInteger oldVal: self instVarAt: anInteger.
>  self primInstVarAt: anInteger put: anObject
>
> Object>> primInstVarAt: anInteger put: anObject
> <primitive: 74>
> ^self basicAt: anInteger - self class instSize put: anObject
>
> ===========
> Then #recordIVarChange can put undoable/redoable records on the stack.
>
> Does this sound feasible? Scary to dynamically re-define primitive  
> methods,
> don't know where to start :-(


This will not work. #instVarAt:put: is not called for regular inst var  
assignments.

Besides, you certainly only want to do that for your domain objects.  
One way to achieve that is to extend the compiler for your class  
hierarchy and make it insert the #recordIVarChange:oldVal:instVarAt:  
send right before or after the assignment bytecode.

This is how Tweak objects work - it has "fields" that can be used  
exactly like instance variables in code, but actually generate change  
events when assigned. It compiles any inst var assignment (and usage)  
as message send of an accessor named like the variable. The setter  
then generates the change events. The getter can be used to implement  
"virtual fields" with a computed value.

- Bert -





More information about the Squeak-dev mailing list