Further improvements to monitor logic.

Code file now generated on open (this catches new items added to the
project) or save.  Outstanding issue that events sometimes seem to get
unsubscribed/garbage collected for seemingly no reason.