-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
113 lines (98 loc) · 3.03 KB
/
Copy pathMainWindow.xaml.cs
File metadata and controls
113 lines (98 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System.Text;
using System.Windows;
namespace PrimeDictate;
internal partial class MainWindow : Window
{
internal MainWindow(DictationWorkspaceViewModel viewModel)
{
InitializeComponent();
this.DataContext = viewModel;
}
private void OnSettingsClick(object sender, RoutedEventArgs e)
{
if (System.Windows.Application.Current is App app)
{
app.ShowSettings();
}
}
private void OnHistoryClick(object sender, RoutedEventArgs e)
{
if (System.Windows.Application.Current is App app)
{
app.ShowHistory();
}
}
private void OnCopyErrorsClick(object sender, RoutedEventArgs e)
{
if (this.DataContext is not DictationWorkspaceViewModel viewModel)
{
return;
}
var builder = new StringBuilder();
foreach (var entry in viewModel.GlobalEntries)
{
if (entry.Level != AppLogLevel.Error)
{
continue;
}
builder.Append('[')
.Append(entry.TimestampUtc.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"))
.Append("] ")
.Append(entry.Level)
.Append(": ")
.AppendLine(entry.DisplayMessage);
}
var text = builder.Length > 0 ? builder.ToString() : "No error entries in Global Activity.";
this.TrySetClipboardText(text);
}
private void OnCopyAllActivityClick(object sender, RoutedEventArgs e)
{
if (this.DataContext is not DictationWorkspaceViewModel viewModel)
{
return;
}
var builder = new StringBuilder();
foreach (var entry in viewModel.GlobalEntries)
{
builder.Append('[')
.Append(entry.TimestampUtc.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss"))
.Append("] ")
.Append(entry.Level)
.Append(": ")
.AppendLine(entry.DisplayMessage);
}
var text = builder.Length > 0 ? builder.ToString() : "No entries in Global Activity.";
this.TrySetClipboardText(text);
}
private void TrySetClipboardText(string text)
{
try
{
System.Windows.Clipboard.SetText(text);
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(
this,
$"Unable to copy to clipboard: {ex.Message}",
"Copy failed",
MessageBoxButton.OK,
MessageBoxImage.Error);
}
}
private void OnTitleBarMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (e.ButtonState == System.Windows.Input.MouseButtonState.Pressed)
{
this.DragMove();
}
}
private void OnMinimizeClick(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void OnCloseClick(object sender, RoutedEventArgs e)
{
this.Close();
}
}