private void SwitchToReal() { // Depending on compile switch for SLICE_IS_SPLITCONTAINER, // grandParent will be both a Slice and a SplitContainer // (Slice is a subclass of SplitContainer), // or just a SplitContainer (SplitContainer is the only child Control of a Slice). // If grandParent is not a Slice, then we have to move up to the great-grandparent // to find the Slice. GhostStringSlice slice = Parent.Parent as GhostStringSlice; // Will also be disposed. if (slice == null) { slice = Parent.Parent.Parent as GhostStringSlice; // Will also be disposed. } // Save info we will need after MakeRealObject destroys this. object[] parentKey = slice.Key; int flidEmptyProp = m_flidEmptyProp; int flidStringProp = m_flidStringProp; int wsToCreate = m_wsToCreate; DataTree datatree = slice.ContainingDataTree; ITsString tssTyped; int ich, hvo, tag, ws; bool fAssocPrev; RootBox.Selection.TextSelInfo(false, out tssTyped, out ich, out fAssocPrev, out hvo, out tag, out ws); // Make the real object and set the string property we are ghosting. The final PropChanged // will typically dispose this and create a new string slice whose key is our own key // followed by the flid of the string property. int hvoNewObj = MakeRealObject(tssTyped); // Now try to make a suitable selection in the slice that replaces this. RestoreSelection(ich, datatree, parentKey, hvoNewObj, flidEmptyProp, flidStringProp, wsToCreate); }
void MakeGhostSlice(ArrayList path, XmlNode node, ObjSeqHashMap reuseMap, ICmObject obj, int flidEmptyProp, XmlNode caller, int indent, ref int insertPosition) { // It's a really bad idea to add it to the path, since it kills // the code that hot swaps it, when becoming real. //path.Add(node); Slice slice = GetMatchingSlice(path, reuseMap); if (slice == null) { slice = new GhostStringSlice(obj.Hvo, flidEmptyProp, node, m_cache); // Set the label and abbreviation (in that order...abbr defaults to label if not given. // Note that we don't have a "caller" here, so we pass 'node' as both arguments... // means it gets searched twice if not found, but that's fairly harmless. slice.Label = GetLabel(node, node, obj, "ghostLabel"); slice.Abbreviation = GetLabelAbbr(node, node, obj, slice.Label, "ghostAbbr"); // Install new item at appropriate position and level. slice.Indent = indent; slice.Object = obj; slice.Cache = m_cache; slice.Mediator = m_mediator; // We need a copy since we continue to modify path, so make it as compact as possible. slice.Key = path.ToArray(); slice.ConfigurationNode = node; slice.CallerNode = caller; // don't mess with this, the obj/seq node would not have a meaningful back color override // for the slice. If we need it invent a new attribute. //slice.OverrideBackColor(XmlUtils.GetOptionalAttributeValue(node, "backColor")); // dubious...should the string slice really get the context menu for the object? slice.ShowContextMenu += new TreeNodeEventHandler(this.OnShowContextMenu); slice.SmallImages = SmallImages; SetNodeWeight(node, slice); slice.FinishInit(); InsertSliceAndRegisterWithContextHelp(insertPosition, slice, node); } else { EnsureValidIndexForReusedSlice(slice, insertPosition); } insertPosition++; // Since we didn't add it to the path, // then there is nothign to do at this end either.. //slice.GenerateChildren(node, caller, obj, indent, ref insertPosition, path, reuseMap); //path.RemoveAt(path.Count - 1); }