示例#1
0
        public override bool Show()
        {
            //! drop filter indexes because they are invalid on the second show if items have changed
            _ii       = null;
            _toFilter = true;

            // main loop
            for (int pass = 0; ; ++pass)
            {
                // filter
                MakeFilter();

                // filtered item number
                int nItem2 = _ii == null ? myItems.Count : _ii.Count;
                if (nItem2 < 2 && AutoSelect)
                {
                    if (nItem2 == 1)
                    {
                        Selected = _ii == null ? 0 : _ii[0];
                        return(true);
                    }
                    else if (pass == 0)
                    {
                        Selected = -1;
                        return(false);
                    }
                }

                // title, bottom
                GetInfo(out string title, out string info);

                // dialog
                var dialog = Far.Api.CreateDialog(1, 1, 1, 1);
                dialog.HelpTopic = string.IsNullOrEmpty(HelpTopic) ? "list-menu" : HelpTopic;
                dialog.NoShadow  = NoShadow;
                dialog.TypeId    = TypeId;

                // title
                dialog.AddBox(1, 1, 1, 1, title);

                // list
                _box            = dialog.AddListBox(1, 1, 1, 1, string.Empty);
                _box.Selected   = Selected;
                _box.SelectLast = SelectLast;
                _box.NoBox      = true;
                _box.WrapCursor = WrapCursor;
                if (IncrementalOptions == PatternOptions.None)
                {
                    _box.AutoAssignHotkeys = AutoAssignHotkeys;
                    _box.NoAmpersands      = !ShowAmpersands;
                }

                // "bottom"
                if (info.Length > 0)
                {
                    dialog.AddText(1, 1, 1, info);
                }

                // items and filter
                _box.ReplaceItems(myItems, _ii);

                // now we are ready to make sizes
                MakeSizes(dialog, Far.Api.UI.WindowSize);

                // handlers
                dialog.ConsoleSizeChanged += OnConsoleSizeChanged;
                _box.KeyPressed           += OnKeyPressed;

                // go!
                _toFilter  = _isKeyHandled = false;
                myKeyIndex = -1;
                bool ok = dialog.Show();
                if (!ok)
                {
                    return(false);
                }
                if (myKeyIndex == -2 || _toFilter)
                {
                    continue;
                }

                // correct by filter
                Selected = _box.Selected;
                if (_ii != null && Selected >= 0)
                {
                    Selected = _ii[Selected];
                }

                // call click if a key was not handled yet
                if (Selected >= 0 && !_isKeyHandled)
                {
                    var item = myItems[Selected];
                    if (item.Click != null)
                    {
                        var e = new MenuEventArgs(item);
                        item.Click(Sender ?? this, e);
                        if (e.Ignore || e.Restart)
                        {
                            continue;
                        }
                    }
                }

                //! empty + enter = -1
                return(Selected >= 0);
            }
        }