static void Init()
        {
            // Get existing open window or if none, make a new one:
            SRWindow  window = (SRWindow)EditorWindow.GetWindow(typeof(SRWindow));
            Texture2D icon   = (Texture2D)findObject("com.eh.searchandreplace.icon");

            window.titleContent = new GUIContent("Search", icon);
            window.Show();
        }
Example #2
0
 void init()
 {
     if (sectionsHash.Count == 0)
     {
         icon = (Texture2D)SRWindow.findObject("psr_icon");
         foreach (SRHelpSection section in sections)
         {
             sectionsHash.Add(section.key, section);
             if (currentSection != null && section.key == currentSection.key)
             {
                 currentSection = section;
             }
         }
         titleContent = SRLoc.GUI("help.window.title");
     }
 }
Example #3
0
        protected override void drawTop()
        {
            GUILayout.Space(10.0f);
            string     labelStr = "Name your search below and it will show up in the dropdown. Searches remember all settings, including the scope and whether to search and replace.";
            GUIContent content  = new GUIContent(labelStr);
            float      height   = SRWindow.richTextStyle.CalcHeight(content, position.width);

            GUILayout.Label(content, SRWindow.richTextStyle, GUILayout.Height(height));

            string newName = EditorGUILayout.TextField("Save New Search", searchName);

            if (errorText != "")
            {
                GUILayout.Label(errorText);
            }
            if (newName != searchName)
            {
                searchName = newName;
            }
            if (GUILayout.Button("Save"))
            {
                if (searchName != "")
                {
                    if (searchNameExists(searchName))
                    {
                        bool confirm = EditorUtility.DisplayDialog("Overwrite?", "Instead of saving a new search, this will overwrite the search '" + searchName + "'. Are you sure?", "Overwrite", "Cancel");
                        if (confirm)
                        {
                            saveAndClose(searchName, parent.currentSearch, parent.searchOptions);
                        }
                    }
                    else
                    {
                        saveAndClose(searchName, parent.currentSearch, parent.searchOptions);
                    }
                }
                else
                {
                    errorText = "You must input a valid name.";
                }
            }
            GUILayout.Space(10.0f);
            SRWindow.Divider();
            GUILayout.Label("Overwrite Existing Search");
        }
        protected override void drawTop()
        {
            GUILayout.Space(10.0f);
            string labelStr = "";

            if (parent.savedSearches.searches.Count == 0)
            {
                labelStr = "You can save searches and use them again later. When you save searches, they will show up in the search dropdown. All search parameters will be saved.";
            }
            else
            {
                labelStr = "Select a search to edit. Searches remember all settings, including the scope and whether to search and replace.";
            }
            GUIContent content = new GUIContent(labelStr);
            float      height  = SRWindow.richTextStyle.CalcHeight(content, position.width);

            GUILayout.Label(content, SRWindow.richTextStyle, GUILayout.Height(height));

            GUILayout.Space(10.0f);
            SRWindow.Divider();
        }
        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();
                }
            }
        }
        void init()
        {
            if (searchOptions == null)
            {
                _initialized = false;
            }
            if (!_initialized)
            {
                _initialized      = true;
                Instance          = this;
                searchType        = new PopupData(0, new string[] { Keys.search, Keys.searchAndReplace }, Keys.prefSearchType, "");
                searchType.boxPad = 10;


                int replacePref = EditorPrefs.GetInt(Keys.prefSearchType, 0);
                replaceMode = replacePref == 0 ? false : true;

                searchForIndex = EditorPrefs.GetInt(Keys.prefSearchFor, 0);

                //This throws errors if done in Ctor! yay.
                searches          = new List <SearchItemSet>();
                searchesToPersist = new HashSet <SearchItemSet>();
                foreach (string searchKey in searchForOptions)
                {
                    SearchItemSet s = SearchItemSet.PopulateFromDisk(searchKey);
                    searches.Add(s);
                }
                SearchItemSet savedSearch = SearchItemSet.PopulateFromDisk(Keys.SavedSearch);
                searches.Add(savedSearch);

                searchOptions            = SearchOptions.PopulateFromDisk();
                searchOptions.searchType = replaceMode ? SearchType.SearchAndReplace : SearchType.Search;
                savedSearches            = SavedSearches.PopulateFromDisk();

                // now that we've loaded all potential searches, which one has the user
                // selected?
                if (searchForIndex < 3)
                {
                    currentSearch = searches[searchForIndex];
                }
                else
                {
                    // If the index is above, then we have a saved search selected. The fourth
                    // sis is the currently loaded saved search.
                    currentSearch = searches[3];
                }

                //EditorStyles does not exist in Constructor??
                richTextStyle          = new GUIStyle(EditorStyles.label);
                richTextStyle.richText = true;
                richTextStyle.wordWrap = true;

                searchBox         = new GUIStyle(EditorStyles.helpBox);
                searchBox.padding = new RectOffset(10, 10, 10, 10);

                searchBoxDragHighlight = new GUIStyle(EditorStyles.helpBox);
                searchBoxDragHighlight.normal.background = EditorGUIUtility.FindTexture("BoxCollider2D Icon");
                searchBoxDragHighlight.border            = new RectOffset(10, 10, 10, 10);
                searchBoxDragHighlight.padding           = new RectOffset(10, 10, 10, 10);

                searchInnerDepthBox         = new GUIStyle(EditorStyles.inspectorFullWidthMargins);
                searchInnerDepthBox.padding = new RectOffset(0, 0, 0, 0);

                resultsBox         = new GUIStyle(EditorStyles.helpBox);
                resultsBox.padding = new RectOffset(0, 0, 10, 10);

                divider            = new GUIStyle("box");
                divider.border.top = divider.border.bottom = 1;
                divider.margin.top = 10;

                dragDivider           = new GUIStyle();
                dragDivider.border    = new RectOffset(1, 1, 1, 1);
                dragDivider.margin    = new RectOffset(0, 0, 0, 0);
                dragDivider.alignment = TextAnchor.MiddleCenter;
                Texture2D thumbbg = (Texture2D)findObject(EditorGUIUtility.isProSkin ? "com.eh.searchandreplace.thumbbg" : "com.eh.searchandreplace.thumbbglight");
                dragDivider.normal.background = thumbbg;
                Texture2D thumbTex = (Texture2D)findObject("com.eh.searchandreplace.thumb");
                thumb = new GUIContent(thumbTex);

                dragDividerNormal = dragDivider.normal.background;

                plusButton            = new GUIStyle(GUI.skin.button);
                plusButton.margin.top = 2;

                toolbarButton             = new GUIStyle(EditorStyles.toolbarButton);
                toolbarButton.fixedHeight = 20;
                toolbarButton.padding     = new RectOffset(0, 0, 2, 2);

                resultStyle1        = new GUIStyle();
                resultStyle1.margin = new RectOffset(1, 1, 0, 0);
                float lightgray = EditorGUIUtility.isProSkin ? 0.22f : 0.8f;
                resultStyle1.normal.background = MakeTex(1, 1, new Color(lightgray, lightgray, lightgray));
                resultStyle2 = new GUIStyle();
                float gray = EditorGUIUtility.isProSkin ? 0.26f : 0.77f;
                resultStyle2.normal.background = MakeTex(1, 1, new Color(gray, gray, gray));
                resultStyle2.margin            = new RectOffset(1, 1, 0, 0);

                selectedStyle        = new GUIStyle();
                selectedStyle.margin = new RectOffset(1, 1, 0, 0);
                float selectGray = EditorGUIUtility.isProSkin ? 0.22f : 0.8f;
                float selectBlue = EditorGUIUtility.isProSkin ? 0.4f : 0.9f;
                selectedStyle.normal.background = MakeTex(1, 1, new Color(selectGray, selectBlue, selectGray));

                swapToggle                   = new GUIStyle();
                swapToggle.fixedWidth        = 15;
                swapToggle.fixedHeight       = 15;
                swapToggle.normal.background = (Texture2D)findObject("com.eh.swap");
                swapToggle.hover.background  = (Texture2D)findObject("com.eh.swap.hover");
                swapToggle.margin            = new RectOffset(0, 4, 2, 0);

                errorStyle = new GUIStyle();
                errorStyle.normal.background = EditorGUIUtility.FindTexture("d_console.erroricon.sml");
                errorStyle.fixedWidth        = 17;
                errorStyle.fixedHeight       = 15;
                errorStyle.margin            = new RectOffset(0, 0, 0, 0);
                errorStyle.padding           = new RectOffset(0, 0, 0, 0);

                olPlusPlus             = new GUIStyle((GUIStyle)"OL Plus");
                olPlusPlus.margin      = new RectOffset(0, 0, 2, 0);
                olPlusPlus.fixedWidth  = 15;
                olPlusPlus.fixedHeight = 15;

                olMinusMinus             = new GUIStyle((GUIStyle)"OL Minus");
                olMinusMinus.margin      = new RectOffset(0, 0, 2, 0);
                olMinusMinus.fixedWidth  = 15;
                olMinusMinus.fixedHeight = 15;

                optionsToggle = new GUIStyle();
                optionsToggle.normal.background   = (Texture2D)findObject("com.eh.options.normal");
                optionsToggle.onNormal.background = (Texture2D)findObject("com.eh.options.onNormal");
                optionsToggle.fixedWidth          = 15;
                optionsToggle.fixedHeight         = 15;

#if UNITY_2018_3_OR_NEWER
                prefabIcon = EditorGUIUtility.FindTexture("Prefab Icon");
#else
                prefabIcon = EditorGUIUtility.FindTexture("PrefabNormal Icon");
#endif
                scriptIcon = EditorGUIUtility.FindTexture("cs Script Icon");
#if UNITY_2018_3_OR_NEWER
                goIcon = EditorGUIUtility.FindTexture("UnityEngine/GameObject Icon");
#else
                goIcon = EditorGUIUtility.FindTexture("GameObject Icon");
#endif
                if (goIcon == null)
                {
                    goIcon = EditorGUIUtility.FindTexture("Prefab Icon");
                }
                materialIcon     = EditorGUIUtility.FindTexture("Material Icon");
                sceneAssetIcon   = EditorGUIUtility.FindTexture("SceneAsset Icon");
                viewToolZoomIcon = EditorGUIUtility.FindTexture("d_ViewToolZoom");
                Texture2D downArrowTex = (Texture2D)findObject("com.eh.down");
                downArrow        = new GUIStyle();
                downArrow.margin = new RectOffset(0, 0, 3, 0);

                downArrow.normal.background = downArrowTex;
                downArrow.fixedWidth        = 15;
                downArrow.fixedHeight       = 15;

                Texture2D upArrowTex = (Texture2D)findObject("com.eh.up");

                upArrow                   = new GUIStyle();
                upArrow.margin            = new RectOffset(0, 0, 3, 0);
                upArrow.normal.background = upArrowTex;
                upArrow.fixedWidth        = 15;
                upArrow.fixedHeight       = 15;

                edit                   = new GUIStyle();
                edit.margin            = new RectOffset(1, 4, 3, 0);
                edit.normal.background = (Texture2D)findObject("com.eh.edit");
                edit.fixedWidth        = 15;
                edit.fixedHeight       = 15;

                save                   = new GUIStyle();
                save.margin            = new RectOffset(1, 1, 3, 0);
                save.normal.background = (Texture2D)findObject("com.eh.save");
                save.fixedWidth        = 15;
                save.fixedHeight       = 15;

                rename                   = new GUIStyle();
                rename.margin            = new RectOffset(1, 1, 3, 0);
                rename.normal.background = (Texture2D)findObject("com.eh.rename");
                rename.fixedWidth        = 15;
                rename.fixedHeight       = 15;

                load                   = new GUIStyle();
                load.margin            = new RectOffset(1, 1, 3, 0);
                load.normal.background = (Texture2D)findObject("com.eh.load");
                load.fixedWidth        = 15;
                load.fixedHeight       = 15;

                loadSearch                   = new GUIStyle();
                loadSearch.margin            = new RectOffset(1, 5, 3, 0);
                loadSearch.normal.background = (Texture2D)findObject("com.eh.loadSearch");
                loadSearch.fixedWidth        = 15;
                loadSearch.fixedHeight       = 15;
            }
        }
