示例#1
0
        public IEnumerable <CommandInfo> ActionByMatch(params string[] searchTerms)
        {
            if (DebugLog)
            {
                Debug.Log("Searching for actions.. " + EditorApplication.timeSinceStartup);
            }

            if (searchTerms.Length > 0 && searchTerms.Any(_ => !_.IsNullOrEmpty()))
            {
                List <CommandInfo> foundCommands = new List <CommandInfo>(CommandsByName.Count);

                IEnumerable <string> firstSearch;

                //not dependent on the option right now (performance satisfying)

                /*    if (MonKeyInternalSettings.Instance.UseAdvancedFuzzySearch)
                 *  {*/
                firstSearch = CommandNames.Where(_ =>
                {
                    if (!_.ToLower().Contains(searchTerms[0]))
                    {
                        var x = StringExt.MatchResultSet(new List <string> {
                            _.ToLower()
                        }, searchTerms[0]);
                        return(x.Count > 0);
                    }

                    return(true);
                });

                firstSearch = CommandNames;

                firstSearch = StringExt.OrderStringsBySearchScore(firstSearch, true, searchTerms)
                              .ThenBy(_ => !CommandsByName[_].HasQuickName)
                              .ThenBy(_ => CommandsByName[_].CommandOrder);

                /*  }
                 * else
                 * {
                 *    firstSearch = StringExt.OrderStringsBySearchScore(CommandsByName.Keys, false, searchTerms)
                 *        .ThenBy(_ => !CommandsByName[_].HasQuickName)
                 *        .ThenBy(_ => CommandsByName[_].CommandOrder);
                 * }*/


                foreach (var name in firstSearch)
                {
                    if (!foundCommands.Contains(CommandsByName[name]) &&
                        IsCommandAuthorized(CommandsByName[name]))
                    {
                        foundCommands.Add(CommandsByName[name]);
                    }
                }

                if (DebugLog)
                {
                    Debug.Log("Search done! " + EditorApplication.timeSinceStartup);
                }

                FindByAliases(searchTerms, foundCommands);

                if (foundCommands.Count > 0)
                {
                    if (MonKeyInternalSettings.Instance.PutInvalidCommandAtEndOfSearch)
                    {
                        return(foundCommands.OrderByDescending(_ => !_.HasValidation ||
                                                               _.IsValid));
                    }

                    return(foundCommands.Take(MaxCommandShown));
                }
            }
            return(new CommandInfo[0]);
        }