public static void OpenAssetInTab(string guid, int line) { foreach (FGCodeWindow codeWindow in codeWindows) { if (codeWindow.textEditor.targetGuid == guid) { codeWindow.Focus(); if (line >= 0) codeWindow.PingLine(line); return; } } string path = AssetDatabase.GUIDToAssetPath(guid); Object target = AssetDatabase.LoadAssetAtPath(path, typeof(MonoScript)) as MonoScript; if (target == null) { target = AssetDatabase.LoadAssetAtPath(path, typeof(TextAsset)) as TextAsset; if (target == null) { target = AssetDatabase.LoadAssetAtPath(path, typeof(Shader)) as Shader; if (target == null) return; } } FGCodeWindow newWindow = OpenNewWindow(target); if (newWindow != null && line >= 0) newWindow.PingLine(line); }
static void WaitForObjectPicker() { var objectPickerId = EditorGUIUtility.GetObjectPickerControlID(); if (objectPickerId == 0x51309) { selected = EditorGUIUtility.GetObjectPickerObject(); } else { EditorApplication.update -= WaitForObjectPicker; if (objectPickerId == 0 && selected != null) { var path = AssetDatabase.GetAssetPath(selected); if (path.StartsWith("Assets/", System.StringComparison.InvariantCultureIgnoreCase)) { var guid = AssetDatabase.AssetPathToGUID(path); FGCodeWindow.OpenAssetInTab(guid); } } selected = null; var pickerType = typeof(Editor).Assembly.GetType("UnityEditor.ObjectSelector", false, false); if (pickerType != null) { var pickers = Resources.FindObjectsOfTypeAll(pickerType); foreach (var picker in pickers) { Object.DestroyImmediate(picker); } } } }
private bool TryDockNextToSimilarTab(FGCodeWindow nextTo) { if (API.windowsField == null || API.mainViewField == null || API.panesField == null || API.addTabMethod == null) return false; System.Array windows = API.windowsField.GetValue(null, new object[0]) as System.Array; if (windows == null) return false; foreach (var window in windows) { var mainView = API.mainViewField.GetValue(window, new object[0]); System.Array allChildren = API.allChildrenField.GetValue(mainView, new object[0]) as System.Array; if (allChildren == null) continue; foreach (var view in allChildren) { if (view.GetType() != API.dockAreaType) continue; List<EditorWindow> panes = API.panesField.GetValue(view) as List<EditorWindow>; if (panes == null) continue; if (nextTo != null ? panes.Contains(nextTo) : panes.Find((EditorWindow pane) => pane is FGCodeWindow)) { API.addTabMethod.Invoke(view, new object[] { this }); return true; } } } return false; }
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); }
public override void OnInspectorGUI() { if (enableEditor) { textEditor.onRepaint = Repaint; textEditor.OnEnable(target); enableEditor = false; } if (Event.current.type == EventType.ValidateCommand) { if (Event.current.commandName == "ScriptInspector.AddTab") { Event.current.Use(); return; } } else if (Event.current.type == EventType.ExecuteCommand) { if (Event.current.commandName == "ScriptInspector.AddTab") { FGCodeWindow.OpenNewWindow(null, null, false); Event.current.Use(); return; } } DoGUI(); }
public static FGCodeWindow OpenNewWindow(Object target, FGCodeWindow nextTo, bool reuseExisting) { if (reuseExisting || target == null) { if (target == null) target = Selection.activeObject as MonoScript; if (target == null) target = Selection.activeObject as TextAsset; if (target == null) target = Selection.activeObject as Shader; if (target == null) return null; string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(target)); foreach (FGCodeWindow codeWindow in codeWindows) { if (codeWindow.textEditor.targetGuid == guid) { codeWindow.Focus(); return codeWindow; } } } useTargetAsset = target; FGCodeWindow window = ScriptableObject.CreateInstance<FGCodeWindow>(); useTargetAsset = null; if (!window.TryDockNextToSimilarTab(nextTo)) window.Show(); window.Focus(); return window; }
private static void OpenLogEntry(EditorWindow console) { var listView = consoleListViewField.GetValue(console); int listViewRow = listView != null ? (int)listViewStateRowField.GetValue(listView) : -1; if (listViewRow >= 0) { bool gotIt = false; startGettingEntriesMethod.Invoke(null, new object[0]); try { gotIt = (bool)getEntryMethod.Invoke(null, new object[] { listViewRow, logEntry }); } finally { endGettingEntriesMethod.Invoke(null, new object[0]); } if (gotIt) { int line = (int)logEntryLineField.GetValue(logEntry); string file = (string)logEntryFileField.GetValue(logEntry); string guid = null; if (file.StartsWith("Assets/")) { guid = AssetDatabase.AssetPathToGUID(file); if (string.IsNullOrEmpty(guid)) { int instanceID = (int)logEntryInstanceIDField.GetValue(logEntry); if (instanceID != 0) { file = AssetDatabase.GetAssetPath(instanceID); if (file.StartsWith("Assets/")) { guid = AssetDatabase.AssetPathToGUID(file); } } } } else { int instanceID = (int)logEntryInstanceIDField.GetValue(logEntry); if (instanceID != 0) { file = AssetDatabase.GetAssetPath(instanceID); if (file.StartsWith("Assets/")) { guid = AssetDatabase.AssetPathToGUID(file); } } } if (!string.IsNullOrEmpty(guid)) { FGCodeWindow.addRecentLocationForNextAsset = true; FGCodeWindow.OpenAssetInTab(guid, line); } } } }
private void GoToResult(int index) { if (currentItem >= results.Count) { return; } var result = (GroupByFile ? results : flatResults)[currentItem]; FGCodeWindow.OpenAssetInTab(result.assetGuid, result.line, result.characterIndex, result.length); }
public void CloseAndSwitch() { if (!instance) { return; } var guid = GetSelectedGUID(); Close(); DestroyImmediate(this); FGCodeWindow.OpenAssetInTab(guid); instance = null; }
internal static FindResultsWindow Create( string description, System.Action <System.Action <string, string, TextPosition, int>, string, SearchOptions> searchFunction, string[] assetGuids, SearchOptions searchOptions, bool inNewWindow) { var previousResults = (FindResultsWindow[])Resources.FindObjectsOfTypeAll(typeof(FindResultsWindow)); var reuseWnd = inNewWindow ? null : previousResults.FirstOrDefault(w => !w.KeepResults && w.replaceText == null); var wnd = reuseWnd ?? CreateInstance <FindResultsWindow>(); wnd.infoText = description; wnd.searchFunction = searchFunction; wnd.assetGuids = assetGuids; wnd.search = searchOptions; wnd.groupByFile = SISettings.groupFindResultsByFile; if (!reuseWnd) { var docked = false; foreach (var prevWnd in previousResults) { if (prevWnd != wnd && prevWnd) { docked = FGCodeWindow.DockNextTo(wnd, prevWnd); if (docked) { break; } } } if (!docked) { var console = FGConsole.FindInstance() ?? (Resources.FindObjectsOfTypeAll(FGConsole.consoleWindowType).FirstOrDefault() as EditorWindow); if (console) { docked = FGCodeWindow.DockNextTo(wnd, console); } } } wnd.ClearResults(); wnd.Show(); wnd.Focus(); return(wnd); }
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)); } }
static void WaitForObjectPicker() { var objectPickerId = EditorGUIUtility.GetObjectPickerControlID(); if (objectPickerId == 0x51309) { selected = EditorGUIUtility.GetObjectPickerObject() as TextAsset; } else { EditorApplication.update -= WaitForObjectPicker; if (objectPickerId == 0 && selected != null) { var path = AssetDatabase.GetAssetPath(selected); if (path.StartsWith("Assets/", System.StringComparison.InvariantCultureIgnoreCase)) { var guid = AssetDatabase.AssetPathToGUID(path); FGCodeWindow.OpenAssetInTab(guid); } } selected = null; } }
public void CloseAndSwitch() { FGCodeWindow.OpenAssetInTab(GetSelectedGUID()); Close(); DestroyImmediate(this); }
public static FGCodeWindow OpenNewWindow(Object target, FGCodeWindow nextTo) { return OpenNewWindow(target, nextTo, false); }
private void DoPopupMenu(EditorWindow console) { var listView = consoleListViewField.GetValue(console); int listViewRow = listView != null ? (int)listViewStateRowField.GetValue(listView) : -1; if (listViewRow < 0) { return; } string text = (string)consoleActiveTextField.GetValue(console); if (string.IsNullOrEmpty(text)) { return; } GenericMenu codeViewPopupMenu = new GenericMenu(); string[] lines = text.Split('\n'); foreach (string line in lines) { int atAssetsIndex = line.IndexOf("(at Assets/"); if (atAssetsIndex < 0) { continue; } int functionNameEnd = line.IndexOf('('); if (functionNameEnd < 0) { continue; } string functionName = line.Substring(0, functionNameEnd).TrimEnd(' '); int lineIndex = line.LastIndexOf(':'); if (lineIndex <= atAssetsIndex) { continue; } int atLine = 0; for (int i = lineIndex + 1; i < line.Length; ++i) { char c = line[i]; if (c < '0' || c > '9') { break; } atLine = atLine * 10 + (c - '0'); } atAssetsIndex += "(at ".Length; string assetPath = line.Substring(atAssetsIndex, lineIndex - atAssetsIndex); string scriptName = assetPath.Substring(assetPath.LastIndexOf('/') + 1); string guid = AssetDatabase.AssetPathToGUID(assetPath); if (!string.IsNullOrEmpty(guid)) { codeViewPopupMenu.AddItem( new GUIContent(scriptName + " - " + functionName.Replace(':', '.') + ", line " + atLine), false, () => { bool openInSI = (openLogEntriesInSi2 || SISettings.handleOpenAssets) && !SISettings.dontOpenAssets; if (EditorGUI.actionKey) { openInSI = !openInSI; } if (openInSI) { FGCodeWindow.addRecentLocationForNextAsset = true; FGCodeWindow.OpenAssetInTab(guid, atLine); } else { FGCodeWindow.openInExternalIDE = true; AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(assetPath), atLine); } }); } } if (codeViewPopupMenu.GetItemCount() > 0) { codeViewPopupMenu.AddSeparator(string.Empty); if (SISettings.handleOpenAssets || SISettings.dontOpenAssets) { codeViewPopupMenu.AddDisabledItem( new GUIContent("Open Call-Stack Entries in Script Inspector") ); } else { codeViewPopupMenu.AddItem( new GUIContent("Open Call-Stack Entries in Script Inspector"), openLogEntriesInSi2, () => { openLogEntriesInSi2 = !openLogEntriesInSi2; } ); } GUIUtility.hotControl = 0; codeViewPopupMenu.ShowAsContext(); GUIUtility.ExitGUI(); } }
private static void OpenLogEntry(EditorWindow console) { var listView = consoleListViewField.GetValue(console); int listViewRow = listView != null ? (int)listViewStateRowField.GetValue(listView) : -1; if (listViewRow >= 0) { bool gotIt = false; startGettingEntriesMethod.Invoke(null, new object[0]); try { gotIt = (bool)getEntryMethod.Invoke(null, new object[] { listViewRow, logEntry }); } finally { endGettingEntriesMethod.Invoke(null, new object[0]); } if (gotIt) { int line = (int)logEntryLineField.GetValue(logEntry); string file = (string)logEntryFileField.GetValue(logEntry); string guid = null; if (file.StartsWith("Assets/", System.StringComparison.OrdinalIgnoreCase)) { guid = AssetDatabase.AssetPathToGUID(file); if (string.IsNullOrEmpty(guid)) { int instanceID = (int)logEntryInstanceIDField.GetValue(logEntry); if (instanceID != 0) { file = AssetDatabase.GetAssetPath(instanceID); if (file.StartsWith("Assets/", System.StringComparison.OrdinalIgnoreCase)) { guid = AssetDatabase.AssetPathToGUID(file); } } } } else { int instanceID = (int)logEntryInstanceIDField.GetValue(logEntry); if (instanceID != 0) { file = AssetDatabase.GetAssetPath(instanceID); if (file.StartsWith("Assets/", System.StringComparison.OrdinalIgnoreCase)) { guid = AssetDatabase.AssetPathToGUID(file); } } } if (string.IsNullOrEmpty(guid)) { string text = (string)consoleActiveTextField.GetValue(console); if (!string.IsNullOrEmpty(text)) { string[] lines = text.Split('\n'); foreach (string textLine in lines) { int atAssetsIndex = textLine.IndexOf("(at Assets/"); if (atAssetsIndex < 0) { continue; } int lineIndex = textLine.LastIndexOf(':'); if (lineIndex <= atAssetsIndex) { continue; } line = 0; for (int i = lineIndex + 1; i < textLine.Length; ++i) { char c = textLine[i]; if (c < '0' || c > '9') { break; } line = line * 10 + (c - '0'); } atAssetsIndex += "(at ".Length; string assetPath = textLine.Substring(atAssetsIndex, lineIndex - atAssetsIndex); guid = AssetDatabase.AssetPathToGUID(assetPath); if (!string.IsNullOrEmpty(guid)) { break; } } } } if (!string.IsNullOrEmpty(guid)) { bool openInSI = (openLogEntriesInSi2 || SISettings.handleOpenAssets) && !SISettings.dontOpenAssets; if (EditorGUI.actionKey) { openInSI = !openInSI; } if (openInSI) { FGCodeWindow.addRecentLocationForNextAsset = true; FGCodeWindow.OpenAssetInTab(guid, line); } else { var assetPath = AssetDatabase.GUIDToAssetPath(guid); if (assetPath.StartsWith("Assets/", System.StringComparison.OrdinalIgnoreCase)) { FGCodeWindow.openInExternalIDE = true; AssetDatabase.OpenAsset(AssetDatabase.LoadMainAssetAtPath(assetPath), line); } } } } } }
private void DoPopupMenu(EditorWindow console) { var listView = consoleListViewField.GetValue(console); int listViewRow = listView != null ? (int)listViewStateRowField.GetValue(listView) : -1; if (listViewRow < 0) { return; } string text = (string)consoleActiveTextField.GetValue(console); if (string.IsNullOrEmpty(text)) { return; } GenericMenu codeViewPopupMenu = new GenericMenu(); string[] lines = text.Split('\n'); foreach (string line in lines) { int atAssetsIndex = line.IndexOf("(at Assets/"); if (atAssetsIndex < 0) { continue; } int functionNameEnd = line.IndexOf('('); if (functionNameEnd < 0) { continue; } string functionName = line.Substring(0, functionNameEnd).TrimEnd(' '); int lineIndex = line.LastIndexOf(':'); if (lineIndex <= atAssetsIndex) { continue; } int atLine = 0; for (int i = lineIndex + 1; i < line.Length; ++i) { char c = line[i]; if (c < '0' || c > '9') { break; } atLine = atLine * 10 + (c - '0'); } atAssetsIndex += "(at ".Length; string assetPath = line.Substring(atAssetsIndex, lineIndex - atAssetsIndex); string scriptName = assetPath.Substring(assetPath.LastIndexOf('/') + 1); string guid = AssetDatabase.AssetPathToGUID(assetPath); if (!string.IsNullOrEmpty(guid)) { codeViewPopupMenu.AddItem( new GUIContent(scriptName + " - " + functionName.Replace(':', '.') + ", line " + atLine), false, () => FGCodeWindow.OpenAssetInTab(guid, atLine)); } } if (codeViewPopupMenu.GetItemCount() > 0) { codeViewPopupMenu.ShowAsContext(); } }
private void OnGUI() { switch (Event.current.type) { case EventType.KeyDown: if ((Event.current.modifiers & ~EventModifiers.FunctionKey) == EventModifiers.Control && (Event.current.keyCode == KeyCode.PageUp || Event.current.keyCode == KeyCode.PageDown)) { SelectAdjacentCodeTab(Event.current.keyCode == KeyCode.PageDown); Event.current.Use(); GUIUtility.ExitGUI(); } else if (Event.current.alt && EditorGUI.actionKey) { if (Event.current.keyCode == KeyCode.RightArrow || Event.current.keyCode == KeyCode.LeftArrow) { if (Event.current.shift) { MoveThisTab(Event.current.keyCode == KeyCode.RightArrow); } else { SelectAdjacentCodeTab(Event.current.keyCode == KeyCode.RightArrow); } Event.current.Use(); GUIUtility.ExitGUI(); } } else if (!Event.current.alt && !Event.current.shift && EditorGUI.actionKey) { if (Event.current.keyCode == KeyCode.W || Event.current.keyCode == KeyCode.F4) { Event.current.Use(); FGCodeWindow codeTab = GetAdjacentCodeTab(false); if (codeTab == null) codeTab = GetAdjacentCodeTab(true); Close(); if (codeTab != null) codeTab.Focus(); } } //else if (!Event.current.alt && !Event.current.shift && EditorGUI.actionKey) //{ // if (Event.current.keyCode == KeyCode.M) // { // Event.current.Use(); // ToggleMaximized(); // GUIUtility.ExitGUI(); // } //} break; case EventType.DragUpdated: case EventType.DragPerform: if (DragAndDrop.objectReferences.Length > 0) { bool ask = false; HashSet<Object> accepted = new HashSet<Object>(); foreach (Object obj in DragAndDrop.objectReferences) { if (AssetDatabase.GetAssetPath(obj).EndsWith(".dll", System.StringComparison.OrdinalIgnoreCase)) continue; if (obj is MonoScript) accepted.Add(obj); else if (obj is TextAsset || obj is Shader) accepted.Add(obj); else if (obj is Material) { Material material = obj as Material; if (material.shader != null) { int shaderID = material.shader.GetInstanceID(); if (shaderID != 0) { if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(shaderID))) accepted.Add(material.shader); } } } else if (obj is GameObject) { GameObject gameObject = obj as GameObject; MonoBehaviour[] monoBehaviours = gameObject.GetComponents<MonoBehaviour>(); foreach (MonoBehaviour mb in monoBehaviours) { MonoScript monoScript = MonoScript.FromMonoBehaviour(mb); if (monoScript != null) { if (!string.IsNullOrEmpty(AssetDatabase.GetAssetPath(monoScript))) { accepted.Add(monoScript); ask = true; } } } } } if (accepted.Count > 0) { DragAndDrop.AcceptDrag(); DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (Event.current.type == EventType.DragPerform) { Object[] sorted = accepted.OrderBy((x) => x.name, System.StringComparer.OrdinalIgnoreCase).ToArray(); if (ask && sorted.Length > 1) { GenericMenu popupMenu = new GenericMenu(); foreach (Object target in sorted) { Object tempTarget = target; popupMenu.AddItem( new GUIContent("Open " + System.IO.Path.GetFileName(AssetDatabase.GetAssetPath(target))), false, () => { OpenNewWindow(tempTarget, this, true); }); } popupMenu.AddSeparator(""); popupMenu.AddItem( new GUIContent("Open All"), false, () => { foreach (Object target in sorted) OpenNewWindow(target, this); }); popupMenu.ShowAsContext(); } else { foreach (Object target in sorted) OpenNewWindow(target, this, sorted.Length == 1); } } Event.current.Use(); return; } } break; case EventType.ValidateCommand: if (Event.current.commandName == "ScriptInspector.AddTab") { Event.current.Use(); return; } break; case EventType.ExecuteCommand: if (Event.current.commandName == "ScriptInspector.AddTab") { Event.current.Use(); OpenNewWindow(targetAsset, this); return; } break; } wantsMouseMove = true; textEditor.OnWindowGUI(this, new RectOffset(0, 0, 19, 1)); }
private void SelectAdjacentCodeTab(bool right) { FGCodeWindow codeTab = GetAdjacentCodeTab(right); if (codeTab != null) codeTab.Focus(); }
private void OnGUI() { if (Event.current.isKey && TabSwitcher.OnGUIGlobal()) { return; } bool needsRepaint = false; if (Event.current.type == EventType.KeyDown) { var nextItem = currentItem; var results = GroupByFile ? this.results : flatResults; if (Event.current.keyCode == KeyCode.DownArrow) { ++nextItem; if (GroupByFile) { while (nextItem < results.Count && results[nextItem].description != null && collapsedPaths.Contains(results[nextItem].assetPath)) { ++nextItem; } } if (nextItem == results.Count) { nextItem = currentItem; } } else if (Event.current.keyCode == KeyCode.RightArrow && currentItem < results.Count) { if (results[currentItem].description == null && collapsedPaths.Contains(results[currentItem].assetPath)) { collapsedPaths.Remove(results[currentItem].assetPath); needsRepaint = true; } else { ++nextItem; } } else if (Event.current.keyCode == KeyCode.UpArrow) { --nextItem; if (GroupByFile) { while (nextItem > 0 && results[nextItem].description != null && collapsedPaths.Contains(results[nextItem].assetPath)) { --nextItem; } } } else if (Event.current.keyCode == KeyCode.LeftArrow && currentItem < results.Count) { if (results[currentItem].description == null) { collapsedPaths.Add(results[currentItem].assetPath); needsRepaint = true; } else if (GroupByFile) { while (results[nextItem].description != null) { --nextItem; } } else { --nextItem; } } else if (Event.current.keyCode == KeyCode.Home) { nextItem = 0; } else if (Event.current.keyCode == KeyCode.End) { nextItem = results.Count - 1; if (GroupByFile) { while (nextItem > 0 && results[nextItem].description != null && collapsedPaths.Contains(results[nextItem].assetPath)) { --nextItem; } } } nextItem = Mathf.Max(0, Mathf.Min(nextItem, results.Count - 1)); scrollToCurrentItem = scrollToCurrentItem || needsRepaint || nextItem != currentItem; needsRepaint = needsRepaint || nextItem != currentItem; currentItem = nextItem; if (Event.current.keyCode == KeyCode.Return || Event.current.keyCode == KeyCode.KeypadEnter || Event.current.keyCode == KeyCode.Space) { if (currentItem < results.Count) { Event.current.Use(); if (results[currentItem].description != null) { GoToResult(currentItem); } else { var path = results[currentItem].assetPath; if (collapsedPaths.Contains(path)) { collapsedPaths.Remove(path); } else { collapsedPaths.Add(path); } needsRepaint = true; } } } else if (needsRepaint) { Event.current.Use(); } if (needsRepaint) { needsRepaint = false; Repaint(); return; } } //if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape) //{ // Close(); // editor.OwnerWindow.Focus(); // return; //} if (evenItemStyle == null) { evenItemStyle = new GUIStyle("PR Label"); evenItemStyle.padding.top = 2; evenItemStyle.padding.bottom = 2; evenItemStyle.padding.left = 2; evenItemStyle.margin.right = 0; evenItemStyle.fixedHeight = 0; evenItemStyle.richText = false; evenItemStyle.stretchWidth = true; evenItemStyle.wordWrap = false; oddItemStyle = new GUIStyle(evenItemStyle); var evenBackground = (GUIStyle)"CN EntryBackEven"; var oddBackground = (GUIStyle)"CN EntryBackodd"; evenItemStyle.normal.background = evenBackground.normal.background; evenItemStyle.focused.background = evenBackground.normal.background; oddItemStyle.normal.background = oddBackground.normal.background; oddItemStyle.focused.background = oddBackground.normal.background; pingStyle = (GUIStyle)"PR Ping"; } var rcToolbar = new Rect(0f, 0f, Screen.width, 20f); GUI.Label(rcToolbar, GUIContent.none, EditorStyles.toolbar); GUILayout.BeginHorizontal(); GUILayout.Label(infoText, GUILayout.Height(20f), GUILayout.MinWidth(0f)); EditorGUILayout.Space(); GUILayout.Label(resultsCountText, GUILayout.Height(20f)); GUILayout.FlexibleSpace(); var newGroupByFile = GUILayout.Toggle(GroupByFile, "Group by File", EditorStyles.toolbarButton, GUILayout.Height(20f), GUILayout.ExpandHeight(true)); keepResults = GUILayout.Toggle(keepResults, "Keep Results", EditorStyles.toolbarButton, GUILayout.Height(20f), GUILayout.ExpandHeight(true)); EditorGUILayout.Space(); GUILayout.EndHorizontal(); if (newGroupByFile != GroupByFile) { var results = GroupByFile ? this.results : flatResults; GroupByFile = newGroupByFile; var newResults = GroupByFile ? this.results : flatResults; if (currentItem < results.Count) { var currentResult = results[currentItem]; if (currentResult.description == null) { currentResult = results[currentItem + 1]; } currentItem = Mathf.Max(0, newResults.IndexOf(currentResult)); } else { currentItem = 0; } needsRepaint = true; scrollToCurrentItem = true; } listViewHeight = Screen.height - rcToolbar.height - 20f; Vector2 scrollToPosition; try { scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); scrollToPosition = scrollPosition; EditorGUIUtility.SetIconSize(new Vector2(16f, 16f)); //resultsLock.EnterReadLock(); if (foundNoResults) { GUILayout.Label("No Results Found!"); } else { var currentPath = ""; bool isExpanded = true; int drawnItemIndex = 0; var results = GroupByFile ? this.results : flatResults; for (var i = 0; i < results.Count; ++i) { var result = results[i]; var itemStyle = (drawnItemIndex & 1) == 0 ? evenItemStyle : oddItemStyle; if (result.description != null && !isExpanded) { continue; } ++drawnItemIndex; var rc = GUILayoutUtility.GetRect(GUIContent.none, itemStyle, GUILayout.Height(21f), GUILayout.ExpandWidth(true)); if (Event.current.type == EventType.Repaint) { itemStyle.Draw(rc, GUIContent.none, false, false, i == currentItem, this == focusedWindow); } if (result.description == null) { currentPath = result.assetPath; isExpanded = !collapsedPaths.Contains(currentPath); var rcToggle = rc; rcToggle.xMax = 18f; bool expand = GUI.Toggle(rcToggle, isExpanded, GUIContent.none, EditorStyles.foldout); if (expand != isExpanded) { currentItem = i; if (expand && !isExpanded) { collapsedPaths.Remove(currentPath); } else if (!expand && isExpanded) { collapsedPaths.Add(currentPath); } needsRepaint = true; } } if (scrollToCurrentItem && i == currentItem && Event.current.type == EventType.Repaint) { if (rc.yMin < scrollPosition.y) { scrollToPosition.y = rc.yMin; needsRepaint = true; } else if (rc.yMax > scrollPosition.y + listViewHeight) { scrollToPosition.y = rc.yMax - listViewHeight; needsRepaint = true; } } if (rc.yMax < scrollPosition.y || rc.yMin > scrollPosition.y + listViewHeight) { continue; } if (Event.current.type == EventType.MouseDown && rc.Contains(Event.current.mousePosition)) { if (i == currentItem && Event.current.button == 0 && Event.current.clickCount == 2) { if (result.description == null) { if (collapsedPaths.Contains(result.assetPath)) { collapsedPaths.Remove(result.assetPath); } else { collapsedPaths.Add(result.assetPath); } needsRepaint = true; } else { FGCodeWindow.OpenAssetInTab(result.assetGuid, result.line, result.characterIndex, result.length); } } else if (Event.current.button == 1 && result.description == null) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Expand All"), false, () => { collapsedPaths.Clear(); }); menu.AddItem(new GUIContent("Collapse All"), false, () => { foreach (var r in results) { if (r.description == null) { collapsedPaths.Add(r.assetPath); } } }); menu.ShowAsContext(); } currentItem = i; needsRepaint = true; scrollToCurrentItem = true; Event.current.Use(); } GUIContent contentContent; int lineInfoLength = 0; if (result.description == null) { contentContent = new GUIContent(result.assetPath, AssetDatabase.GetCachedIcon(result.assetPath)); rc.xMin = 18f; } else { string lineInfo; if (GroupByFile) { lineInfo = (result.line + 1).ToString() + ": "; } else { lineInfo = System.IO.Path.GetFileName(result.assetPath) + '(' + (result.line + 1).ToString() + "): "; } lineInfoLength = lineInfo.Length; contentContent = new GUIContent(lineInfo + result.description); rc.xMin = 22f; } if (Event.current.type == EventType.Repaint) { if (result.description != null) { var dotContent = new GUIContent("."); var preContent = new GUIContent(contentContent.text.Substring(0, lineInfoLength + result.characterIndex - result.trimOffset) + '.'); var resultContent = new GUIContent('.' + contentContent.text.Substring(0, lineInfoLength + result.characterIndex + result.length - result.trimOffset) + '.'); var dotSize = itemStyle.CalcSize(dotContent); var preSize = itemStyle.CalcSize(preContent); preSize.x -= dotSize.x; var resultSize = itemStyle.CalcSize(resultContent); resultSize.x -= dotSize.x * 2f; var rcHighlight = new Rect(rc.x + preSize.x - 4f, rc.y + 2f, resultSize.x - preSize.x + 14f, rc.height - 4f); GUI.color = new Color(1f, 1f, 1f, 0.4f); pingStyle.Draw(rcHighlight, false, false, false, false); GUI.color = Color.white; } GUI.backgroundColor = Color.clear; itemStyle.Draw(rc, contentContent, false, false, i == currentItem, this == focusedWindow); GUI.backgroundColor = Color.white; } } } GUILayout.FlexibleSpace(); } finally { //resultsLock.ExitReadLock(); GUILayout.EndScrollView(); } if (Event.current.type == EventType.Repaint) { if (needsRepaint) { scrollToCurrentItem = false; scrollPosition = scrollToPosition; Repaint(); } else { scrollToCurrentItem = false; } } }
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); }
private void ReplaceAll() { Unsubscribe(); FGTextBuffer buffer = null; string guid = null; bool canEditAll = true; var canEditBuffers = new HashSet <FGTextBuffer>(); for (var i = flatResults.Count; i-- > 0;) { var result = flatResults[i]; if (!result.selected) { continue; } if (result.assetGuid != guid) { guid = result.assetGuid; buffer = FGTextBufferManager.GetBuffer(guid); if (buffer.IsLoading) { buffer.LoadImmediately(); } if (FGCodeWindow.CodeWindows.All(x => x.TargetAssetGuid != guid)) { var wnd = FGCodeWindow.OpenAssetInTab(guid); if (wnd) { wnd.OnFirstUpdate(); } } if (!buffer.TryEdit()) { canEditAll = false; } else { canEditBuffers.Add(buffer); } } } if (!canEditAll) { if (!EditorUtility.DisplayDialog("Replace", "Some assets are locked and cannot be edited!", "Continue Anyway", "Cancel")) { Close(); } } buffer = null; guid = null; var updatedLines = new HashSet <int>(); for (var i = flatResults.Count; i-- > 0;) { var result = flatResults[i]; if (!result.selected) { continue; } if (result.assetGuid != guid) { if (buffer != null) { foreach (var line in updatedLines) { buffer.UpdateHighlighting(line, line); } buffer.EndEdit(); FGTextBufferManager.AddBufferToGlobalUndo(buffer); updatedLines.Clear(); } guid = result.assetGuid; buffer = FGTextBufferManager.GetBuffer(guid); if (buffer != null) { if (canEditBuffers.Contains(buffer)) { buffer.BeginEdit("*Replace All"); } else { buffer = null; } } } if (buffer != null) { var from = new FGTextBuffer.CaretPos { line = result.line, characterIndex = result.characterIndex }; var to = new FGTextBuffer.CaretPos { line = result.line, characterIndex = result.characterIndex + result.length }; var insertAt = buffer.DeleteText(from, to); if (replaceText != "") { buffer.InsertText(insertAt, replaceText); } updatedLines.Add(result.line); } } if (buffer != null) { foreach (var line in updatedLines) { buffer.UpdateHighlighting(line, line); } buffer.EndEdit(); FGTextBufferManager.AddBufferToGlobalUndo(buffer); } FGTextBufferManager.RecordGlobalUndo(); Close(); }
private void DrawEventListener(Rect rect, int index, bool isactive, bool isfocused) { var element = listenersArray.GetArrayElementAtIndex(index); var propertyMethodName = element.FindPropertyRelative("m_MethodName"); bool isDefined = !string.IsNullOrEmpty(propertyMethodName.stringValue); MethodInfo method = null; if (isDefined && currentEvent != null) { try { rebuildMethod.Invoke(currentEvent, null); } catch {} persistentCallGroup = persistentCallsField.GetValue(currentEvent); var persistentCall = getListenerMethod.Invoke(persistentCallGroup, new object[] { index }); method = findMethodMethod.Invoke(currentEvent, new [] { persistentCall }) as MethodInfo; isDefined = false; if (method != null) { var declaringType = method.DeclaringType; if (declaringType != null) { var name = declaringType.Assembly.GetName().Name.ToLowerInvariant(); isDefined = name == "assembly-csharp" || name == "assembly-csharp-firstpass" || name == "assembly-csharp-editor" || name == "assembly-csharp-editor-firstpass"; } } } bool isDoubleClick = Event.current.type == EventType.MouseDown && Event.current.clickCount == 2 && rect.Contains(Event.current.mousePosition); Rect rc = rect; rc.y += 3f; rc.height = 15f; rc.xMin = rc.xMax - 21f; rc.width = 21f; rect.width -= 20f; if (originalCallback != null) { originalCallback(rect, index, isactive, isfocused); } if (isactive && isfocused && Event.current.type == EventType.KeyDown && Event.current.character == '\n') { isDoubleClick = true; } bool wasEnabled = GUI.enabled; GUI.enabled = isDefined; bool isButtonClick = GUI.Button(rc, "...", EditorStyles.miniButtonRight); if (isDefined && (isButtonClick || isDoubleClick && Event.current.type != EventType.Used)) { var declaringType = ReflectedTypeReference.ForType(method.DeclaringType).definition; if (declaringType != null) { var member = declaringType.FindName(method.IsSpecialName ? method.Name.Substring("set_".Length) : method.Name, 0, false); if (member != null) { List <SymbolDeclaration> declarations = null; var methodGroup = member as MethodGroupDefinition; if (member.kind == SymbolKind.MethodGroup && methodGroup != null) { var parameters = method.GetParameters(); foreach (var m in methodGroup.methods) { if (m.IsStatic) { continue; } var p = m.GetParameters() ?? new List <ParameterDefinition>(); if (p.Count != parameters.Length) { continue; } for (var i = p.Count; i-- > 0;) { var pType = p[i].TypeOf(); if (pType == null) { goto nextMethod; } var parameterType = ReflectedTypeReference.ForType(parameters[i].ParameterType).definition as TypeDefinitionBase; if (!pType.IsSameType(parameterType)) { goto nextMethod; } } // Yay! We found it :) declarations = m.declarations; if (declarations == null || declarations.Count == 0) { declarations = FGFindInFiles.FindDeclarations(m); if (declarations == null || declarations.Count == 0) { // Boo! Something went wrong. break; } } nextMethod: continue; } } else { // It's a property declarations = member.declarations; if (declarations == null || declarations.Count == 0) { declarations = FGFindInFiles.FindDeclarations(member); } } if (declarations != null && declarations.Count > 0) { foreach (var decl in declarations) { var node = decl.NameNode(); if (node == null || !node.HasLeafs()) { continue; } string cuPath = null; for (var scope = decl.scope; scope != null; scope = scope.parentScope) { var cuScope = scope as CompilationUnitScope; if (cuScope != null) { cuPath = cuScope.path; break; } } if (cuPath == null) { continue; } var cuObject = AssetDatabase.LoadAssetAtPath(cuPath, typeof(MonoScript)); if (cuObject == null) { continue; } var buffer = FGTextBufferManager.GetBuffer(cuObject); if (buffer == null) { continue; } // Declaration is valid! if (buffer.lines.Count == 0) { buffer.LoadImmediately(); } var span = buffer.GetParseTreeNodeSpan(node); EditorApplication.delayCall += () => { FGCodeWindow.OpenAssetInTab(AssetDatabase.AssetPathToGUID(cuPath), span.line + 1); }; } } } } } GUI.enabled = wasEnabled; }