Copy program log to clipboard button

Closes #9
This commit is contained in:
2026-03-03 10:59:29 +09:00
parent 94cf073012
commit 94c8945140
2 changed files with 31 additions and 12 deletions
+20 -10
View File
@@ -36,7 +36,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
private bool _isPerformingInitialLoad; private bool _isPerformingInitialLoad;
private string _processDir; private string _processDir;
private bool _isCreatingPDF; private bool _isCreatingPDF;
private string _createPDFLog; private string _programLog;
private string _workingFolder; private string _workingFolder;
private string _reportTitle; private string _reportTitle;
@@ -56,11 +56,11 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
var quotes = Constants.GetQuotes(); var quotes = Constants.GetQuotes();
Random random = new Random(); Random random = new Random();
var quoteIndex = random.Next(0, quotes.Length); var quoteIndex = random.Next(0, quotes.Length);
_createPDFLog = "----- MayShow v" + Constants.AppVersion + " ------" + Environment.NewLine; _programLog = "----- MayShow v" + Constants.AppVersion + " ------" + Environment.NewLine;
_createPDFLog += quotes[quoteIndex] + Environment.NewLine; _programLog += quotes[quoteIndex] + Environment.NewLine;
_createPDFLog += "---------------------------------------" + Environment.NewLine; _programLog += "---------------------------------------" + Environment.NewLine;
_createPDFLog += "Loaded and ready to create report!" + Environment.NewLine; _programLog += "Loaded and ready to create report!" + Environment.NewLine;
_createPDFLog += "Please copy and send this Program Log when reporting any issues with the software."; _programLog += "Please copy and send this Program Log when reporting any issues with the software.";
_workingFolder = ""; _workingFolder = "";
ReportFiles = _reportFiles = new ObservableCollection<ReportFile>(); ReportFiles = _reportFiles = new ObservableCollection<ReportFile>();
_reportTitle = ""; _reportTitle = "";
@@ -141,10 +141,10 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
} }
} }
public string CreatePDFLog public string ProgramLog
{ {
get => _createPDFLog; get => _programLog;
set { _createPDFLog = value; NotifyPropertyChanged(); } set { _programLog = value; NotifyPropertyChanged(); }
} }
public bool HasUnsavedWork public bool HasUnsavedWork
@@ -176,7 +176,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
{ {
var timestamp = string.Format("[{0:s}]", DateTime.Now); var timestamp = string.Format("[{0:s}]", DateTime.Now);
Console.WriteLine(timestamp + " " + message, arguments); Console.WriteLine(timestamp + " " + message, arguments);
CreatePDFLog += Environment.NewLine + string.Format(message, arguments ?? []); ProgramLog += Environment.NewLine + string.Format(message, arguments ?? []);
} }
public async void ChooseFolder() public async void ChooseFolder()
@@ -563,6 +563,16 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
await SavePDFReportDataToDisk(report); 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) public byte[]? GetFont(string faceName)
{ {
LogInfo(string.Format("Loading font {0}", faceName)); LogInfo(string.Format("Loading font {0}", faceName));
+11 -2
View File
@@ -270,14 +270,23 @@
Spacing="2" Spacing="2"
Grid.Row="3"> Grid.Row="3">
<Rectangle Fill="Gray" Height="3" HorizontalAlignment="Stretch"/> <Rectangle Fill="Gray" Height="3" HorizontalAlignment="Stretch"/>
<Label Content="Program Log" FontSize="14" FontWeight="Bold"/> <Grid ColumnDefinitions="Auto, *">
<Label Content="Program Log" FontSize="14" FontWeight="Bold" Grid.Column="0"/>
<Button Command="{Binding CopyLogToClipboard}"
FontSize="10"
Grid.Column="1"
HorizontalAlignment="Right"
Margin="0,2,8,2">
<TextBlock><Run Text="&#xf0c5;" FontFamily="{StaticResource FontAwesomeSolid}"/> Copy Program Log to Clipboard</TextBlock>
</Button>
</Grid>
</StackPanel> </StackPanel>
<ScrollViewer Margin="2" <ScrollViewer Margin="2"
Grid.Row="4" Grid.Row="4"
x:Name="LogScrollView" x:Name="LogScrollView"
VerticalScrollBarVisibility="Visible" VerticalScrollBarVisibility="Visible"
AllowAutoHide="False"> AllowAutoHide="False">
<SelectableTextBlock Text="{Binding CreatePDFLog}" <SelectableTextBlock Text="{Binding ProgramLog}"
Margin="2" Margin="2"
TextWrapping="Wrap" TextWrapping="Wrap"
x:Name="LogBlock"/> x:Name="LogBlock"/>