Exemple #1
0
        public void AddItem(MenuItemDef menuItemDef)
        {
            bool flag = false;

            if (!string.IsNullOrEmpty(menuItemDef.BeginGroup))
            {
                flag = bool.Parse(menuItemDef.BeginGroup);
            }
            if (menuItemDef.HasSubMenu)
            {
                this.ClearSubItem(menuItemDef.Name);
                this.AddSubmenuItem(menuItemDef.Name, menuItemDef.Caption,
                                    string.IsNullOrEmpty(menuItemDef.MainMenuItem) ? "" : menuItemDef.MainMenuItem, flag);
            }
            else
            {
                BarSubItem item = null;
                if (!string.IsNullOrEmpty(menuItemDef.MainMenuItem))
                {
                    item = this.popupMenu_0.Manager.Items[menuItemDef.MainMenuItem] as BarSubItem;
                    if (item == null)
                    {
                        item = new BarSubItem
                        {
                            Name = menuItemDef.MainMenuItem
                        };
                        this.popupMenu_0.Manager.Items.Add(item);
                        if (flag)
                        {
                            this.popupMenu_0.AddItem(item).BeginGroup = true;
                        }
                        else
                        {
                            this.popupMenu_0.AddItem(item);
                        }
                    }
                }
                BarItem item2 = null;
                item2 = this.popupMenu_0.Manager.Items[menuItemDef.Name];
                if (item2 == null)
                {
                    item2 = this.method_1(menuItemDef);
                }
                if (item2 != null)
                {
                    if (item != null)
                    {
                        item.ItemLinks.Add(item2).BeginGroup = flag;
                    }
                    else if (flag)
                    {
                        this.popupMenu_0.AddItem(item2).BeginGroup = true;
                    }
                    else
                    {
                        this.popupMenu_0.AddItem(item2);
                    }
                }
            }
        }
        private static void ReadBarItems(IPopuMenuWrap ipopuMenuWrap_0, XmlNode xmlNode_0)
        {
            MenuItemDef itemAttribute = GetItemAttribute(xmlNode_0);

            if (xmlNode_0.ChildNodes.Count > 0)
            {
                itemAttribute.HasSubMenu = true;
            }
            ipopuMenuWrap_0.AddItem(itemAttribute);
            for (int i = 0; i < xmlNode_0.ChildNodes.Count; i++)
            {
                ReadBarItems(ipopuMenuWrap_0, itemAttribute.Name, xmlNode_0.ChildNodes[i]);
            }
        }
        private static void ReadBarItems(IBarManager ibarManager_0, XmlNode xmlNode_0)
        {
            MenuItemDef itemAttribute = GetItemAttribute(xmlNode_0);

            if (xmlNode_0.ChildNodes.Count == 0)
            {
                ibarManager_0.AddItem(itemAttribute);
            }
            else
            {
                for (int i = 0; i < xmlNode_0.ChildNodes.Count; i++)
                {
                    ReadBarItems(ibarManager_0, xmlNode_0.ChildNodes[i]);
                }
            }
        }
