Split the saving of tree state from the saving of the project path.

Those are two independent things that need to happen at different times.

This is a followup to #9212.

cc @ingorichter