Ignore brushes and scene's tool settings during undo.
Note that this affects all tool settings, not only sculpt/paint
ones.
Add code preserving scene's toolsettings accross undo.
IDPointers are dealt with special care, we try to keep existing ones for
some (like brushes) when possible.
Note that this only covers ToolSettings, changes done to Brush etc.
other IDs are still undone currently.
Part of T71759.