Re: [@dxli and @sand1024] please a tip for the RS_Eventhandler
Posted by
dxli on
Apr 10, 2025; 6:50pm
URL: https://forum.librecad.org/fixed-thanks-please-a-tip-for-the-RS-Eventhandler-tp5726883p5726888.html
It reminds me the longer time design issues with eventhandler:
1. actions should be owned by eventhandler, but currently, actions are held by eventhandler as shared_ptr. Wondering whether it's better to use unique_ptr instead;
2. the setCurrentAction() api should all be in smart pointers.
sand1024 wrote
oh, now I see that you call finish(false); in trigger() method.
I"ll try to make some assumptions and guess - but in general - I don't think that the current implementation is correct way from the overall actions' lifecycle.
If the action is not a one-shoot one that should be finished right after the invocation - instead of calling the trigger() in init(), you need to define the set of states for the action and maintain the state via setStatus() method.
It might be that only one state is supported by the action, that's also ok.
Later, in event handlers (like onMouseMove etc.) - you'll do necessary processing according to the current state of the action.
By default - if you'd like to finish the action, you can call setStatus(-1) (any negative value for the state, actually). Usually right button click returns the action to the previous state until it finish.