Beispiel #1
0
 public static void LoadItems(this ISectionHeader sectionHeader, IEnumerable <IScreenItem> items)
 {
     foreach (var item in items)
     {
         sectionHeader.AddItem(item);
     }
 }
        private void butTest_Click(object sender, RoutedEventArgs e)
        {
            ISectionHeader sh = this.Model;

            // find the first ScreenSection. set to the items of that section.
            var sect = sh.Items.OfType <ScreenSectionModel>().First();

            if (sect != null)
            {
                sh = sect;
            }

            var found = sh.Items.FirstOrDefault(c => c.ItemName == "abc3");

            if (found != null)
            {
                sh.RemoveItem(found);
            }

            var item = new ScreenLiteralModel();

            item.ItemName  = "abc3";
            item.ScreenLoc = new OneScreenLoc(1, 5);

            sh.AddItem(item);
        }
        public static void WorkScreenItem(
            ActionCode action, ISectionHeader sectionHeader, ScreenItemModel itemModel)
        {
            bool cancelAction = false;

            while (true)
            {
                var window = new WorkScreenItemWindow(action);
                window.ScreenItemModel = itemModel;
                var rv = window.ShowDialog();
                if ((rv == null) || (rv.Value == false))
                {
                    cancelAction = true;
                    break;
                }

                if (window.ModelTypeChanged == true)
                {
                    if (action != ActionCode.Add)
                    {
                        sectionHeader.ReplaceModel(itemModel, window.ScreenItemModel);
                        sectionHeader.OnSectionHeaderChanged();
                    }
                    itemModel = window.ScreenItemModel;
                    continue;
                }
                else
                {
                    // the selectedItem was passed by reference. On return that same reference
                    // has been updated by the WorkScreenItemWindow. No need to apply to the
                    // itemsSource. It is already updated.
                    cancelAction = false;
                    itemModel    = window.ScreenItemModel;
                    break;
                }
            }

            // entry accepted. Add to list of items.
            if ((cancelAction == false) && (action == ActionCode.Add))
            {
                sectionHeader.AddItem(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);
        }