This class handle the Main context menu (and its children) It also has knownledge of the shortcuts for each item in the menu
Inheritance: IDisposable
Example #1
0
        public MenuItem(AppliMenu menuToRegisterTo, string name, Image img, Action action, string itemId, string defaultKey, List <MenuItem> children)
        {
            ItemName  = name;
            ItemImage = img;

            // children?
            if (children != null)
            {
                ChildrenList = children;
                Children     = children.Select(item => (YamuiMenuItem)item).ToList();
            }

            // shortcut?
            if (!string.IsNullOrEmpty(itemId))
            {
                ItemId   = itemId;
                ItemSpec = defaultKey;

                if (Config.Instance.ShortCuts.ContainsKey(ItemId))
                {
                    ItemSpec = Config.Instance.ShortCuts[ItemId];
                    Config.Instance.ShortCuts.Remove(ItemId);
                }

                if (!string.IsNullOrEmpty(ItemSpec))
                {
                    Config.Instance.ShortCuts.Add(ItemId, ItemSpec);
                    Shortcut = new ShortcutKey(ItemSpec);
                    SubText  = ItemSpec;
                }

                // we set up a list of items to use in the shortcut page
                if (menuToRegisterTo != null)
                {
                    menuToRegisterTo.ShortcutableItemList.Add(this);
                }
            }

            // action?
            if (action != null)
            {
                OnClic = action;
                // We set the Do() action, which is the "go through" action when the OnClic action is activated
                Do = () => {
                    if (OnClic != null)
                    {
                        try {
                            OnClic();
                        } catch (Exception e) {
                            ErrorHandler.ShowErrors(e, "Error in : " + ItemName);
                        }
                    }
                };
            }
        }
Example #2
0
        public MenuItem(AppliMenu menuToRegisterTo, string name, Image img, Action <YamuiMenuItem> action, string itemId, string defaultKey, List <MenuItem> children)
        {
            DisplayText = name;
            ItemImage   = img;

            // children?
            if (children != null)
            {
                ChildrenList = children;
                Children     = children.Cast <FilteredTypeTreeListItem>().ToList();
            }

            // shortcut?
            if (!string.IsNullOrEmpty(itemId))
            {
                ItemId   = itemId;
                ItemSpec = defaultKey;

                if (Config.Instance.ShortCuts.ContainsKey(ItemId))
                {
                    ItemSpec = Config.Instance.ShortCuts[ItemId];
                    Config.Instance.ShortCuts.Remove(ItemId);
                }

                Config.Instance.ShortCuts.Add(ItemId, ItemSpec);

                if (!string.IsNullOrEmpty(ItemSpec))
                {
                    Shortcut = new ShortcutKey(ItemSpec);
                    SubText  = ItemSpec;
                }

                // we set up a list of items to use in the shortcut page
                if (menuToRegisterTo != null)
                {
                    menuToRegisterTo.ShortcutableItemList.Add(this);
                }
            }

            // action?
            OnClic = action;

            // default is not expanded
            IsExpanded = false;
        }
Example #3
0
 public MenuItem(AppliMenu menuToRegisterTo, string name, Image img, Action <YamuiMenuItem> action, string itemId, string defaultKey) :
     this(menuToRegisterTo, name, img, action, itemId, defaultKey, null)
 {
 }
Example #4
0
 public MenuItem(AppliMenu menuToRegisterTo, string name, Image img, Action action, string itemId, string defaultKey)
     : this(menuToRegisterTo, name, img, action, itemId, defaultKey, null)
 {
 }
Example #5
0
        public MenuItem(AppliMenu menuToRegisterTo, string name, Image img, Action action, string itemId, string defaultKey, List<MenuItem> children)
        {
            ItemName = name;
            ItemImage = img;

            // children?
            if (children != null) {
                ChildrenList = children;
                Children = children.Select(item => (YamuiMenuItem)item).ToList();
            }

            // shortcut?
            if (!string.IsNullOrEmpty(itemId)) {

                ItemId = itemId;
                ItemSpec = defaultKey;

                if (Config.Instance.ShortCuts.ContainsKey(ItemId)) {
                    ItemSpec = Config.Instance.ShortCuts[ItemId];
                    Config.Instance.ShortCuts.Remove(ItemId);
                }

                if (!string.IsNullOrEmpty(ItemSpec)) {
                    Config.Instance.ShortCuts.Add(ItemId, ItemSpec);
                    Shortcut = new ShortcutKey(ItemSpec);
                    SubText = ItemSpec;
                }

                // we set up a list of items to use in the shortcut page
                if (menuToRegisterTo != null)
                    menuToRegisterTo.ShortcutableItemList.Add(this);
            }

            // action?
            if (action != null) {
                OnClic = action;
                // We set the Do() action, which is the "go through" action when the OnClic action is activated
                Do = () => {
                    if (OnClic != null) {
                        try {
                            OnClic();
                        } catch (Exception e) {
                            ErrorHandler.ShowErrors(e, "Error in : " + ItemName);
                        }
                    }
                };
            }
        }