-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBatchPreviewDialog.xaml.cs
More file actions
156 lines (117 loc) · 5.08 KB
/
Copy pathBatchPreviewDialog.xaml.cs
File metadata and controls
156 lines (117 loc) · 5.08 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using ReadFolder.Services;
using WpfBrush = System.Windows.Media.Brush;
using WpfKeyEventArgs = System.Windows.Input.KeyEventArgs;
namespace ReadFolder;
public partial class BatchPreviewDialog : Window
{
private readonly BatchPreviewDialogViewModel _viewModel;
public BatchPreviewDialog(BatchPreviewRequest request)
{
InitializeComponent();
_viewModel = new BatchPreviewDialogViewModel(request);
DataContext = _viewModel;
}
public bool DoNotShowToday => _viewModel.DoNotShowToday;
private void TitleBar_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragMove();
}
}
private void Window_PreviewKeyDown(object sender, WpfKeyEventArgs e)
{
if (e.Key == Key.Escape)
{
DialogResult = false;
e.Handled = true;
return;
}
if (e.Key == Key.Enter && DataContext is BatchPreviewDialogViewModel { CanConfirm: true })
{
DialogResult = true;
e.Handled = true;
}
}
private void Confirm_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
private void Cancel_Click(object sender, RoutedEventArgs e)
{
DialogResult = false;
}
}
public sealed class BatchPreviewDialogViewModel
{
private const int VisibleItemLimit = 20;
public BatchPreviewDialogViewModel(BatchPreviewRequest request)
{
var localization = LocalizationService.Instance;
TitleText = localization["Dialog.BatchPreviewTitle"];
SubtitleText = localization["Dialog.BatchPreviewSubtitle"];
ActionText = request.Action;
ItemCountText = localization.Format("Dialog.BatchPreviewItemCount", request.ItemCount);
ConflictCountText = localization.Format("Dialog.BatchPreviewConflictCount", request.Conflicts.Count);
BoundaryText = localization["Dialog.BatchPreviewBoundary"];
TargetLabel = localization["Dialog.BatchPreviewTargetLabel"];
Target = request.Target;
ItemsLabel = localization["Dialog.BatchPreviewItemsLabel"];
ConflictsLabel = localization["Dialog.BatchPreviewConflictsLabel"];
NoticePrefix = localization["Dialog.BatchPreviewNoticePrefix"];
HasConflicts = request.Conflicts.Count > 0;
CanConfirm = !HasConflicts;
NoticeText = HasConflicts
? localization["Dialog.BatchPreviewConflictNotice"]
: request.IsDelete
? localization["Dialog.BatchPreviewDeleteNotice"]
: localization["Dialog.BatchPreviewNotice"];
NoticeBackground = HasConflicts ? ThemeService.GetBrush("DangerBg") : ThemeService.GetBrush("WarningBg");
NoticeBorder = HasConflicts ? ThemeService.GetBrush("DangerBorder") : ThemeService.GetBrush("WarningBorder");
NoticeForeground = HasConflicts ? ThemeService.GetBrush("DangerText") : ThemeService.GetBrush("WarningText");
HasHiddenItems = request.HiddenItemCount > 0;
MoreText = localization.Format("Dialog.BatchPreviewMore", request.HiddenItemCount);
CancelText = HasConflicts
? localization["Dialog.BatchPreviewClose"]
: localization["Dialog.BatchPreviewCancel"];
ConfirmText = localization["Dialog.BatchPreviewConfirm"];
FooterHint = HasConflicts
? localization["Dialog.BatchPreviewEscClose"]
: localization["Dialog.BatchPreviewEscEnter"];
DoNotShowTodayText = localization["Dialog.BatchPreviewDoNotShowToday"];
DoNotShowTodayTooltip = localization["Dialog.BatchPreviewDoNotShowTodayTooltip"];
Items = new ObservableCollection<BatchPreviewItem>(request.Items.Take(VisibleItemLimit));
Conflicts = new ObservableCollection<string>(request.Conflicts.Select(conflict => "- " + conflict));
}
public string TitleText { get; }
public string SubtitleText { get; }
public string ActionText { get; }
public string ItemCountText { get; }
public string ConflictCountText { get; }
public string BoundaryText { get; }
public string TargetLabel { get; }
public string Target { get; }
public string NoticePrefix { get; }
public string NoticeText { get; }
public WpfBrush NoticeBackground { get; }
public WpfBrush NoticeBorder { get; }
public WpfBrush NoticeForeground { get; }
public string ItemsLabel { get; }
public string ConflictsLabel { get; }
public ObservableCollection<BatchPreviewItem> Items { get; }
public ObservableCollection<string> Conflicts { get; }
public bool HasConflicts { get; }
public bool CanConfirm { get; }
public bool HasHiddenItems { get; }
public string MoreText { get; }
public string CancelText { get; }
public string ConfirmText { get; }
public string FooterHint { get; }
public bool DoNotShowToday { get; set; }
public string DoNotShowTodayText { get; }
public string DoNotShowTodayTooltip { get; }
}