From 94c89451409656f061cea2719034eb9bf384842b Mon Sep 17 00:00:00 2001 From: Michael Babienco Date: Tue, 3 Mar 2026 10:59:29 +0900 Subject: [PATCH] Copy program log to clipboard button Closes #9 --- src/ViewModels/MainViewModel.cs | 30 ++++++++++++++++++++---------- src/Views/MainView.axaml | 13 +++++++++++-- 2 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/ViewModels/MainViewModel.cs b/src/ViewModels/MainViewModel.cs index 6d0e81d..8d4d626 100644 --- a/src/ViewModels/MainViewModel.cs +++ b/src/ViewModels/MainViewModel.cs @@ -36,7 +36,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown private bool _isPerformingInitialLoad; private string _processDir; private bool _isCreatingPDF; - private string _createPDFLog; + private string _programLog; private string _workingFolder; private string _reportTitle; @@ -56,11 +56,11 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown var quotes = Constants.GetQuotes(); Random random = new Random(); var quoteIndex = random.Next(0, quotes.Length); - _createPDFLog = "----- MayShow v" + Constants.AppVersion + " ------" + Environment.NewLine; - _createPDFLog += quotes[quoteIndex] + Environment.NewLine; - _createPDFLog += "---------------------------------------" + Environment.NewLine; - _createPDFLog += "Loaded and ready to create report!" + Environment.NewLine; - _createPDFLog += "Please copy and send this Program Log when reporting any issues with the software."; + _programLog = "----- MayShow v" + Constants.AppVersion + " ------" + Environment.NewLine; + _programLog += quotes[quoteIndex] + Environment.NewLine; + _programLog += "---------------------------------------" + Environment.NewLine; + _programLog += "Loaded and ready to create report!" + Environment.NewLine; + _programLog += "Please copy and send this Program Log when reporting any issues with the software."; _workingFolder = ""; ReportFiles = _reportFiles = new ObservableCollection(); _reportTitle = ""; @@ -141,10 +141,10 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown } } - public string CreatePDFLog + public string ProgramLog { - get => _createPDFLog; - set { _createPDFLog = value; NotifyPropertyChanged(); } + get => _programLog; + set { _programLog = value; NotifyPropertyChanged(); } } public bool HasUnsavedWork @@ -176,7 +176,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown { var timestamp = string.Format("[{0:s}]", DateTime.Now); Console.WriteLine(timestamp + " " + message, arguments); - CreatePDFLog += Environment.NewLine + string.Format(message, arguments ?? []); + ProgramLog += Environment.NewLine + string.Format(message, arguments ?? []); } public async void ChooseFolder() @@ -563,6 +563,16 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown await SavePDFReportDataToDisk(report); } + public async Task CopyLogToClipboard() + { + var clipboard = TopLevelGrabber?.GetTopLevel().Clipboard; + if (clipboard != null) + { + await clipboard.SetTextAsync(ProgramLog); + LogInfo("Program log has been copied to the clipboard!"); + } + } + public byte[]? GetFont(string faceName) { LogInfo(string.Format("Loading font {0}", faceName)); diff --git a/src/Views/MainView.axaml b/src/Views/MainView.axaml index 40be5ec..019fa98 100644 --- a/src/Views/MainView.axaml +++ b/src/Views/MainView.axaml @@ -270,14 +270,23 @@ Spacing="2" Grid.Row="3"> -