Exemple #4
0
        private static ToolStripItem CreateMenuItemFromAction(MenuItemDef action, Project project)
        {
            if (action is SeparatorMenuItemDef)
            {
                return(CreateMenuItemSeparator());
            }
            else
            {
                // Build ContextMenu item
                ToolStripMenuItem menuItem = new ToolStripMenuItem(action.Title, null, (s, e) => action.Execute(action, project));
                menuItem.Tag     = action;
                menuItem.Name    = action.Name;
                menuItem.Text    = action.Title;
                menuItem.Checked = action.Checked;
                //menuItem.CheckOnClick = false;
                menuItem.Enabled = (action.IsFeasible && action.IsGranted(project.SecurityManager));
                if (action.IsFeasible && !action.IsGranted(project.SecurityManager))
                {
                    if (action is DelegateMenuItemDef)
                    {
                        menuItem.ToolTipText = string.Format("Action is deactivated because you don't have the permission for '{0}'.", ((DelegateMenuItemDef)action).RequiredPermission);
                    }
                    else
                    {
                        menuItem.ToolTipText = "Action is deactivated because you don't have the required permissions.";
                    }
                }
                else
                {
                    menuItem.ToolTipText = action.Description;
                }
                menuItem.Image = action.Image;
                menuItem.ImageTransparentColor = action.ImageTransparentColor;

                menuItem.DropDownItems.Clear();
                // Add sub menu items (do not skip any sub items: if parent is granted, subitems are granted too)
                if (action.SubItems != null)
                {
                    int cnt = action.SubItems.Length;
                    for (int i = 0; i < cnt; ++i)
                    {
                        menuItem.DropDownItems.Add(CreateMenuItemFromAction(action.SubItems[i], project));
                    }
                }
                return(menuItem);
            }
        }
        private static MenuItemDef GetItemAttribute(XmlNode xmlNode_0)
        {
            MenuItemDef def = new MenuItemDef();

            for (int i = 0; i < xmlNode_0.Attributes.Count; i++)
            {
                XmlAttribute attribute = xmlNode_0.Attributes[i];
                switch (attribute.Name.ToLower())
                {
                case "name":
                    def.Name = attribute.Value;
                    break;

                case "caption":
                    def.Caption = attribute.Value;
                    break;

                case "path":
                    def.Path = attribute.Value;
                    break;

                case "classname":
                    def.ClassName = attribute.Value;
                    break;

                case "subtype":
                    def.SubType = attribute.Value;
                    break;

                case "begingroup":
                    def.BeginGroup = attribute.Value;
                    break;

                case "bitmap":
                    def.BitmapPath = attribute.Value;
                    break;
                }
            }
            return(def);
        }
Exemple #6
0
        private static ToolStripItem CreateMenuItemFromAction(MenuItemDef action, Project project)
        {
            if (action is SeparatorMenuItemDef)
            {
                return(CreateMenuItemSeparator());
            }
            else
            {
                // Build ContextMenu item
                ToolStripMenuItem menuItem = new ToolStripMenuItem(action.Title, null, (s, e) => action.Execute(action, project));
                menuItem.Tag     = action;
                menuItem.Name    = action.Name;
                menuItem.Text    = action.Title;
                menuItem.Checked = action.Checked;
                //menuItem.CheckOnClick = false;
                menuItem.Enabled = (action.IsFeasible && action.IsGranted(project.SecurityManager));
                if (action.IsFeasible && !action.IsGranted(project.SecurityManager))
                {
                    menuItem.ToolTipText = "Action is not granted.";
                }
                else
                {
                    menuItem.ToolTipText = action.Description;
                }
                menuItem.Image = action.Image;
                menuItem.ImageTransparentColor = action.ImageTransparentColor;

                menuItem.DropDownItems.Clear();
                // Add sub menu items (do not skip any sub items: if parent is granted, subitems are granted too)
                if (action.SubItems != null)
                {
                    for (int i = 0; i < action.SubItems.Length; ++i)
                    {
                        menuItem.DropDownItems.Add(CreateMenuItemFromAction(action.SubItems[i], project));
                    }
                }
                return(menuItem);
            }
        }
Exemple #7
0
        /// <summary>
        /// Creates a collection of ToolStripMenuItems from a collection of MenuItemDefs. Actions that are not allowed will be skipped.
        /// </summary>
        public static IEnumerable <ToolStripItem> GetContextMenuItemsFromAllowedActions(IEnumerable <MenuItemDef> actions,
                                                                                        Project project)
        {
            if (actions == null)
            {
                throw new ArgumentNullException("actions");
            }
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }
            MenuItemDef lastMenuItemDef = null;
            // Attention!!
            // We have to iterate manually instead of unsing foreach here because otherwise always the least
            // processed action's Execute method will be called.
            IEnumerator <MenuItemDef> enumerator = actions.GetEnumerator();

            while (enumerator.MoveNext())
            {
                // Skip actions that are not allowed
                if (!enumerator.Current.IsGranted(project.SecurityManager))
                {
                    continue;
                }
                // If the item is a separator and no 'real' item was created before, skip the separator
                // as we do not want a context  menu beginning with a menu seperator
                if (enumerator.Current is SeparatorMenuItemDef &&
                    (lastMenuItemDef == null || lastMenuItemDef is SeparatorMenuItemDef))
                {
                    continue;
                }
                // Build and return menu item
                yield return(CreateMenuItemFromAction(enumerator.Current, project));

                lastMenuItemDef = enumerator.Current;
            }
        }
