Clear tabs first before destroying window.

This prevents us from holding unique pointers to dangling widgets
after they have been already destroyed by the notebook.