protected PluginMenuPartStruct GetMenuItemIndex(PluginMenuItemPart theMenuItemPart, TreeNodeCollection nodes)
        {
            PluginMenuPartStruct theMenuItem = new PluginMenuPartStruct();
            int    index         = 0;
            string menuItemIndex = GetMenuItemIndex(theMenuItemPart.Locate);
            PluginMenuItemLocateType menuItemLocationType = (PluginMenuItemLocateType)(
                Enum.Parse(typeof(PluginMenuItemLocateType),
                           GetMenuItemLocator(theMenuItemPart.Locate),
                           true
                           )
                );

            theMenuItem.IsCreate = menuItemLocationType == PluginMenuItemLocateType.Create;

            if (int.TryParse(menuItemIndex, out index))
            {
                theMenuItem.Index = PluginMenuItemPartLocator.GetMenuLocatorIndex(menuItemLocationType, index, nodes.Count);
            }
            else if (menuItemIndex.Length == 0)
            {
                theMenuItem.Index = nodes.Count;
            }
            else
            {
                int realIndex = GetMenuItemIndexById(nodes, menuItemIndex);
                theMenuItem.Index = PluginMenuItemPartLocator.GetMenuLocatorIndex(
                    menuItemLocationType,
                    realIndex,
                    nodes.Count
                    );
                // Make only support ID
                if (menuItemLocationType == PluginMenuItemLocateType.Make)
                {
                    if (realIndex >= 0 && realIndex < nodes.Count)
                    {
                        theMenuItem.IsCreate = false;
                    }
                    else
                    {
                        theMenuItem.IsCreate = true;
                    }
                }
            }
            theMenuItem.Exist = theMenuItem.Index < nodes.Count &&
                                theMenuItem.Index >= 0;

            return(theMenuItem);
        }
        protected void AddTreeNodeIntoTree(ConnectionPointContainer container, ItemCollection nodes, PluginConfigItem theItem, PluginMenuPath thePath, IList <PluginMenuItemPart> thePaths, ExecutePluginCallback callback)
        {
            if (thePaths.Count < 1)
            {
                return;
            }

            PluginMenuItemPart         firstPart  = thePaths[0];
            PluginMenuPartStruct       menuStruct = GetMenuItemIndex(firstPart, nodes);
            IList <PluginMenuItemPart> otherParts = GetLeavesMenuItemParts(thePaths);

            if (!menuStruct.IsCreate)
            {
                AddTreeNodeIntoTree(container, (nodes[menuStruct.Index] as TreeViewItem).Items,
                                    theItem, thePath, otherParts, callback);
            }
            else
            {
                TreeViewItem theMenuItem = new TreeViewItem()
                {
                    Header = firstPart.TextStyle.Text
                };
                CreateMenuEndItem(firstPart, theMenuItem, GetImageList(container, thePath.MenuImageIndex));

                nodes.Insert(
                    menuStruct.Index,
                    theMenuItem
                    );

                if (thePaths.Count > 1)
                {
                    AddTreeNodeIntoTree(container, theMenuItem.Items, theItem, thePath, otherParts, callback);
                }
                else
                {
                    theMenuItem.Name = theItem.Url;
                    theMenuItem.Tag  = new object[] { theItem, callback };

                    //theMenuItem.TreeView.NodeMouseClick -= new TreeNodeMouseClickEventHandler(TreeView_NodeMouseClick);
                    //theMenuItem.TreeView.NodeMouseClick += new TreeNodeMouseClickEventHandler(TreeView_NodeMouseClick);

                    return;
                }
            }
        }
        protected PluginMenuPartStruct GetMenuItemIndex(PluginMenuItemPart theMenuItemPart, TreeNodeCollection nodes)
        {
            PluginMenuPartStruct theMenuItem = new PluginMenuPartStruct();
            int index = 0;
            string menuItemIndex = GetMenuItemIndex(theMenuItemPart.Locate);
            PluginMenuItemLocateType menuItemLocationType = (PluginMenuItemLocateType)(
                Enum.Parse(typeof(PluginMenuItemLocateType),
                    GetMenuItemLocator(theMenuItemPart.Locate),
                    true
                    )
                );
            theMenuItem.IsCreate = menuItemLocationType == PluginMenuItemLocateType.Create;

            if (int.TryParse(menuItemIndex, out index))
            {
                theMenuItem.Index = PluginMenuItemPartLocator.GetMenuLocatorIndex(menuItemLocationType, index, nodes.Count);
            }
            else if (menuItemIndex.Length == 0)
            {
                theMenuItem.Index = nodes.Count;
            }
            else
            {
                int realIndex = GetMenuItemIndexById(nodes, menuItemIndex);
                theMenuItem.Index = PluginMenuItemPartLocator.GetMenuLocatorIndex(
                    menuItemLocationType,
                    realIndex,
                    nodes.Count
                    );
                // Make only support ID
                if (menuItemLocationType == PluginMenuItemLocateType.Make)
                {
                    if (realIndex >= 0 && realIndex < nodes.Count)
                        theMenuItem.IsCreate = false;
                    else
                        theMenuItem.IsCreate = true;
                }
            }
            theMenuItem.Exist = theMenuItem.Index < nodes.Count
                    && theMenuItem.Index >= 0;

            return theMenuItem;
        }
