Пример #1
0
        /// <summary>
        /// The historic button shows a menu that allows the user to select a previously selected folders
        /// </summary>
        private void BtHistoricOnButtonPressed(object sender, EventArgs eventArgs)
        {
            List <YamuiMenuItem> itemList = new List <YamuiMenuItem>();

            foreach (var path in Config.Instance.SharedConfHistoric.Split(','))
            {
                if (!string.IsNullOrEmpty(path))
                {
                    itemList.Add(new YamuiMenuItem {
                        ItemImage = ImageResources.FolderType, ItemName = path, OnClic = () => {
                            if (IsHandleCreated)
                            {
                                BeginInvoke((Action) delegate {
                                    fl_directory.Text = path;
                                    RefreshList();
                                });
                            }
                        }
                    });
                }
            }
            if (itemList.Count > 0)
            {
                var menu = new YamuiMenu(Cursor.Position, itemList);
                menu.Show();
            }
        }
Пример #2
0
        private void yamuiCharButton1_Click(object sender, EventArgs e)
        {
            var menu = new YamuiMenu(Cursor.Position, new List <YamuiMenuItem> {
                new YamuiMenuItem {
                    ItemName = "zefefzefzef zedf item 1",
                    Children = new List <YamuiMenuItem> {
                        new YamuiMenuItem {
                            ItemName = "child 1"
                        }
                    }
                },
                new YamuiMenuItem {
                    ItemName = "item 2",
                },
                new YamuiMenuItem {
                    ItemName = "item 3",
                    Children = new List <YamuiMenuItem> {
                        new YamuiMenuItem {
                            ItemName = "child 1"
                        },
                        new YamuiMenuItem {
                            ItemName = "child 2"
                        }
                    }
                }
            });

            menu.Show();
        }
Пример #3
0
        /// <summary>
        /// Show a given menu
        /// </summary>
        public static void ShowMenuAtCursor(List <YamuiMenuItem> menuList, string menuTitle, string menuLogo = "logo16x16", int minSize = 180)
        {
            try {
                // Close any already opened menu
                ForceCloseMenu();

                // open requested menu
                var copyMenuList = menuList.ToList();
                copyMenuList.Insert(0, new YamuiMenuItem {
                    IsSeparator = true
                });

                var menu = new YamuiMenu(Cursor.Position, copyMenuList, "<div class='contextMenuTitle'><img src='" + menuLogo + "' width='16' Height='16' style='padding-right: 5px; padding-top: 1px;'>" + menuTitle + "</span>", minSize);
                menu.Show();
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error in ShowMenuAtCursor");
            }
        }
Пример #4
0
        /// <summary>
        /// Show a given menu
        /// </summary>
        public static void ShowMenu(List <YamuiMenuItem> menuList, string menuTitle, string menuLogo, bool showAtCursor = false, int minWidth = 250)
        {
            try {
                // Close any already opened menu
                ForceClose();

                if (menuLogo == null)
                {
                    menuLogo = Utils.GetNameOf(() => ImageResources.Logo16x16);
                }

                // open requested menu
                _popup = new YamuiMenu {
                    HtmlTitle        = "<div class='contextMenuTitle'><img src='" + menuLogo + "' width='16' Height='16' style='padding-right: 5px; padding-top: 1px;'>" + menuTitle + "</span>",
                    SpawnLocation    = Cursor.Position,
                    MenuList         = menuList,
                    DisplayNbItems   = true,
                    DisplayFilterBox = true,
                    FormMinSize      = new Size(minWidth, 0)
                };
                if (!showAtCursor)
                {
                    _popup.ParentWindowRectangle = WinApi.GetWindowRect(Npp.CurrentSci.Handle);
                }
                _popup.YamuiList.ShowTreeBranches = Config.Instance.ShowTreeBranches;
                _popup.ClicItemWrapper            = item => {
                    if (item.OnClic != null)
                    {
                        try {
                            item.OnClic(item);
                        } catch (Exception e) {
                            ErrorHandler.ShowErrors(e, "Error in : " + item.DisplayText);
                        }
                    }
                };
                _popup.Show(Npp.Win32Handle);
            } catch (Exception e) {
                ErrorHandler.ShowErrors(e, "Error in ShowMenuAtCursor");
            }
        }
Пример #5
0
        /// <summary>
        /// displays the popup form
        /// </summary>
        private void DisplayPopup(string initialString)
        {
            if (_listItems != null && _listItems.Count > 0)
            {
                var displayFilterBox = !string.IsNullOrEmpty(initialString) || _listItems.Count > 15;

                // correct default selected
                foreach (var item in _listItems)
                {
                    item.IsSelectedByDefault = item.Index == SelectedIndex;
                }

                var spawnPt = PointToScreen(new Point());
                spawnPt.Offset(0, displayFilterBox ? 0 : Height);
                _listPopup = new YamuiMenu {
                    SpawnLocation            = spawnPt,
                    MenuList                 = _listItems.Cast <YamuiMenuItem>().ToList(),
                    DisplayFilterBox         = displayFilterBox,
                    Resizable                = false,
                    Movable                  = false,
                    FormMinSize              = new Size(Width, 0),
                    AutocompletionLineHeight = (displayFilterBox ? -1 : 1) * Height,
                    InitialFilterString      = initialString
                };

                // on popup clic
                _listPopup.ClicItemWrapper = item => {
                    if (item != null)
                    {
                        SelectedIndex = ((YamuiComboItem)item).Index;
                        if (SelectedIndexChangedByUser != null)
                        {
                            SelectedIndexChangedByUser(this);
                        }
                    }
                    _listPopup.Close();
                    _listPopup.Dispose();
                };

                // show
                var owner = FindForm();
                if (owner != null)
                {
                    _listPopup.Show(new WindowWrapper(owner.Handle));
                }
                else
                {
                    _listPopup.Show();
                }

                _listPopup.YamuiList.IndexChanged += list => {
                    var item = list.SelectedItem;
                    if (item != null)
                    {
                        SelectedIndex = ((YamuiComboItem)item).Index;
                        if (SelectedIndexChangedByUser != null)
                        {
                            SelectedIndexChangedByUser(this);
                        }
                    }
                };
            }
        }