Ejemplo n.º 1
0
        public void AddItem(IMenuItem menuItem, IMenuItemMetaData importData)
        {
            StringBuilder gestureText = new StringBuilder();

            var linkedCommands = _globalCommandImportData.Where(x => x.Value.Command == menuItem.Command);

            foreach (var link in linkedCommands)
            {
                gestureText.Append(link.Value.GestureText).Append(" ");
            }

            var itemViewModel = new MenuItemModel(menuItem.HeaderText, menuItem.Command, gestureText.ToString().Trim());
            _menuInfo.Add(new MenuItemInfo(importData.Key, importData.RelativePosition, importData.RelativeMenuItemKey, itemViewModel, importData.ShouldPrependSeparator));

        }
Ejemplo n.º 2
0
        public MenuItemModel Build()
        {
            var root = new MenuItemModel(String.Empty, null, String.Empty);

            foreach (var info in _menuInfo)
            {
                MenuItemModel relativeItem;

                if (info.RelativeMenuItemKey == MenuItems.Root)
                    relativeItem = root;
                else
                {
                    var relativeItemInfo = _menuInfo.Where(x => x.MenuItemKey == info.RelativeMenuItemKey).FirstOrDefault();

                    if (relativeItemInfo == null)
                        throw new MenuItemNotFoundException(String.Format("The menu item with key {0} declares a relative item key {1} that was not found.", info.MenuItemKey, info.RelativeMenuItemKey));

                    relativeItem = relativeItemInfo.MenuItem;
                }

                switch (info.RelativePosition)
                {
                    case MenuPosition.InsertAfter:
                        relativeItem.InsertAfter(info.MenuItem);
                        break;
                    case MenuPosition.InsertBefore:
                        relativeItem.InsertBefore(info.MenuItem);
                        break;
                    case MenuPosition.AppendTo:
                        if (info.ShouldPrependSeparator)
                            relativeItem.AppendChild(new MenuSeparatorModel());

                        relativeItem.AppendChild(info.MenuItem);
                        break;
                    case MenuPosition.PrependTo:
                        relativeItem.PrependChild(info.MenuItem);
                        break;
                }
            }

            return root;
        }
Ejemplo n.º 3
0
 public MenuItemInfo(String menuItemKey, MenuPosition relativePosition, String relativeMenuItemKey, MenuItemModel menuItem, Boolean shouldPrependSeparator)
 {
     this.MenuItemKey = menuItemKey;
     this.RelativePosition = relativePosition;
     this.RelativeMenuItemKey = relativeMenuItemKey;
     this.MenuItem = menuItem;
     this.ShouldPrependSeparator = shouldPrependSeparator;
 }
Ejemplo n.º 4
0
 private void InsertChildAfter(MenuItemModel childToInsert, MenuItemModel relativePositionMarker)
 {
     var index = this._children.IndexOf(relativePositionMarker);
     this._children.Insert(index + 1, childToInsert);
     childToInsert.SetParent(this);
 }
Ejemplo n.º 5
0
        private void SetParent(MenuItemModel parent)
        {
            this._parent = parent;

            foreach (var item in _previousSiblings)
                _parent.InsertChildBefore(item, this);

            foreach (var item in _nextSiblings)
                _parent.InsertChildAfter(item, this);
        }
Ejemplo n.º 6
0
        private void InsertChildBefore(MenuItemModel childToInsert, MenuItemModel relativePositionMarker)
        {
            var index = this._children.IndexOf(relativePositionMarker);

            if (index > 0)
            {
                if (this._children[index - 1] is MenuSeparatorModel)
                {
                    index--;
                }
            }

            this._children.Insert(index, childToInsert);
            childToInsert.SetParent(this);
        }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds a child item to the start of this list.
 /// </summary>
 /// <param name="newItem">The menu item to insert</param>
 public void PrependChild(MenuItemModel newItem)
 {
     this._children.Insert(0, newItem);
     newItem.SetParent(this);
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Adds a child item to the end of this list.
 /// </summary>
 /// <param name="newItem">The menu item to insert</param>
 public void AppendChild(MenuItemModel newItem)
 {
     this._children.Add(newItem);
     newItem.SetParent(this);
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Inserts a sibling item in the position after this item.
 /// </summary>
 /// <param name="newItem">The menu item to insert</param>
 public void InsertAfter(MenuItemModel newItem)
 {
     if (_parent == null)
     {
         _nextSiblings.Add(newItem);
     }
     else
     {
         _parent.InsertChildAfter(newItem, this);
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Inserts a sibling item in the position before this item.
 /// </summary>
 /// <param name="newItem">The menu item to insert</param>
 public void InsertBefore(MenuItemModel newItem)
 {
     if (_parent == null)
     {
         _previousSiblings.Add(newItem);
     }
     else
     {
         _parent.InsertChildBefore(newItem, this);
     }
 }