[Cuis-dev] Debug action for buttons

Facundo Javier Gelatti javiergelatti at gmail.com
Mon Nov 13 15:16:33 PST 2023

Hello folks!
I include some code to add an option to debug the action of MenuItemMorphs
and PluggableButtonMorphs. See demo video
and screenshot below:

[image: image.png]

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
   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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20231113/ef31804e/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/20231113/ef31804e/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: DebugAction-FacundoJavierGelatti.cs.st
Type: application/octet-stream
Size: 3484 bytes
Desc: not available
URL: <http://lists.cuis.st/mailman/archives/cuis-dev/attachments/20231113/ef31804e/attachment-0001.obj>

More information about the Cuis-dev mailing list