Save TreeWidget state when it changes
(cherry picked from commit caac33d05802d6e67805ece14eb5bd116db27392)