Exemplo n.º 1
0
        /// <summary>
        ///     Auto complete a player name or command (if there's 1 option) or show a list of possibilities
        /// </summary>
        private void AutoComplete()
        {
            if (string.IsNullOrEmpty(Text))
            {
                return;
            }

            string text = (Text.Contains(' ')) ? Text.Split(' ').Last() : Text;

            string             result      = "";
            AutoCompletionMenu contextMenu = null;

            int matches = 0;

            foreach (string command in getAutoCompleteContent())
            {
                // evaluate the lowercase, but don't alter the case for completion
                if (!command.ToLower().StartsWith(text.ToLower()))
                {
                    continue;
                }

                if (matches == 0)                 // nothing found yet (first found item)
                {
                    result = command;
                }
                else if (matches == 1)                 // this is our second hit, create a list
                {
                    contextMenu = new AutoCompletionMenu();
                    contextMenu.MenuItems.Add(result, AutoCompleteFromContextMenu);
                    contextMenu.MenuItems.Add(command, AutoCompleteFromContextMenu);
                }
                else                  // third or later hit, append existing list
                {
                    contextMenu.MenuItems.Add(command, AutoCompleteFromContextMenu);
                }
                matches++;
            }

            // exactly one match. Change the text.
            if (matches == 1)
            {
                Text = Text.Substring(0, Text.Length - text.Length) + result;
                Select(Text.Length, 0);
                return;                 // we're done, auto complete name
            }

            // show a contextmenu
            if (matches > 1)
            {
                ContextMenu = contextMenu;
                ContextMenu.Show(this, new Point(0, Height));
                ContextMenu.Collapse += ((sender, args) => ResetContextMenu());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Auto complete a player name or command (if there's 1 option) or show a list of possibilities
        /// </summary>
        private void AutoComplete()
        {
            if (string.IsNullOrEmpty(Text)) return;

            string text = (Text.Contains(' ')) ? Text.Split(' ').Last() : Text;

            string result = "";
            AutoCompletionMenu contextMenu = null;

            int matches = 0;

            foreach (string command in getAutoCompleteContent())
            {
                // evaluate the lowercase, but don't alter the case for completion
                if (!command.ToLower().StartsWith(text.ToLower())) continue;

                if (matches == 0) // nothing found yet (first found item)
                {
                    result = command;
                }
                else if (matches == 1) // this is our second hit, create a list
                {
                    contextMenu = new AutoCompletionMenu();
                    contextMenu.MenuItems.Add(result, AutoCompleteFromContextMenu);
                    contextMenu.MenuItems.Add(command, AutoCompleteFromContextMenu);
                }
                else  // third or later hit, append existing list
                {
                    contextMenu.MenuItems.Add(command, AutoCompleteFromContextMenu);
                }
                matches++;
            }

            // exactly one match. Change the text.
            if (matches == 1)
            {
                Text = Text.Substring(0, Text.Length - text.Length) + result;
                Select(Text.Length, 0);
                return; // we're done, auto complete name
            }

            // show a contextmenu
            if (matches > 1)
            {
                ContextMenu = contextMenu;
                ContextMenu.Show(this, new Point(0, Height));
                ContextMenu.Collapse += ((sender, args) => ResetContextMenu());
            }
        }