Beispiel #4
0
        protected void AddMenuItemIntoMenu(ConnectionPointContainer container,
                                           ItemCollection menuItemCollection,
                                           PluginConfigItem theItem,
                                           PluginMenuPath thePath,
                                           IList <PluginMenuItemPart> thePaths, ExecutePluginCallback callback)
        {
            if (thePaths.Count < 1)
            {
                return;
            }

            PluginMenuItemPart         firstPart  = thePaths[0];
            PluginMenuPartStruct       menuStruct = GetMenuItemIndex(firstPart, menuItemCollection);
            IList <PluginMenuItemPart> otherParts = GetLeavesMenuItemParts(thePaths);

            if (!menuStruct.IsCreate)
            {
                AddMenuItemIntoMenu(container,
                                    (menuItemCollection[menuStruct.Index] as MenuItem).Items,
                                    theItem,
                                    thePath,
                                    otherParts, callback);
            }
            else
            {
                if (firstPart.TextStyle.Text.Trim() == "-")
                {
                    menuItemCollection.Insert(menuStruct.Index, new Separator());
                    return;
                }

                MenuItem theMenuItem = new MenuItem()
                {
                    Header = firstPart.TextStyle.Text
                };

                CreateMenuEndItem(firstPart, theMenuItem, GetImageList(container, thePath.MenuImageIndex));
                menuItemCollection.Insert(menuStruct.Index, theMenuItem);

                if (thePaths.Count > 1)
                {
                    AddMenuItemIntoMenu(container, theMenuItem.Items, theItem, thePath, otherParts, callback);
                }
                else
                {
                    theMenuItem.Name = theItem.Url;
                    theMenuItem.Tag  = new object[] { theItem, callback };
                    string[] behaviors = theItem.Behavior.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    foreach (string action in behaviors)
                    {
                        PluginConfigItemBehaviorMode theBehavior = (PluginConfigItemBehaviorMode)Enum.Parse(typeof(PluginConfigItemBehaviorMode), action, true);
                        switch (theBehavior)
                        {
                        case PluginConfigItemBehaviorMode.Click:
                            theMenuItem.Click -= TheMenuItem_Click;
                            theMenuItem.Click += TheMenuItem_Click;
                            break;

                        case PluginConfigItemBehaviorMode.MouseOver:
                            theMenuItem.MouseMove -= TheMenuItem_MouseMove;
                            theMenuItem.MouseMove += TheMenuItem_MouseMove;
                            break;
                        }
                    }
                    return;
                }
            }
        }