示例#1
0
        private void    RefreshResult(bool limitResults = true)
        {
            if (NGSpotlightWindow.UpdatingResult != null)
            {
                NGSpotlightWindow.UpdatingResult();
            }

            ++this.changeCount;
            this.results.Clear();
            this.weight.Clear();

            this.error.Clear();
            this.cleanLowerKeywords = string.Empty;

            string filter = this.ExtractFilterInKeywords();

            if (this.keywords.Length > 0 && this.keywords[0] == ':')
            {
                this.UpdateAvailableFilters();

                if (filter != null)
                {
                    if (this.IdentifyFilter(filter) == true)
                    {
                        this.keywords = string.Empty;
                        this.RefreshResult();
                        GUI.FocusControl(null);
                        this.focusTextfieldOnce = false;
                        this.Repaint();
                    }
                    else
                    {
                        this.error.Add("Filter not recognized with \"" + filter + "\".");
                    }
                }

                return;
            }

            SpotlightSettings settings = HQ.Settings != null?HQ.Settings.Get <SpotlightSettings>() : null;

            int  maxResult = limitResults == true && settings != null ? settings.maxResult : int.MaxValue;
            bool keepResultsWithPartialMatch = settings != null ? settings.keepResultsWithPartialMatch : true;

            if (this.keywords.Length == 0 && this.filterInstances.Count > 0)
            {
                foreach (var registry in NGSpotlightWindow.entries)
                {
                    for (int i = 0; i < registry.Value.Count; i++)
                    {
                        if (registry.Value[i] == null)
                        {
                            continue;
                        }

                        int j      = 0;
                        int family = 0;

                        // At least one level 0 filter must filter it in.
                        for (; j < this.filterInstances.Count; j++)
                        {
                            if (this.filterInstances[j].FilterLevel == 0 && this.filterInstances[j].CheckFilterIn(this, registry.Value[i]) == true)
                            {
                                family |= this.filterInstances[j].FamilyMask;
                            }
                        }

                        if (family == 0)
                        {
                            continue;
                        }

                        j = 0;

                        for (; j < this.filterInstances.Count; j++)
                        {
                            if ((family & this.filterInstances[j].FamilyMask) != 0)
                            {
                                if (this.filterInstances[j].FilterLevel > 0 && this.filterInstances[j].CheckFilterIn(this, registry.Value[i]) == false)
                                {
                                    break;
                                }
                            }
                        }

                        if (j < this.filterInstances.Count)
                        {
                            continue;
                        }

                        if (this.results.Count < maxResult)
                        {
                            this.results.Add(new EntryRef()
                            {
                                key = registry.Key, i = i
                            });
                        }
                        else
                        {
                            return;
                        }
                    }
                }
            }
            else if (this.keywords.Length > 0)
            {
                string lowerKeywords = this.keywords.ToLower();
                this.cleanLowerKeywords = lowerKeywords;

                if (filter != null)
                {
                    this.cleanLowerKeywords = lowerKeywords.Substring(filter.Length);
                }

                // Custom implementation of fuzzy search.
                foreach (var registry in NGSpotlightWindow.entries)
                {
                    for (int i = 0; i < registry.Value.Count; i++)
                    {
                        if (registry.Value[i] == null)
                        {
                            continue;
                        }

                        if (this.filterInstances.Count > 0)
                        {
                            int j      = 0;
                            int family = 0;

                            // At least one level 0 filter must filter it in.
                            for (; j < this.filterInstances.Count; j++)
                            {
                                if (this.filterInstances[j].FilterLevel == 0 && this.filterInstances[j].CheckFilterIn(this, registry.Value[i]) == true)
                                {
                                    family |= this.filterInstances[j].FamilyMask;
                                }
                            }

                            if (family == 0)
                            {
                                continue;
                            }

                            j = 0;

                            for (; j < this.filterInstances.Count; j++)
                            {
                                if ((family & this.filterInstances[j].FamilyMask) != 0)
                                {
                                    if (this.filterInstances[j].FilterLevel > 0 && this.filterInstances[j].CheckFilterIn(this, registry.Value[i]) == false)
                                    {
                                        break;
                                    }
                                }
                            }

                            if (j < this.filterInstances.Count)
                            {
                                continue;
                            }
                        }

                        int weight;

                        if (this.WeightContent(keepResultsWithPartialMatch, registry.Value[i].LowerStringContent, this.cleanLowerKeywords, out weight) == true)
                        {
                            int k = 0;

                            for (; k < this.weight.Count; k++)
                            {
                                if (weight < this.weight[k])
                                {
                                    this.weight.Insert(k, weight);
                                    this.results.Insert(k, new EntryRef()
                                    {
                                        key = registry.Key, i = i
                                    });
                                    break;
                                }
                            }

                            if (k == this.weight.Count && this.results.Count < maxResult)
                            {
                                this.results.Add(new EntryRef()
                                {
                                    key = registry.Key, i = i
                                });
                                this.weight.Add(weight);
                            }
                            else if (this.results.Count > maxResult)
                            {
                                this.results.RemoveAt(this.results.Count - 1);
                                this.weight.RemoveAt(this.weight.Count - 1);
                            }
                        }
                    }
                }
            }
        }