[Cuis-dev] Debug action for buttons

Hernán Wilkinson hernan.wilkinson at 10pines.com
Tue Nov 14 03:17:44 PST 2023


This is such a great tool!!! it's really cool!
Thank you Facu!

Cheers!
Hernan.

On Mon, Nov 13, 2023 at 8:16 PM Facundo Javier Gelatti via Cuis-dev <
cuis-dev at lists.cuis.st> wrote:

> Hello folks!
> I include some code to add an option to debug the action of MenuItemMorphs
> and PluggableButtonMorphs. See demo video
> <https://drive.google.com/file/d/1cVMwcMS56EgpYOiQg5MawVF6W_RaEzX3/view>
> and screenshot below:
>
> [image: image.png]
> Cheers!
> Facu.
>
> PS: I leave additional details about the implementation, that could be
> useful during code-review 👇
>
> ------------------------------
> 📝 The changes include support for MenuItemMorphs and PluggableButtonMorphs
> (for convenience, in this email, I'll refer to both of them as "buttons").
> It'd be nice to have a more general implementation¹, but I started only
> with those because I usually debug the actions of those kinds of morph
> types (manually, until now :P).
>
> The way it's implemented is by opening a debugger on the morph's action,
> and making it go forward² until it reaches the appropriate method on the
> morph's target/model (see #debugAction).
> Notice that it also shows a confirmation message in case you try to debug
> —and therefore run— the action of a disabled button³.
>
> To execute the button's action, I reused some code from
> PluggableButtonMorph>>#performAction and MenuItemMorph>>#invokeWithEvent:.
> To do that, I extracted a couple of methods; I include here the reasons
> that motivated the way I chose to do it:
>
>    1. To be able to skip the check to see if the button was enabled or
>    not, I had to extract the code that runs the action without making any
>    precondition checks.
>    2. In the case of MenuItemMorph>>#invokeWithEvent:, the #numArgs message
>    is sent to the corresponding selector. During manual testing, I discovered
>    that this caused the String>>#numArgs method to run in the debugger
>    (stepping through it as part of the mechanism mentioned before), and it was *very
>    slow*. So, to avoid running that part of the code in the debugger, I
>    extracted a method that does all the pre-processing and returns a block
>    that's ready to run the action (MenuItemMorph>>#actionBlockForEvent:).
>    Then, I run *that* block on the debugger.
>    3. The issue mentioned in point (2) did not happen for
>    PluggableButtonMorph>>#performAction. Nonetheless, I made a similar
>    implementation, just for consistency's sake (
>    PluggableButtonMorph>>#actionBlock). The different name has to do with
>    the different vocabulary used for the PluggableButtonMorph vs. the
>    MenuItemMorph, and with the fact that the MenuItemMorph needs an event
>    parameter.
>    4. As the MenuItemMorph needs an event, we have to simulate it. I
>    wasn't sure what was the best way to do it, so I'm currently passing
>    nil. While trying it out, I noticed that all of the menu items I
>    tested the option with were *not* using the event object. At any rate,
>    if there's some menu option that uses it, it'll fail with a "does not
>    understand" error.
>
> Additionally, as a refactor, to be able to open the debugger on a block
> without doing anything else, I extracted the method Debugger
> class>>#openDebugging:label: from Debugger class>>#openDebugging:to:label:
> .
> _____
> ¹ e.g. detecting the events supported by any morph and letting you
> simulate and debug the one of your choosing.
> ² i.e. "step into", by sending the #send message.
> ³ Since the action is not run by a normal interaction with the button, and
> if it's disabled maybe running the action could leave the system in an
> unexpected state. It does, though, let you debug the action if you really
> want to do it.
> --
> Cuis-dev mailing list
> Cuis-dev at lists.cuis.st
> https://lists.cuis.st/mailman/listinfo/cuis-dev
>


-- 

*Hernán WilkinsonAgile Software Development, Teaching & Coaching*
*Phone: +54-011*-4893-2057
*Twitter: @HernanWilkinson*
*site: http://www.10Pines.com <http://www.10pines.com/>*
Address: Alem 896, Floor 6, Buenos Aires, Argentina
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20231114/85b0b325/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 92698 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20231114/85b0b325/attachment-0001.png>


More information about the Cuis-dev mailing list