add a method to find the ancestor dock tab widget.
more layout op handlers and code cleanup

This implements the rest of the layout op handlers.
It also refactors a lot of repeated code in contextmanager methods.