Make sure an item being renamed is displayed in the tree.

Also makes sure that the item being shown is within the project.
Fix for #9423 and #9487.