From: Jean-Philippe Bruyère Date: Wed, 16 Jul 2025 18:22:06 +0000 (+0200) Subject: debug log, wip X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=f88017f962a2e1c34a8826f17af44318d4744242;p=jp%2Fcrowedit.git debug log, wip --- diff --git a/CrowEditBase/CrowEditBase.csproj b/CrowEditBase/CrowEditBase.csproj index 962c66c..15f76ef 100644 --- a/CrowEditBase/CrowEditBase.csproj +++ b/CrowEditBase/CrowEditBase.csproj @@ -20,7 +20,7 @@ - + diff --git a/CrowEditBase/src/LogViewerWidget.cs b/CrowEditBase/src/LogViewerWidget.cs index 8d575cb..1a83c74 100644 --- a/CrowEditBase/src/LogViewerWidget.cs +++ b/CrowEditBase/src/LogViewerWidget.cs @@ -322,8 +322,6 @@ namespace Crow entries = filteredLines.Skip(ScrollY).Take(visibleLines).ToArray(); } - //perf.Restart(); - for (int i = 0; i < entries.Count(); i++) { int idx = i + ScrollY; LogEntry le = entries.ElementAt(i); @@ -371,14 +369,11 @@ namespace Crow break; } gr.MoveTo (x, y + fe.Ascent); - ReadOnlySpan tmp = le.msg.AsSpan(0, Math.Min (400, le.msg.Length)); + ReadOnlySpan tmp = le.msg.AsSpan(0, Math.Min (100, le.msg.Length)); gr.ShowText (tmp); } y += fe.Height; } - /*perf.Stop(); - Console.WriteLine($"log onDraw: {visibleLines} lines in {perf.ElapsedMilliseconds} ms");*/ - } public override void onMouseLeave(object sender, MouseMoveEventArgs e) diff --git a/CrowEditBase/ui/CrowEdit.style b/CrowEditBase/ui/CrowEdit.style index 83011fe..099d56a 100644 --- a/CrowEditBase/ui/CrowEdit.style +++ b/CrowEditBase/ui/CrowEdit.style @@ -153,7 +153,7 @@ EnumSelector { Template = "#ui.EnumSelector.template"; //ItemStyle = "CheckBox"; } -/*CheckBox { +CheckBox { Template= "#Crow.CheckBox2.template"; Width = "Stretched"; Height = "Fit"; @@ -164,7 +164,7 @@ EnumSelector { Unchecked = "{Background=${ControlIdle}}"; MouseEnter = "{Foreground=${ControlCaptionHoverColor}}"; MouseLeave = "{Foreground=${ControlForeground}}"; -}*/ +} StateBox { Template= "#Crow.CheckBox2.template"; Width = "Stretched"; diff --git a/CrowEditBase/ui/sourceEditor.itmp b/CrowEditBase/ui/sourceEditor.itmp index 53cdcad..e88413c 100644 --- a/CrowEditBase/ui/sourceEditor.itmp +++ b/CrowEditBase/ui/sourceEditor.itmp @@ -12,7 +12,7 @@ LargeIncrement="{../tb.PageWidth}" SmallIncrement="1" CursorRatio="{../tb.ChildWidthRatio}" Maximum="{../tb.MaxScrollX}" /> - + diff --git a/plugins/CECrowPlugin/src/CrowService.cs b/plugins/CECrowPlugin/src/CrowService.cs index 770820d..d38a4cf 100644 --- a/plugins/CECrowPlugin/src/CrowService.cs +++ b/plugins/CECrowPlugin/src/CrowService.cs @@ -50,36 +50,17 @@ namespace CECrowPlugin ]; #region Commands - public Command CMDStartRecording, CMDStopRecording, CMDRefresh; + public Command CMDStartRecording, CMDStopRecording, CMDRefresh, CMDAddEventToRecord, CMDRemoveEventToRecord; public Command CMDGotoParentEvent, CMDEventHistoryForward, CMDEventHistoryBackward; public CommandGroup LoggerCommands => new CommandGroup (CMDRefresh, CMDStartRecording, CMDStopRecording); public CommandGroup GraphicTreeCommands => new CommandGroup (CMDRefresh); public CommandGroup EventCommands => new CommandGroup( CMDGotoParentEvent, CMDEventHistoryBackward, CMDEventHistoryForward); - public ActionCommand CMDOptions_SelectCrowAssemblyLocation => new ActionCommand ("...", - () => { - FileDialog dlg = App.LoadIMLFragment (@" - "); - dlg.OkClicked += (sender, e) => CrowDbgAssemblyLocation = (sender as FileDialog).SelectedFileFullPath; - dlg.DataSource = this; - } - ); - public ActionCommand CMDOptions_AddCrowAssembly => new ActionCommand ("Add Assembly with Crow Ressource", - () => { - FileDialog dlg = App.LoadIMLFragment (@" - "); - dlg.OkClicked += (sender, e) => { - crowAssemblies.Add ((sender as FileDialog).SelectedFileFullPath); - saveCrowAssemblies (); - }; - dlg.DataSource = this; - } - ); - public ActionCommand CMDOptions_RemoveCrowAssembly; - public ActionCommand CMDViewPreview, CMDViewGraphicTree, CMDViewProperties; + public Command CMDOptions_SelectCrowAssemblyLocation, CMDOptions_AddCrowAssembly, CMDOptions_RemoveCrowAssembly; + public Command CMDOptions_SelectDebugLogDirectory; + public Command CMDViewPreview, CMDViewGraphicTree, CMDViewProperties; public CommandGroup ViewCommands; + void initCommands () { CMDViewPreview = new ActionCommand("Preview", () => App.LoadWindow ("#CECrowPlugin.ui.winCrowPreview.crow", App), "#icons.presentation.svg"); @@ -90,6 +71,19 @@ namespace CECrowPlugin CMDRefresh = new ActionCommand ("Refresh", refresh, "#icons.refresh.svg", IsRunning); CMDStartRecording = new ActionCommand ("Start Recording", () => Recording = true, "#icons.circle.svg", false); CMDStopRecording = new ActionCommand ("Stop Recording", stopRecording, "#icons.circle-red.svg", false); + CMDAddEventToRecord = new ActionCommand ("Add Event To Record", () => { + if (EvtTypeToAddForRecording != DbgEvtType.None && !recordedEvents.Contains(EvtTypeToAddForRecording)) { + recordedEvents.Add(EvtTypeToAddForRecording); + EvtTypeToAddForRecording = DbgEvtType.None; + } + }); + CMDRemoveEventToRecord = new ActionCommand ("Remove Event To Record", () => { + if (currentRecordedEvent != DbgEvtType.None && recordedEvents.Contains(currentRecordedEvent)) { + recordedEvents.Remove(currentRecordedEvent); + currentRecordedEvent = DbgEvtType.None; + } + }); + CMDGotoParentEvent = new ActionCommand("parent", ()=> { CurrentEvent = CurrentEvent?.parentEvent; }, "#icons.level-up.svg", false); CMDEventHistoryBackward = new ActionCommand("back.", currentEventHistoryGoBack, "#icons.previous.svg", false); @@ -100,6 +94,32 @@ namespace CECrowPlugin crowAssemblies.Remove(selectedCrowAssembly); saveCrowAssemblies (); }, "#icons.trash.svg", false); + CMDOptions_SelectCrowAssemblyLocation = new ActionCommand ("...", () => + { + FileDialog dlg = App.LoadIMLFragment (@" + "); + dlg.OkClicked += (sender, e) => CrowDbgAssemblyLocation = (sender as FileDialog).SelectedFileFullPath; + dlg.DataSource = this; + }); + CMDOptions_AddCrowAssembly = new ActionCommand ("Add Assembly with Crow Ressource", () => { + FileDialog dlg = App.LoadIMLFragment (@" + "); + dlg.OkClicked += (sender, e) => { + crowAssemblies.Add ((sender as FileDialog).SelectedFileFullPath); + saveCrowAssemblies (); + }; + dlg.DataSource = this; + }); + CMDOptions_SelectDebugLogDirectory = new ActionCommand ("...", () => + { + FileDialog dlg = App.LoadIMLFragment (@" + "); + dlg.DataSource = this; + }); + } #endregion @@ -109,6 +129,14 @@ namespace CECrowPlugin delSetSource (imlSource); } } + void refresh () { + if (!IsRunning) + Start (); + if (IsRunning) { + fiITor_NextInstantiatorID?.SetValue (null, 0); + delReloadIml (); + } + } Project currentSolution; Exception currentException; @@ -228,70 +256,6 @@ namespace CECrowPlugin #endregion - #region DebugLog - bool recording, debugLogIsEnabled; - IList recordedEvents = new ObservableList(new DbgEvtType[] {DbgEvtType.Widget} ); - DbgEvtType addRecordedEvents = DbgEvtType.None; - public bool DebugLogIsEnabled { - get => debugLogIsEnabled; - set { - if (debugLogIsEnabled == value) - return; - debugLogIsEnabled = value; - CMDStartRecording.CanExecute = debugLogIsEnabled & !Recording; - CMDStopRecording.CanExecute = debugLogIsEnabled & Recording; - NotifyValueChanged (debugLogIsEnabled); - } - } - public bool Recording { - get => recording; - set { - if (recording == value) - return; - recording = IsRunning & DebugLogIsEnabled & value; - if (recording) { - fiDbg_IncludedEvents.SetValue (dbgIFace, RecordedEvents.ToList()); - CMDStartRecording.CanExecute = false; - CMDStopRecording.CanExecute = true; - } else { - fiDbg_IncludedEvents.SetValue (dbgIFace, new List()); - CMDStartRecording.CanExecute = debugLogIsEnabled; - CMDStopRecording.CanExecute = false; - } - NotifyValueChanged(recording); - } - } - public IList RecordedEvents { - get => recordedEvents; - set { - if (recordedEvents == value) - return; - recordedEvents = value; - if (Recording) - fiDbg_IncludedEvents.SetValue (dbgIFace, value); - NotifyValueChanged (recordedEvents); - } - } - public DbgEvtType AddRecordedEvents { - get => addRecordedEvents; - set { - if (addRecordedEvents == value) - return; - addRecordedEvents = value; - NotifyValueChanged (addRecordedEvents); - } - } - public string DebugLogFilePath { - get => Configuration.Global.Get ("DebugLogFilePath"); - set { - if (DebugLogFilePath == value) - return; - Configuration.Global.Set ("DebugLogFilePath", value); - NotifyValueChanged (value); - } - } - #endregion - public bool HasVkvgBackend { get; private set; } public int RefreshRate { get => Configuration.Global.Get ("RefreshRate", 10); @@ -662,7 +626,7 @@ namespace CECrowPlugin } #endregion - #region Mouse & Keyboard + #region Mouse & Keyboard Point mouseScreenPos;//absolute on screen position. public void onKeyDown(KeyEventArgs e) { @@ -763,8 +727,91 @@ namespace CECrowPlugin #endregion #region Debug log + bool recording, debugLogIsEnabled; + int firstWidgetIndexToGet = 0; + public object LogMutex = new object (); IList events; IList widgets; + IList recordedEvents = new ObservableList(new DbgEvtType[] { DbgEvtType.Widget } ); + DbgEvtType evtTypeToAddForRecording = DbgEvtType.None, currentRecordedEvent = DbgEvtType.None; + public bool DebugLogIsEnabled { + get => debugLogIsEnabled; + set { + if (debugLogIsEnabled == value) + return; + debugLogIsEnabled = value; + CMDStartRecording.CanExecute = debugLogIsEnabled & !Recording; + CMDStopRecording.CanExecute = debugLogIsEnabled & Recording; + NotifyValueChanged (debugLogIsEnabled); + } + } + public bool Recording { + get => recording; + set { + if (recording == value) + return; + recording = IsRunning & DebugLogIsEnabled & value; + if (recording) { + fiDbg_IncludedEvents.SetValue (dbgIFace, RecordedEvents.ToList()); + CMDStartRecording.CanExecute = false; + CMDStopRecording.CanExecute = true; + } else { + fiDbg_IncludedEvents.SetValue (dbgIFace, new List()); + CMDStartRecording.CanExecute = debugLogIsEnabled; + CMDStopRecording.CanExecute = false; + } + NotifyValueChanged(recording); + } + } + public IList RecordedEvents { + get => recordedEvents; + set { + if (recordedEvents == value) + return; + recordedEvents = value; + if (Recording) + fiDbg_IncludedEvents.SetValue (dbgIFace, value); + NotifyValueChanged (recordedEvents); + } + } + public DbgEvtType EvtTypeToAddForRecording { + get => evtTypeToAddForRecording; + set { + if (evtTypeToAddForRecording == value) + return; + evtTypeToAddForRecording = value; + NotifyValueChanged (evtTypeToAddForRecording); + } + } + public object CurrentRecordedEvent { + get => currentRecordedEvent; + set { + if (currentRecordedEvent == (DbgEvtType)value) + return; + currentRecordedEvent = (DbgEvtType)value; + NotifyValueChanged(currentRecordedEvent); + } + } + public string DebugLogFileDirectory { + get => Configuration.Global.Get ("DebugLogFileDirectory", Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments)); + set { + if (DebugLogFileDirectory == value) + return; + Configuration.Global.Set ("DebugLogFileDirectory", value); + NotifyValueChanged (value); + } + } + public bool DebugLogToFile { + get => Configuration.Global.Get (nameof(DebugLogToFile)); + set { + if (DebugLogToFile == value) + return; + Configuration.Global.Set (nameof(DebugLogToFile), value); + NotifyValueChanged(DebugLogToFile); + DbgLogger.ConsoleOutput = !value; + } + } + public IList Events { get => events; set { @@ -783,42 +830,42 @@ namespace CECrowPlugin NotifyValueChanged (nameof (Widgets), widgets); } } - void refresh () { - if (!IsRunning) - Start (); - if (IsRunning) { - fiITor_NextInstantiatorID?.SetValue (null, 0); - delReloadIml (); - } - - //updateCrowApp(); - } + void stopRecording () { if (!Recording) return; Recording = false; - getLog (); - App.LoadWindow ("#CECrowPlugin.ui.winDebugLog.crow", this); + if (DebugLogToFile) { + string logfilepath = Path.Combine(DebugLogFileDirectory, $"crow-{DateTime.Now:yyyy-MM-dd_hh-mm}.log"); + using (FileStream stream = new FileStream(logfilepath, FileMode.CreateNew, FileAccess.Write)) { + writeLog(stream); + MessageBox.ShowModal(App, MessageBox.Type.Information, $"Debug log saved to: {logfilepath}"); + } + } else { + getLog (); + App.LoadWindow ("#CECrowPlugin.ui.winDebugLog.crow", this); + } + } + void writeLog(Stream stream) { + Type debuggerType = crowAssembly.GetType("Crow.DbgLogger"); + MethodInfo miSave = debuggerType.GetMethod("Save", + new Type[] { + dbgIfaceType, + typeof(Stream), + typeof(int), + typeof(bool) + }); + miSave.Invoke(null, new object[] {dbgIFace, stream, firstWidgetIndexToGet, true}); } - int firstWidgetIndexToGet = 0; - public object LogMutex = new object (); void getLog () { using (Stream stream = new MemoryStream (1024)) { - Type debuggerType = crowAssembly.GetType("Crow.DbgLogger"); - MethodInfo miSave = debuggerType.GetMethod("Save", - new Type[] { - dbgIfaceType, - typeof(Stream), - typeof(int), - typeof(bool) - }); - - List widgets = new List(); List events = new List(); - miSave.Invoke(null, new object[] {dbgIFace, stream, firstWidgetIndexToGet, true}); + + writeLog(stream); stream.Seek(0, SeekOrigin.Begin); + DbgLogger.Load (stream, events, widgets); lock (LogMutex) { @@ -918,7 +965,6 @@ namespace CECrowPlugin disableCurrentEventHistory = false; } - void currentEventHistoryGoForward () { disableCurrentEventHistory = true; CurrentEventHistoryBackward.Push (CurrentEvent); @@ -935,7 +981,7 @@ namespace CECrowPlugin if (curWidgetRecord == value) return; curWidgetRecord = value; - NotifyValueChanged (nameof (CurrentWidget), curWidgetRecord); + NotifyValueChanged ("CurrentWidgetRecord", curWidgetRecord); NotifyValueChanged ("CurWidgetRootEvents", curWidgetRecord?.RootEvents); NotifyValueChanged ("CurrentWidgetEvents", curWidgetRecord?.Events); NotifyValueChanged ("CurWidgetProperties", CurWidgetProperties); diff --git a/plugins/CECrowPlugin/ui/EnumSelector.template b/plugins/CECrowPlugin/ui/EnumSelector.template index b0a9f25..b2f6559 100644 --- a/plugins/CECrowPlugin/ui/EnumSelector.template +++ b/plugins/CECrowPlugin/ui/EnumSelector.template @@ -1,10 +1,21 @@ - + + + + + \ No newline at end of file diff --git a/plugins/CECrowPlugin/ui/WidgetRecord.itemp b/plugins/CECrowPlugin/ui/WidgetRecord.itemp index 2b1297d..69d4242 100644 --- a/plugins/CECrowPlugin/ui/WidgetRecord.itemp +++ b/plugins/CECrowPlugin/ui/WidgetRecord.itemp @@ -1,10 +1,11 @@ + diff --git a/plugins/CECrowPlugin/ui/dbg.style b/plugins/CECrowPlugin/ui/dbg.style index 2cd82c1..5cd5301 100644 --- a/plugins/CECrowPlugin/ui/dbg.style +++ b/plugins/CECrowPlugin/ui/dbg.style @@ -4,7 +4,7 @@ } smallLabCaption { - Font="mono, 8"; + Font="mono, 10"; Foreground="Grey"; } smallLabValue { @@ -32,4 +32,16 @@ labWidgetRecordList { DbgEventWidget { CacheEnabled = "true"; +} +CheckBoxEvtType { + Template= "#Crow.CheckBox2.template"; + Width = "160"; + Height = "Fit"; + CornerRadius = "2"; + Background = "${ControlIdle}"; + Foreground = "${ControlForeground}"; + Checked = "{Background=${ControlHighlight}}"; + Unchecked = "{Background=${ControlIdle}}"; + MouseEnter = "{Foreground=${ControlCaptionHoverColor}}"; + MouseLeave = "{Foreground=${ControlForeground}}"; } \ No newline at end of file diff --git a/plugins/CECrowPlugin/ui/winConfiguration.crow b/plugins/CECrowPlugin/ui/winConfiguration.crow index 4f8c87b..42f7c27 100644 --- a/plugins/CECrowPlugin/ui/winConfiguration.crow +++ b/plugins/CECrowPlugin/ui/winConfiguration.crow @@ -40,13 +40,21 @@ - - + + - - -