Exemplo n.º 1
0
        public static TabSwitcher Create(bool selectNext)
        {
            if (trueFocusedWindow)
            {
                trueFocusedWindow.Focus();
                trueFocusedWindow = null;
            }

            guids = FGCodeWindow.GetGuidHistory();
            if (guids.Count == 0)
            {
                return(null);
            }

            items = new GUIContent[guids.Count];
            for (var i = 0; i < items.Length; ++i)
            {
                var path       = AssetDatabase.GUIDToAssetPath(guids[i]);
                var textBuffer = FGTextBufferManager.TryGetBuffer(path);
                var fileName   = System.IO.Path.GetFileName(path);
                var name       = textBuffer != null && textBuffer.IsModified ? "*" + fileName : fileName;
                items[i] = new GUIContent(name, AssetDatabase.GetCachedIcon(path), path);
            }
            selected = selectNext ? (items.Length > 1 ? 1 : 0) : items.Length - 1;
            if (!(EditorWindow.focusedWindow is FGCodeWindow))
            {
                selected = 0;
            }

            var numRows = Mathf.Min(items.Length, 10);
            var height  = itemHeight * numRows;
            var width   = lastWidth;

            owner = EditorWindow.focusedWindow;
            var  center   = owner.position.center;
            Rect position = new Rect((int)(center.x - 0.5f * width), (int)(center.y - height * 0.5f), width, height);

            var window = CreatePopup <TabSwitcher>();

            window.hideFlags = HideFlags.HideAndDontSave;

#if UNITY_4_0 || UNITY_4_1 || UNITY_4_2 || UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0
            window.title = "";
#else
            window.titleContent.text = "";
#endif
            window.minSize = Vector2.one;

            window.position       = position;
            window.wantsMouseMove = false;
            window.ShowPopup();
            //window.Repaint();
            //window.Focus();

            //if (window.owner != null)
            //	window.owner.Focus();

            EditorApplication.modifierKeysChanged += window.OnModifierKeysChanged;
            return(window);
        }
Exemplo n.º 2
0
        static void Si3_OpenFile()
        {
            var restoreFocusedWindow = EditorWindow.focusedWindow;

            var projectDir  = Application.dataPath;
            var currentDir  = projectDir;
            var guidHistory = FGCodeWindow.GetGuidHistory();

            if (guidHistory.Count >= 1)
            {
                var lastAssetPath = AssetDatabase.GUIDToAssetPath(guidHistory[0]);
                currentDir = System.IO.Path.GetDirectoryName(lastAssetPath);
            }

            try
            {
                var open = EditorUtility.OpenFilePanel("Open in Script Inspector", currentDir,
#if UNITY_EDITOR_OSX
                                                       "");
#else
                                                       "cs;*.js;*.boo;*.shader;*.txt");
#endif
                if (!string.IsNullOrEmpty(open))
                {
                    if (open.StartsWith(projectDir, System.StringComparison.InvariantCultureIgnoreCase))
                    {
                        open = open.Substring(projectDir.Length - "Assets".Length);
                        var guid = AssetDatabase.AssetPathToGUID(open);
                        FGCodeWindow.OpenAssetInTab(guid);
                    }
                }
                else if (restoreFocusedWindow)
                {
                    restoreFocusedWindow.Focus();
                }
            }
            finally
            {
                System.IO.Directory.SetCurrentDirectory(projectDir.Substring(0, projectDir.Length - "/Assets".Length));
            }
        }