Example #7
0
        public virtual void Draw()
        {
            GUIStyle resultStyle = alternate ? SRWindow.resultStyle1 : SRWindow.resultStyle2;

            if (Selected)
            {
                resultStyle = SRWindow.selectedStyle;
            }
            GUILayout.BeginHorizontal(resultStyle);
            string labelStr = "";
            string template = "";

            switch (actionTaken)
            {
            case SearchAction.Found:
                //search only.
                template = SRWindow.Instance.Compact() ? foundCompact : found;
                break;

            case SearchAction.Replaced:
                template = SRWindow.Instance.Compact() ? replacedCompact : replaced;
                break;

            case SearchAction.InstanceFound:
                template = SRWindow.Instance.Compact() ? instanceFoundCompact : instanceFound;
                break;

            case SearchAction.InstanceReplaced:
                template = SRWindow.Instance.Compact() ? instanceReplacedCompact : instanceReplaced;
                break;

            case SearchAction.InstanceNotReplaced:
                template = SRWindow.Instance.Compact() ? notReplacedCompact : notReplaced;
                break;

            case SearchAction.Error:
                template = SRWindow.Instance.Compact() ? errorTemplateCompact : errorTemplate;
                break;

            case SearchAction.NotFound:
                template = SRWindow.Instance.Compact() ? notFoundCompact : notFound;
                break;

            case SearchAction.AssetMissingScript:
                template = SRWindow.Instance.Compact() ? assetMissingScriptCompact : assetMissingScript;
                break;

            case SearchAction.RanScript:
                template = SRWindow.Instance.Compact() ? ranScriptCompact : ranScript;
                break;

            default:
                template = unknown;
                break;
            }
            labelStr = format(template);
            float      width   = SRWindow.Instance.position.width - 80;
            GUIContent content = new GUIContent(labelStr);
            float      height  = SRWindow.richTextStyle.CalcHeight(content, width);

            EditorGUILayout.SelectableLabel(labelStr, SRWindow.richTextStyle, GUILayout.Height(height));
            Texture2D icon = SRWindow.prefabIcon;

            if (pathInfo.objID.isSceneObject)
            {
                icon = SRWindow.goIcon;
            }
            if (GUILayout.Button(icon, new GUILayoutOption[] { GUILayout.Width(30), GUILayout.Height(20) }))
            {
                Event e             = Event.current;
                bool  openInProject = e.shift;
                resultSet.Select(this, openInProject, SRWindow.metaKeyDown(e));
            }
            GUILayout.EndHorizontal();
        }