Use accessors to determine the presence of widgets
Fix loss of undo step after using undo

Basically the same mistake that was (partially) fixed in a6510fe0d.
Speed up gui_info.index()

We avoid calling .length() (a recursive function) in .index() (a
recursive function). Privodes a nice speed up in very complex trees
(long with lots of newlines, for example).
Swap tests to bail out on the cheap test if possible
Provide an (element, index) iterator for .sub

This way a user (TextBox) can iterate over .sub and get the index for
each element cheaply, otherwise .index() is quite expensive.
Use the custom iterator to get indexes fast

This way we eliminate most calls to .gui_info.index() which was very
expensive in complex trees.
Remove unused variables