Exemplo n.º 3
0
        public FindResultsWindow ListAllResults()
        {
            string[] allTextAssetGuids;
            var      lookInOption = this.lookInOption;

            if (lookForOption == FindReplace_LookFor.AllAssets ||
                lookForOption == FindReplace_LookFor.Shaders ||
                lookForOption == FindReplace_LookFor.TextAssets)
            {
                if (lookInOption > FindReplace_LookIn.CurrentTabOnly)
                {
                    lookInOption = FindReplace_LookIn.WholeProject;
                }
            }

            if (lookInOption == FindReplace_LookIn.OpenTabsOnly)
            {
                allTextAssetGuids = (from w in FGCodeWindow.CodeWindows select w.TargetAssetGuid).Distinct().ToArray();
            }
            else if (lookInOption == FindReplace_LookIn.CurrentTabOnly)
            {
                allTextAssetGuids = new [] { editor != null ? editor.targetGuid : FGCodeWindow.GetGuidHistory().FirstOrDefault() };
            }
            else if (lookInOption != FindReplace_LookIn.WholeProject &&
                     lookForOption != FindReplace_LookFor.AllAssets &&
                     lookForOption != FindReplace_LookFor.Shaders &&
                     lookForOption != FindReplace_LookFor.TextAssets)
            {
                if (FGFindInFiles.assets != null)
                {
                    FGFindInFiles.assets.Clear();
                }

                if (lookInOption == FindReplace_LookIn.FirstPassGameAssemblies || lookInOption == FindReplace_LookIn.AllGameAssemblies)
                {
                    if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpFirstPass);
                    }
                    if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptFirstPass);
                    }
                    if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooFirstPass);
                    }
                }
                if (lookInOption == FindReplace_LookIn.GameAssemblies || lookInOption == FindReplace_LookIn.AllGameAssemblies)
                {
                    if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharp);
                    }
                    if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScript);
                    }
                    if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.Boo);
                    }
                }
                if (lookInOption == FindReplace_LookIn.FirstPassEditorAssemblies || lookInOption == FindReplace_LookIn.AllEditorAssemblies)
                {
                    if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpEditorFirstPass);
                    }
                    if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptEditorFirstPass);
                    }
                    if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooEditorFirstPass);
                    }
                }
                if (lookInOption == FindReplace_LookIn.EditorAssemblies || lookInOption == FindReplace_LookIn.AllEditorAssemblies)
                {
                    if (lookForOption == FindReplace_LookFor.CSharpScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.CSharpEditor);
                    }
                    if (lookForOption == FindReplace_LookFor.JSScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.UnityScriptEditor);
                    }
                    if (lookForOption == FindReplace_LookFor.BooScripts || lookForOption == FindReplace_LookFor.AllScriptTypes)
                    {
                        FGFindInFiles.FindAllAssemblyScripts(AssemblyDefinition.UnityAssembly.BooEditor);
                    }
                }

                allTextAssetGuids = FGFindInFiles.assets.ToArray();
            }
            else
            {
                allTextAssetGuids = FGFindInFiles.FindAllTextAssets().ToArray();

                IEnumerable <string> realTextAssets = null;
                switch (lookForOption)
                {
                case FindReplace_LookFor.AllAssets:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where !ignoreFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
                        select guid;
                    break;

                case FindReplace_LookFor.AllScriptTypes:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where scriptFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
                        select guid;
                    break;

                case FindReplace_LookFor.CSharpScripts:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".cs"
                        select guid;
                    break;

                case FindReplace_LookFor.JSScripts:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".js"
                        select guid;
                    break;

                case FindReplace_LookFor.BooScripts:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()) == ".boo"
                        select guid;
                    break;

                case FindReplace_LookFor.Shaders:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where shaderFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
                        select guid;
                    break;

                case FindReplace_LookFor.TextAssets:
                    realTextAssets =
                        from guid in allTextAssetGuids
                        where !nonTextFileTypes.Contains(Path.GetExtension(AssetDatabase.GUIDToAssetPath(guid).ToLowerInvariant()))
                        select guid;
                    break;
                }

                allTextAssetGuids = realTextAssets.ToArray();
            }

            if (allTextAssetGuids.Length == 0 || allTextAssetGuids.Length == 1 && allTextAssetGuids[0] == null)
            {
                Debug.LogWarning("No asset matches selected searching scope!");
                return(null);
            }

            var searchOptions = new FindResultsWindow.SearchOptions {
                text      = findText,
                matchCase = matchCase,
                matchWord = matchWholeWord,
            };

            FindResultsWindow resultsWindow = FindResultsWindow.Create(
                "Searching for '" + findText + "'...",
                FGFindInFiles.FindAllInSingleFile,
                allTextAssetGuids,
                searchOptions,
                isReplace ? "<b>Replace</b>" : listResultsInNewWindow ? "" : "Find Results");

            return(resultsWindow);
        }