Friday 23 November 2012

Including/Reusing an H2 script inside another H2 Script

Here is a cool technique that I use to include *.H2 scripts into other scripts, and the environment that I create during its development:

Here is what this script is doing:

  • Line 1: 'Include' the source code of the Util - Windows Handles Viewer (Simple Gui).h2 at the top (think of this as a 'copy and paste' of the external script code
  • Line 3: Get a reference to the parent Form object (note that the topPanel value was set on the included H2 script) and set a timer to close it in 10 sec (this is very useful when doing development on stand-alone Form controls, since during REPL development we just want to take a quick look at what happened with the latest code changes
  • Line 7: insert a panel below (this is the same as adding a SplitContainer with the current control at the top and a new Panel at the bottom
  • Line 8: Because the split container (created in line 7) by default sets the Splitter Distance to be half of the current form (and calling {target}.insert_Below(nn) will set the bottom frame to be the size of nn), we need to set this value here (since we want the top frame to have the size of nn (in this case 30 )
  • Line 10: Add a .Net TextBox with the Docking value set to Fill and with MultiLine enabled (which is why I call it a TextArea)

This is what this script looks like (with the comments/arrows added using Lucid Chart) 

Question: does this diagram make sense? Should I create more like these?

I'm still trying to figure out a good convention and format for these 'this is what is going on' kind of diagrams