protected void ReplacePartWithNewAttribute(string attr, string attrValueNew)
{
XmlNode newPartref;
XmlNode newLayout = Inventory.MakeOverride(
Key,
attr,
attrValueNew,
LayoutCache.LayoutVersionNumber, out newPartref);
Inventory.GetInventory("layouts", m_cache.ProjectId.Name).PersistOverrideElement(newLayout);
DataTree dt = ContainingDataTree;
var rootKey = Key[0] as XmlNode;
// The first item in the key is always the root XML node for the whole display. This has now changed,
// so if we don't do something, subsequent visibility commands for other slices will use the old
// version as a basis and lose the change we just made (unless we Refresh, which we don't want to do
// when showing everything). Also, if we do refresh, we'll discard and remake everything.
foreach (Slice slice in dt.Slices)
{
if (slice.Key != null && slice.Key.Length >= 0 && slice.Key[0] == rootKey && rootKey != newLayout)
slice.Key[0] = newLayout;
}
int lastPartRef;
XmlNode oldPartRef = PartRef(out lastPartRef);
if (oldPartRef != null)
{
oldPartRef = (XmlNode)Key[lastPartRef];
Key[lastPartRef] = newPartref;
foreach (Slice slice in dt.Slices)
{
if (slice.Key == null)
continue; // this can happen for dummy slices. (LT-5817)
for (int i = 0; i < slice.Key.Length; i++)
{
var node = slice.Key[i] as XmlNode;
if (node == null)
continue;
if (XmlUtils.NodesMatch(oldPartRef, node))
slice.Key[i] = newPartref;
}
}
}
}