Example #1
0
        public void RegisterItem(ToolStripPath path, IToolStripItemCodon toolStripItem)
        {
            ToolStripItem view = (ToolStripItem)toolStripItem.View;

            if (path.PathPoints.Count == 1)
            {
                if (path.PathPoints[0].Index.HasValue)
                {
                    int index = path.PathPoints[0].Index.Value;
                    if (index >= this.Items.Count)
                    {
                        index = this.Items.Count;
                    }
                    this.Items.Insert(index, view);
                }
                else
                {
                    this.Items.Add(view);
                }
            }
            else
            {
                ToolStripMenuItemView   targetItem           = null;
                ToolStripItemCollection targetItemCollection = this.Items;
                for (int i = 1; i < path.PathPoints.Count; i++)
                {
                    foreach (ToolStripMenuItemView targetItemDoozer in targetItemCollection)
                    {
                        IToolStripItemView doozer = targetItemDoozer as IToolStripItemView;
                        if (doozer == null)
                        {
                            continue;
                        }
                        if (doozer.Codon.PathPoint == path.PathPoints[i].Name)
                        {
                            targetItem           = targetItemDoozer;
                            targetItemCollection = targetItemDoozer.DropDownItems;
                            break;
                        }
                    }
                }
                if (targetItem != null)
                {
                    if (path.PathPoints[path.PathPoints.Count - 1].Index.HasValue)
                    {
                        int index = path.PathPoints[path.PathPoints.Count - 1].Index.Value;
                        if (index >= targetItem.DropDownItems.Count)
                        {
                            index = targetItem.DropDownItems.Count;
                        }
                        targetItem.DropDownItems.Insert(index, view);
                    }
                    else
                    {
                        targetItem.DropDownItems.Add(view);
                    }
                }
            }
        }
Example #2
0
        public void RegisterItem(ToolStripPath path, IToolStripItemCodon toolStripItem)
        {
            if (path.PathPoints.Count > 1)
            {
                throw new NotImplementedException("工具栏暂不支持多级注册项");
            }
            toolStripItem.Owner = this.Codon;
            ToolStripMenuItemView item = toolStripItem.View as ToolStripMenuItemView;

            if (path.PathPoints[0].Index.HasValue)
            {
                this.Items.Insert(path.PathPoints[0].Index.Value, item);
            }
            else
            {
                this.Items.Add(item);
            }
        }