void DrawToolbarColumnButtons(LoggingContainer container) { for (int i = 0; i < this.columnButtonDatas.Length; i++) { var data = columnButtonDatas[i]; Columns column = (Columns)i; data.Value = consoleVM.IsColumnShow(column); this.Toggle(data, () => { consoleVM.SetColumnShow(column, data.Value); }); } }
public void SaveLoggingData() { LoggingContainer container = this.GetCurrentContainer(); var list = container.GetLoggingList(); string filename = string.Format("log-{0:yyyy-MM-dd_HH-mm-ss}", DateTime.Now); string location = EditorUtility.SaveFilePanel("Save", lastSaveDir, filename, "txt"); if (string.IsNullOrEmpty(location)) { return; } FileInfo file = new FileInfo(location); DirectoryInfo dir = file.Directory; if (!dir.Exists) { dir.Create(); } this.lastSaveDir = dir.FullName; StringBuilder buf = new StringBuilder(); foreach (LoggingEntry entry in list) { foreach (LoggingData data in entry.LoggingDatas) { buf.AppendFormat("{0:yyyy-MM-dd HH:mm:ss.fff}", data.TimeStamp); buf.AppendFormat(" Thread[{0}]", data.ThreadName); buf.AppendFormat(" {0}", data.Level.ToString()); buf.AppendFormat(" {0}", data.LoggerName); buf.AppendFormat(" - {0}", data.Message); buf.Append("\r\n"); if (data.LocationInfo != null && data.LocationInfo.StackFrames != null) { foreach (var frame in data.LocationInfo.StackFrames) { buf.Append(frame.FullInfo.Replace(Directory.GetCurrentDirectory().ToString() + @"\", "")).Append("\r\n"); } } buf.Append("\r\n"); } } File.WriteAllText(location, buf.ToString()); }
void DrawToolbarLevelButtons(LoggingContainer container) { for (int i = 0; i < this.levelButtonDatas.Length; i++) { var data = levelButtonDatas[i]; Level level = (Level)(i + 1); data.Value = consoleVM.IsLevelShow(level); int count = container.GetCount(level); data.Text = count < 1000 ? count.ToString() : "999+"; this.Toggle(data, () => { consoleVM.SetLevelShow(level, data.Value); }); } }
void OnGUI() { Init(); LoggingContainer container = consoleVM.GetCurrentContainer(); Color oldColor = GUI.backgroundColor; this.DrawToolbar(container); GUI.backgroundColor = oldColor; this.DrawVerticalSplitter(); GUI.backgroundColor = oldColor; this.DrawLoggingGrid(container); GUI.backgroundColor = oldColor; this.DrawLoggingDetail(); GUI.backgroundColor = oldColor; this.Repaint(); }
void AddLoggingData(TerminalInfo terminalInfo, LoggingData loggingData) { lock (_lock) { LoggingContainer container = null; int index = this.terminalInfos.IndexOf(terminalInfo); if (index < 0) { this.terminalInfos.Add(terminalInfo); container = new LoggingContainer(terminalInfo, this.maxCapacity); this.containers.Add(container); if (this.currentIndex < 0 || this.currentIndex >= this.terminalInfos.Count) { this.currentIndex = 0; } } else { container = this.containers[index]; } container.Add(loggingData); } }
void DrawLoggingGrid(LoggingContainer container) { var areaRect = new Rect(0f, toolbarHeight, position.width, position.height * this.verticalSplitterPercent - toolbarHeight - splitterRectHeight / 2f); List <LoggingEntry> list = container.GetLoggingList(); this.renderedList.Clear(); this.renderedLineCountList.Clear(); foreach (LoggingEntry logging in list) { if (!ShouldShow(logging)) { continue; } if (consoleVM.Collapse) { renderedList.Add(logging.LoggingData); renderedLineCountList.Add(logging.Count); } else { renderedList.AddRange(logging.LoggingDatas); } } int count = renderedList.Count; var viewRect = new Rect(0, 0, areaRect.width - 20, count * lineHeight); if (viewRect.height >= areaRect.height && this.loggingVerticalScrollBarPercent > 0.95f) { loggingPanelScrollPosition.y = viewRect.height - areaRect.height; } loggingPanelScrollPosition = GUI.BeginScrollView(areaRect, loggingPanelScrollPosition, viewRect); if (viewRect.height >= areaRect.height) { this.loggingVerticalScrollBarPercent = loggingPanelScrollPosition.y / (viewRect.height - areaRect.height); } int firstIndex = (int)(loggingPanelScrollPosition.y / lineHeight); int lastIndex = firstIndex + (int)(areaRect.height / lineHeight); firstIndex = Mathf.Clamp(firstIndex - 5, 0, count); lastIndex = Mathf.Clamp(lastIndex + 5, 0, count); if (this.selectedIndex >= count) { this.selectedIndex = -1; } for (int i = firstIndex; i < lastIndex; i++) { LoggingData data = renderedList[i]; var content = this.GetLogLineGUIContent(data); var lineStyle = (i % 2 == 0) ? entryStyleBackEven : entryStyleBackOdd; bool selected = i == selectedIndex; lineStyle.normal = selected ? GUI.skin.GetStyle(lineStyle.name).onNormal : GUI.skin.GetStyle(lineStyle.name).normal; if (GUI.Button(new Rect(0f, i * lineHeight, viewRect.width, lineHeight), content, lineStyle)) { if (selected) { if (EditorApplication.timeSinceStartup - lastClickTime < doubleClickInterval) { lastClickTime = 0; OpenSourceFile(data.LocationInfo); } else { lastClickTime = EditorApplication.timeSinceStartup; } } else { this.selectedIndex = i; lastClickTime = EditorApplication.timeSinceStartup; } } if (consoleVM.Collapse) { int logCount = renderedLineCountList[i]; GUIContent countContent = new GUIContent(logCount < 100 ? logCount.ToString() : "99+"); var size = countBadgeStyle.CalcSize(countContent); size.x = Mathf.Clamp(size.x + 5, 20, 30); size.y = Mathf.Clamp(size.y, 20, lineHeight); GUI.Label(new Rect(viewRect.width - 15f - size.x / 2f, i * lineHeight + (lineHeight - size.y) / 2f, size.x, size.y), countContent, countBadgeStyle); } } GUI.EndScrollView(); }
void DrawToolbar(LoggingContainer container) { EditorGUILayout.BeginHorizontal(EditorStyles.toolbar); if (this.consoleVM.CurrentIndex >= 0) { consoleVM.CurrentIndex = EditorGUILayout.Popup(consoleVM.CurrentIndex, GetTerminalInfoOptions(), EditorStyles.toolbarDropDown, GUILayout.MinWidth(100), GUILayout.MaxWidth(200)); } GUILayout.Space(5f); this.collapseToggle.Value = consoleVM.Collapse; this.Toggle(this.collapseToggle, () => { consoleVM.Collapse = this.collapseToggle.Value; }); GUILayout.Space(5f); DrawToolbarColumnButtons(container); GUILayout.Space(5f); GUILayout.FlexibleSpace(); GUI.SetNextControlName("searchTextField"); consoleVM.FilterText = EditorGUILayout.TextField(consoleVM.FilterText, this.toolbarSeachTextFieldStyle, GUILayout.MinWidth(100), GUILayout.MaxWidth(500)); if (GUILayout.Button("", this.toolbarSeachCancelButtonStyle)) { consoleVM.FilterText = ""; GUI.FocusControl(""); } GUILayout.FlexibleSpace(); GUILayout.Space(5f); this.playToggle.Value = this.consoleVM.PlayState; this.Toggle(this.playToggle, () => { this.consoleVM.PlayState = this.playToggle.Value; if (this.playToggle.Value) { this.consoleVM.Start(); } else { this.consoleVM.Stop(); } }); if (consoleVM.PlayState) { if (GUILayout.Button("Running", EditorStyles.toolbarDropDown, GUILayout.Width(60))) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent(string.Format("{0}:{1}", consoleVM.GetLocalIPAddress().ToString(), consoleVM.Port.ToString())), false, delegate() { }); menu.ShowAsContext(); } } else { consoleVM.Port = EditorGUILayout.IntField(consoleVM.Port, EditorStyles.toolbarTextField, GUILayout.Width(52)); } GUILayout.Space(5f); this.DrawToolbarLevelButtons(container); if (this.Button(this.clearButton)) { EditorApplication.delayCall += () => this.consoleVM.ClearLoggingData(); } if (this.Button(this.saveButton)) { EditorApplication.delayCall += () => this.consoleVM.SaveLoggingData(); } GUILayout.Space(5f); EditorGUILayout.EndHorizontal(); }