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 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; }
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; } }
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 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; }
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 void CloseAndSwitch() { FGCodeWindow.OpenAssetInTab(GetSelectedGUID()); Close(); DestroyImmediate(this); }
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(); }