public void LoadSearch(SavedSearch search)
        {
            SavedSearch newSearch = search.Clone();

            currentSearch = newSearch.search;
            currentSearch.SetPath(Keys.SavedSearch);
            searchOptions = newSearch.options;
#if !PSR_FULL
            searchOptions.searchType = SearchType.Search;
#endif

            updateReplaceMode();
            PersistCurrentSearch();
        }
Beispiel #2
0
        protected override void drawItem(SavedSearch search, int index)
        {
            GUIStyle resultStyle = index % 2 == 0 ? SRWindow.resultStyle1 : SRWindow.resultStyle2;

            GUILayout.BeginHorizontal(resultStyle, GUILayout.Height(25.0f));
            if (GUILayout.Button("Overwrite", GUILayout.Width(100.0f)))
            {
                bool confirm = EditorUtility.DisplayDialog("Overwrite?", "Instead of saving a new search, this will overwrite the search '" + search.name + "'. Are you sure?", "Overwrite", "Cancel");
                if (confirm)
                {
                    searchToOverwrite = search;
                }
            }
            GUILayout.Label(search.name);
            GUILayout.EndHorizontal();
        }
Beispiel #3
0
        void OnGUI()
        {
            drawTop();

            scrollPosition = GUILayout.BeginScrollView(scrollPosition);

            for (int i = 0; i < parent.savedSearches.searches.Count; i++)
            {
                SavedSearch search = parent.savedSearches.searches[i];
                drawItem(search, i);
            }

            GUILayout.EndScrollView();
            drawBottom();
            cleanup();
        }
        public void MoveSearch(SavedSearch moveSearch, int moveSearchAmount)
        {
            SavedSearch ss = null;

            if (searchForIndex > 3)
            {
                ss = savedSearches.searches[searchForIndex - 4];
            }
            int index = savedSearches.searches.IndexOf(moveSearch);

            savedSearches.searches.Remove(moveSearch);
            index += moveSearchAmount;
            savedSearches.searches.Insert(index, moveSearch);
            if (searchForIndex > 3)
            {
                searchForIndex = savedSearches.searches.IndexOf(ss) + 4;
                EditorPrefs.SetInt(Keys.prefSearchFor, searchForIndex);
            }
        }
        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();
                }
            }
        }
        protected override void drawItem(SavedSearch search, int index)
        {
            GUIStyle resultStyle = index % 2 == 0 ? SRWindow.resultStyle1 : SRWindow.resultStyle2;

            GUILayout.BeginHorizontal(resultStyle, GUILayout.Height(25.0f));
            // bool loadSearch = GUILayout.Button(new GUIContent("", "Load"), SRWindow.load);
            // if(loadSearch)
            // {
            //   parent.LoadSearch(search);
            //   Close();
            // }
            if (editingSearch == search)
            {
                if (isRenaming)
                {
                    newName = GUILayout.TextField(newName);
                    if (GUILayout.Button("OK", GUILayout.Width(50.0f)))
                    {
                        if (newName == "")
                        {
                            EditorUtility.DisplayDialog("Blank Name", "The name cannot be left blank.", "OK");
                        }
                        else if (search.name == newName)
                        {
                            //same name....cancel.
                            isRenaming = false;
                        }
                        else if (searchNameExists(newName))
                        {
                            EditorUtility.DisplayDialog("Existing Search", "There is already a search named '" + newName + "'.", "OK");
                        }
                        else
                        {
                            editingSearch = null;
                            search.name   = newName;
                            isRenaming    = false;
                            searchesDirty = true;
                        }
                    }
                    if (GUILayout.Button("Cancel", GUILayout.Width(50.0f)))
                    {
                        isRenaming = false;
                    }
                }
                else
                {
                    GUILayout.Label(search.name, GUILayout.MaxWidth(400.0f));

                    if (GUILayout.Button(new GUIContent("", "Rename"), SRWindow.rename))
                    {
                        newName    = search.name;
                        isRenaming = true;
                    }
                    GUI.enabled = index != 0;
                    if (GUILayout.Button(new GUIContent("", "Move Up"), SRWindow.upArrow))
                    {
                        moveSearch       = search;
                        moveSearchAmount = -1;
                    }
                    GUI.enabled = true;

                    GUI.enabled = index != parent.savedSearches.searches.Count - 1;
                    if (GUILayout.Button(new GUIContent("", "Move Down"), SRWindow.downArrow))
                    {
                        moveSearch       = search;
                        moveSearchAmount = 1;
                    }
                    GUI.enabled = true;
                    if (GUILayout.Button(new GUIContent("", "Delete Search"), SRWindow.olMinusMinus))
                    {
                        bool confirm = EditorUtility.DisplayDialog("Delete?", "Are you sure you would like to delete the search '" + search.name + "'?", "Delete", "Cancel");
                        if (confirm)
                        {
                            deletedSearches.Add(search);
                        }
                    }
                    if (GUILayout.Button("Done", GUILayout.Width(40.0f)))
                    {
                        editingSearch = null;
                    }
                }
            }
            else
            {
                GUILayout.Label(search.name);
                if (GUILayout.Button(new GUIContent("", "More Options"), SRWindow.edit))
                {
                    editingSearch = search;
                }
            }
            GUILayout.Width(5.0f);
            GUILayout.EndHorizontal();
        }
Beispiel #7
0
 protected virtual void drawItem(SavedSearch search, int index)
 {
 }
 public void AddSearch(SavedSearch search)
 {
     searches.Insert(0, search);
     Persist();
 }