Login  Register

onAnswerCommand and structure change

Posted by NorbertHartl on Oct 22, 2010; 11:57am
URL: https://forum.world.st/onAnswerCommand-and-structure-change-tp3007074.html

I like to execute a command in a way that the structure is changed while the command is being executed. If the command is commited I like to advance the structure to another structure. If the command is aborted than I like to return to the structure from where the command has been invoked.

Basically I do something like this

        html anchor
                goto: (self context
                                structure: self structureWhileCommandIsExecuting
                                command: MyPierCommand new);
                with: 'do it' ]

In MyPierCommand>>doExecute I do at the end

self answer: (self context structure: self structureAfterCommandHasBeingCommited )

This way I have chose a structure for command execution and the structure if the command is commited. But on abort it stays where it has been executed (structureWhileCommandIsExecuting). Looking at

PRContentsWidget>>onAnswerCommand: aCommand
        aCommand isNil
                ifTrue: [ ^ self context: (self context structure: self context structure) ].
        [ aCommand execute ]
                on: MAError
                do: [ :err | ^ self component errors add: err ].
        self context: aCommand answer

we see that if aCommand isNil (abort) the structure is nailed to the current one (while executing). Would it be ok to change that so it is answering every time? I simple change would be to change

buildComponent: aContext
        ^ aContext command asComponent
                onAnswer: [ :value | self onAnswerCommand: value ];
                yourself

to

buildComponent: aContext
        ^ aContext command asComponent
                onAnswer: [ :value | value ifNotNil: [ self onAnswerCommand: value ] ifNil: [ aContext command doAnswer ] ];
                yourself

this way

PRCommand>>doAnswer
        self answer ifNil: [ self answer: (self context structure: self structure) ]

would the same but some could overwrite the answer when creating the link

what do you think?

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