Пример #1
0
        void OnGUI()
        {
            init(); // dirty flag means this only runs once.
            Instance = this;
            float topViewPercent = searchJob == null ? 1.0f : dividePercentY;
            bool  canInteract    = searchJob == null || searchJob.SearchStatus != SearchStatus.InProgress;

            GUI.enabled    = canInteract;
            scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Height(position.height * topViewPercent));

            GUILayout.BeginHorizontal();
            CVS();

            Event e = Event.current;
            bool  searchWhilePlaying = !Application.isPlaying;

#if PSR_FULL
            searchWhilePlaying = true;
#endif
            if (e.type == EventType.KeyDown && searchWhilePlaying)
            {
                if (e.keyCode == KeyCode.Return && metaKeyDown(e) && !(e.shift))
                {
                    e.Use();
                    if (continueSearch())
                    {
                        doSearch();
                        return;//searching wipes the layout!!!
                    }
                }
                if (e.keyCode == KeyCode.Return && metaKeyDown(e) && e.shift && searchOptions.searchType == SearchType.SearchAndReplace)
                {
                    e.Use();
                    if (continueSearch())
                    {
                        doSearchAndReplace();
                        return;//searching wipes the layout!!!
                    }
                }
                if (e.keyCode == KeyCode.Backspace && metaKeyDown(e) && e.shift)
                {
                    e.Use();
                    searchJob = null;
                    return;//searching wipes the layout!!!
                }
            }

            GUILayout.BeginHorizontal();
            float lw = EditorGUIUtility.labelWidth;
            EditorGUIUtility.labelWidth = SRWindow.compactLabelWidth;
            List <GUIContent> searchLabels = new List <GUIContent>();
            //searchLabels.AddRange(searchForOptionLabels);
            foreach (string label in searchForOptionLabels)
            {
                searchLabels.Add(SRLoc.GUI(label));
            }
            searchLabels.Add(new GUIContent("------"));
            if (savedSearches.searches.Count > 0)
            {
                foreach (SavedSearch ss in savedSearches.searches)
                {
                    searchLabels.Add(new GUIContent(ss.name));
                }
                searchLabels.Add(new GUIContent("-------"));
                searchLabels.Add(new GUIContent("Edit Searches"));
            }
            searchLabels.Add(new GUIContent("Save Search"));
            int newSearchForIndex = EditorGUILayout.Popup(SRLoc.GUI("search.popup"), searchForIndex, searchLabels.ToArray());
            if (newSearchForIndex != searchForIndex)
            {
                if (newSearchForIndex == 3)
                {
                    // Ignore! This is a divider.
                }
                else
                {
                    if (newSearchForIndex < 3)
                    {
                        searchForIndex = newSearchForIndex;
                        EditorPrefs.SetInt(Keys.prefSearchFor, searchForIndex);
                        //search is one of the normal persistent searches.
                        currentSearch = searches[searchForIndex];
                    }
                    else
                    {
                        // either loading a search, or saving the current search.
                        if (newSearchForIndex == searchLabels.Count - 1)
                        {
                            //show save search window.
                            childWindow        = (SearchWindow)ScriptableObject.CreateInstance(typeof(SaveSearchWindow));
                            childWindow.parent = this;
                            childWindow.ShowUtility();
                        }
                        else if (newSearchForIndex == searchLabels.Count - 2)
                        {
                            childWindow        = (SearchWindow)ScriptableObject.CreateInstance(typeof(LoadSearchWindow));
                            childWindow.parent = this;
                            childWindow.ShowUtility();
                        }
                        else
                        {
                            int savedSearchIndex = newSearchForIndex - 4;
                            if (savedSearchIndex < savedSearches.searches.Count)
                            {
                                searchForIndex = newSearchForIndex;
                                EditorPrefs.SetInt(Keys.prefSearchFor, searchForIndex);
                                SavedSearch ss = savedSearches.searches[searchForIndex - 4];
                                LoadSearch(ss);
                            }
                        }
                    }
                }
            }

            EditorGUIUtility.labelWidth = lw; // i love stateful gui! :(

            updateSearchType();

            drawHelp();

            GUILayout.EndHorizontal();
            // GUILayout.BeginHorizontal();
            // GUILayout.EndHorizontal();

            CVE();

            GUILayout.EndHorizontal();
            // GUILayout.Space(10);
            GUILayout.BeginVertical();
            currentSearch.Draw(searchOptions);


            GUI.enabled = canInteract && currentSearch.CanSearch(searchOptions) && searchWhilePlaying; //NOTE: whether we can search while the application is playing is controlled by the search scope.
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            CVS();
            if (GUILayout.Button("Search", GUILayout.Width(200.0f)))
            {
                if (continueSearch())
                {
                    doSearch();
                    return; // We have to return immediately because all our guilayout is wiped
                }
            }
#if PSR_FULL
            GUI.enabled = canInteract && currentSearch.CanSearchAndReplace(searchOptions) && searchWhilePlaying; //NOTE: whether we can search while the application is playing is controlled by the search scope.

            if (searchOptions.searchType == SearchType.SearchAndReplace)
            {
                if (GUILayout.Button("Search And Replace", GUILayout.Width(200.0f)))
                {
                    if (continueSearch())
                    {
                        doSearchAndReplace();
                        return;
                    }
                }
            }
#endif

            GUI.enabled = canInteract;
            CVE();
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if (searchJob == null)
            {
                GUILayout.FlexibleSpace();

                GUILayout.BeginHorizontal();
                GUILayout.FlexibleSpace();

                GUILayout.EndHorizontal();
            }// else searchjob will draw it!

            GUILayout.EndVertical();


            GUILayout.EndScrollView();
            GUI.enabled = true;

            float dividerHeight = 7.0f;
            Color c             = GUI.backgroundColor;
            if (resizing)
            {
                GUI.color = Color.green;
            }
            if (GUILayout.RepeatButton(thumb, dragDivider, new GUILayoutOption[] { GUILayout.ExpandWidth(true), GUILayout.Height(dividerHeight) }))
            {
                resizing = true;
            }
            GUI.color = c;

            if (resizing)
            {
                float minSplitViewSize = 60.0f; // The smallest we will allow the 'split' to be sized.

                float maxY   = Mathf.Min(SRWindow.Instance.position.height - minSplitViewSize, Event.current.mousePosition.y);
                float mouseY = Mathf.Max(minSplitViewSize, maxY);
                mouseY        -= dividerHeight * 0.5f;
                dividePercentY = mouseY / SRWindow.Instance.position.height;
                Repaint();
                if (Event.current.type == EventType.Used)
                {
                    resizing = false;
                }
            }


            if (searchJob != null)
            {
                searchJob.Draw();
            }


            GUILayout.Space(10);

            if (persist)
            {
                persist = false;
                // currentSearch.Persist();
                foreach (SearchItemSet sis in searchesToPersist)
                {
                    sis.Persist();
                }
            }
        }