public static void ReplaceModel( this ISectionHeader sectionHeader, ScreenItemModel itemModel, ScreenItemModel screenItemModel) { var ix = sectionHeader.ItemIndexOf(itemModel); if (ix >= 0) { sectionHeader.InsertItemBefore(ix, screenItemModel); sectionHeader.RemoveItem(itemModel); } }
private IScreenItem Paste_Actual( RelativePosition Rltv, ISectionHeader ToSectionHeader, int ToIndex = -1) { int toIndex = ToIndex; IScreenItem lastPasteItem = null; if (ToIndex >= 0) { lastPasteItem = ToSectionHeader.GetItemAt(ToIndex); } var rltv = Rltv; foreach (var item in this) { IScreenItem pasteItem = null; // remove from the from list. if (item.CopyPasteCode == CopyPasteCode.Cut) { pasteItem = item.Cut(); } // dup the item to copy. if (item.CopyPasteCode == CopyPasteCode.Copy) { pasteItem = ScreenItemModel.Factory(item.ScreenItem); pasteItem.AssignItemGuid(); } // index of the insert relative to item. toIndex = -1; if (lastPasteItem != null) { toIndex = ToSectionHeader.Items.IndexOf(lastPasteItem); } // insert into ToList. if (rltv == RelativePosition.After) { ToSectionHeader.InsertItemAfter(toIndex, pasteItem); } else if (rltv == RelativePosition.Begin) { ToSectionHeader.InsertItemBegin(pasteItem); } else if (rltv == RelativePosition.End) { ToSectionHeader.AddItem(pasteItem); } else if (rltv == RelativePosition.Before) { ToSectionHeader.InsertItemBefore(toIndex, pasteItem); } else { throw new Exception("invalid relative postion"); } // clear the copy/paste marking on the screenItem. if (this.IsGlobalList == true) { item.ScreenItem.CopyPasteCode = null; } // the last pasted item. lastPasteItem = pasteItem; // subsequent items are placed after the prior pasted item rltv = RelativePosition.After; } // clear the list of pending actions. this.Clear(); return(lastPasteItem); }