Exemple #8
0
 public void AddItem(MenuItemDef menuItemDef)
 {
 }
Exemple #9
0
        private BarItem method_1(MenuItemDef menuItemDef_0)
        {
            ICommand           command = null;
            BarManagerCategory category;

            if ((menuItemDef_0.Path != null) && (menuItemDef_0.ClassName != null))
            {
                try
                {
                    if (menuItemDef_0.Path[1] != ':')
                    {
                        menuItemDef_0.Path = Application.StartupPath + @"\" + menuItemDef_0.Path;
                    }
                    if (File.Exists(menuItemDef_0.Path))
                    {
                        command = this.method_0(menuItemDef_0.Path).LoadClass(menuItemDef_0.ClassName) as ICommand;
                        if (command != null)
                        {
                            // command.OnCreate(null);
                            if (menuItemDef_0.SubType != null)
                            {
                                try
                                {
                                    int subType = int.Parse(menuItemDef_0.SubType);
                                    (command as ICommandSubType).SetSubType(subType);
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                }
            }
            if (command == null)
            {
                return(null);
            }
            BarItem item = null;

            item = this.popupMenu_0.Manager.Items[menuItemDef_0.Name];
            if (item != null)
            {
                return(item);
            }
            item = new BarButtonItem();
            this.popupMenu_0.Manager.Items.Add(item);
            item.Id      = this.popupMenu_0.Manager.GetNewItemId();
            item.Name    = menuItemDef_0.Name;
            item.Tag     = command;
            item.Caption = command.Caption;
            if (menuItemDef_0.Caption != null)
            {
                item.Caption = menuItemDef_0.Caption;
            }
            item.Enabled = command.Enabled;
            if (command.Tooltip != null)
            {
                item.Hint = command.Tooltip;
            }
            if ((menuItemDef_0.BitmapPath == null) && (command.Bitmap != 0))
            {
                try
                {
                    IntPtr hbitmap = new IntPtr(command.Bitmap);
                    Bitmap bitmap  = Image.FromHbitmap(hbitmap);
                    bitmap.MakeTransparent();
                    item.Glyph = bitmap;
                    goto Label_01E8;
                }
                catch
                {
                    goto Label_01E8;
                }
            }
            if (menuItemDef_0.BitmapPath != null)
            {
                item.Glyph = new Bitmap(menuItemDef_0.BitmapPath);
            }
Label_01E8:
            if (command.Category != null)
            {
                if (command.Category.Length > 0)
                {
                    category = this.popupMenu_0.Manager.Categories[command.Category];
                    if (category == null)
                    {
                        category = new BarManagerCategory(command.Category, Guid.NewGuid());
                        this.popupMenu_0.Manager.Categories.Add(category);
                    }
                    item.Category = category;
                    return(item);
                }
                category = this.popupMenu_0.Manager.Categories["其他"];
                if (category == null)
                {
                    category = new BarManagerCategory("其他", Guid.NewGuid());
                    this.popupMenu_0.Manager.Categories.Add(category);
                }
                item.Category = category;
                return(item);
            }
            category = this.popupMenu_0.Manager.Categories["其他"];
            if (category == null)
            {
                category = new BarManagerCategory("其他", Guid.NewGuid());
                this.popupMenu_0.Manager.Categories.Add(category);
            }
            item.Category = category;
            return(item);
        }