Esempio n. 1
0
        void UpdateAutoCompleteListActual(bool isChain)
        {
            //float startTime = Time.realtimeSinceStartup;
            string startingAutoCompleteKey = autoCompleteKey;

            CompletionItem[] completionItems = new CompletionItem[0];
            if (startingAutoCompleteKey == ".")
            {
                startingAutoCompleteKey = "";
            }

            if (isChain)
            {
                completionItems = editor.syntaxRule.GetChainCompletionItems();
            }
            else
            {
                completionItems = editor.syntaxRule.GetGlobalCompletionItems();
            }

            //Debug.Log("AutoCompleteKey: "+startingAutoCompleteKey+" "+isChain);
            //Dictionary<string,,GameObject> bb;
            //bb = new Dictionary<string, UnityEngine.GameObject>
            List <UIDEFuzzySearchItem> inputItems = new List <UIDEFuzzySearchItem>();

            for (int i = 0; i < completionItems.Length; i++)
            {
                if (completionItems[i] == null)
                {
                    continue;
                }
                if (completionItems[i].displayName.Length == 0)
                {
                    continue;
                }
                char c = completionItems[i].displayName[0];
                if (!char.IsLetter(c) && c != '_')
                {
                    continue;
                }

                if (completionItems[i].isType || completionItems[i].isClassOrStruct)
                {
                    completionItems[i].name = completionItems[i].GetCompletionFriendlyName();
                }

                UIDEFuzzySearchItem fuzzyItem = new UIDEFuzzySearchItem();
                fuzzyItem.text       = CleanStringForSearch(completionItems[i].displayName);
                fuzzyItem.metaObject = completionItems[i];
                inputItems.Add(fuzzyItem);
            }

            UIDEFuzzySearchItem[] sortedFuzzyItems = UIDEFuzzySearch.GetSortedList(startingAutoCompleteKey, inputItems.ToArray(), false, false);

            List <CompletionItem> sortedCompletionItems = new List <CompletionItem>();

            //Type sorting
            CompletionItem      lastMetaItem  = null;
            UIDEFuzzySearchItem lastFuzzyItem = null;

            for (int i = 0; i < sortedFuzzyItems.Length; i++)
            {
                CompletionItem metaItem = (CompletionItem)sortedFuzzyItems[i].metaObject;
                if (lastFuzzyItem != null && lastFuzzyItem.score == sortedFuzzyItems[i].score)
                {
                    int compareValue = metaItem.Compare(lastMetaItem);
                    if (compareValue == 1)
                    {
                        sortedCompletionItems.Insert(i - 1, metaItem);
                    }
                    else
                    {
                        sortedCompletionItems.Add(metaItem);
                    }
                }
                else
                {
                    sortedCompletionItems.Add(metaItem);
                }
                lastMetaItem  = metaItem;
                lastFuzzyItem = sortedFuzzyItems[i];
            }

            int                   bestIndex = 0;
            UIDEHashTable         hashTable = new UIDEHashTable();
            List <CompletionItem> acItems   = new List <CompletionItem>();

            for (int i = 0; i < sortedCompletionItems.Count; i++)
            {
                //CompletionItem newItem = new CompletionItem();
                //newItem.fuzzyItem = items[i];

                CompletionItem existingItem = (CompletionItem)hashTable.Get(sortedCompletionItems[i].displayName);
                //if (existingItem != null) {
                //	existingItem.others.Add(newItem);
                //}
                //else {
                if (existingItem == null)
                {
                    hashTable.Set(sortedCompletionItems[i].displayName, sortedCompletionItems[i]);
                    acItems.Add(sortedCompletionItems[i]);
                }
                //selectedText
            }

            if (acItems.Count <= maxHeight)
            {
                List <CompletionItem> newACItems = new List <CompletionItem>();
                for (int i = 0; i < acItems.Count; i++)
                {
                    bool isInsert = (i % 2) == 0;
                    if (isInsert)
                    {
                        bestIndex++;
                        newACItems.Insert(0, acItems[i]);
                    }
                    else
                    {
                        newACItems.Add(acItems[i]);
                    }
                }
                acItems   = newACItems;
                bestIndex = Mathf.Max(bestIndex - 1, 0);
            }

            while (holdAutoCompleteUpdate)
            {
                Thread.Sleep(1);
            }

            itemList = acItems;

            selectedIndex = bestIndex;
            wantsFunishedUpdateAutoComplete = true;

            editor.editorWindow.Repaint();
            //Debug.Log(Time.realtimeSinceStartup-startTime);
        }