Esempio n. 1
0
        private void Autocomplete()
        {
            if (_multipleAutocompleteOptions)
            {
                _matchIndex++;
                if (_matchIndex == _matchesList.Count)
                {
                    _matchIndex = 0;
                }
                CommandTb.Text = _matchesList[_matchIndex] + " ";
                ChangeIcon();
            }
            else
            {
                if (CommandTb.Text.Split(' ').Length == 1)
                {
                    _matchesList = _autocompleteList.Where(x => x.ToLower().StartsWith(CommandTb.Text.ToLower()))
                                   .ToList();
                    _matchesList.Sort();
                    _matchesList = _matchesList.Distinct().ToList();
                    if (_matchesList.Count > 0)
                    {
                        CommandTb.Text = _matchesList[0] + " ";
                        ChangeIcon();
                        if (_matchesList.Count > 1)
                        {
                            _multipleAutocompleteOptions = true;
                            _matchIndex = 0;
                        }
                    }
                }
                else // Auto-completing an argument, not a command
                {
                    try
                    {
                        Command thisCommand = _validCommands[CommandTb.Text.Split(' ')[0]];
                        if (thisCommand.Name == "settings") // Autocomplete Settings args
                        {
                            string        argument  = CommandTb.Text.Split(' ')[1];
                            List <string> autoLines = File.ReadAllLines(_configPath + "ms-settings.txt")
                                                      .Where(settingLine => settingLine.Substring(12).StartsWith(argument.ToLower()))
                                                      .ToList();
                            // Only load into memory when needed, and it's not a large file - just a list of settings pages.
                            if (autoLines.Count > 0)
                            {
                                // Replace unfinished argument with full one
                                CommandTb.Text = CommandTb.Text.Split(' ')[0] + " " + autoLines[0].Substring(12);
                            }
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }

            CommandTb.Select(CommandTb.Text.Length, 0); // move cursor to end of text box
        }
Esempio n. 2
0
 private void Autocomplete()
 {
     if (MultipleAutocompleteOptions)
     {
         MatchIndex++;
         if (MatchIndex == MatchesList.Count)
         {
             MatchIndex = 0;
         }
         CommandTb.Text = MatchesList[MatchIndex] + " ";
     }
     else
     {
         if (CommandTb.Text.Split(' ').Length == 1)
         {
             MatchesList = AutocompleteList.Where(x => x.ToLower().StartsWith(CommandTb.Text.ToLower())).ToList();
             MatchesList.Sort();
             MatchesList = MatchesList.Distinct().ToList();
             if (MatchesList.Count > 0)
             {
                 CommandTb.Text = MatchesList[0] + " ";
                 changeIcon();
                 if (MatchesList.Count > 1)
                 {
                     MultipleAutocompleteOptions = true;
                     MatchIndex = 0;
                 }
             }
         }
         else // Autocompleting an argument, not a command
         {
             try
             {
                 Command thisCommand = ValidCommands[CommandTb.Text.Split(' ')[0]];
                 if (thisCommand.Name == "settings") // Autocomplete Settings args
                 {
                     String        argument  = CommandTb.Text.Split(' ')[1];
                     List <string> autoLines = System.IO.File.ReadAllLines(Properties.Settings.Default.SettingsPath + "ms-settings.txt").Where(settingLine => settingLine.Substring(12).StartsWith(argument.ToLower())).ToList <string>();
                     if (autoLines.Count > 0)
                     {
                         // Replace unfinished argument with full one
                         CommandTb.Text = CommandTb.Text.Split(' ')[0] + " " + autoLines[0].Substring(12);
                     }
                 }
             }
             catch { }
         }
     }
     CommandTb.Select(CommandTb.Text.Length, 0); // move cursor to end of textbox
 }