Save treeview state when it changes
(cherry picked from commit a9dc38ff66a2130c907216912b7608b4318c8977)