コード例 #1
0
ファイル: AppliMenu.cs プロジェクト: jcaillon/3P
        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);
                        }
                    }
                };
            }
        }
コード例 #2
0
ファイル: Npp.cs プロジェクト: jcaillon/3P
 /// <summary>
 /// Creates entry in the FuncItems list, which list the menu entry displayed in Npp's plugin menu
 /// </summary>
 public static void SetCommand(int index, string commandName, Action functionPointer, ShortcutKey shortcut = new ShortcutKey(), bool checkOnInit = false)
 {
     var funcItem = new FuncItem {
         _cmdID = index,
         _itemName = commandName
     };
     if (functionPointer != null)
         funcItem._pFunc = functionPointer;
     if (shortcut._key != 0)
         funcItem._pShKey = shortcut;
     funcItem._init2Check = checkOnInit;
     UnmanagedExports.FuncItems.Add(funcItem);
 }