Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
NewWorkspaceSettingsDialog.xaml.cs
1using CommunityToolkit.Mvvm.Input;
2using MahApps.Metro.Controls;
3using MahApps.Metro.Controls.Dialogs;
4using System.Collections;
5using System.ComponentModel;
7using System.Windows.Input;
8
10{
14 public partial class NewWorkspaceSettingsDialog : CustomDialog, INotifyDataErrorInfo
15 {
16 #region Constructor
17
18 private readonly TaskCompletionSource<MessageDialogResult> _tcs;
19
20 public NewWorkspaceSettingsDialog()
21 {
22 InitializeComponent();
23 _tcs = new TaskCompletionSource<MessageDialogResult>();
25 Validate();
26 }
27
28 public NewWorkspaceSettingsDialog(MetroWindow parentWindow) : base(parentWindow)
29 {
30 InitializeComponent();
31 _tcs = new TaskCompletionSource<MessageDialogResult>();
33 Validate();
34 }
35
36 #endregion
37
38 // **********************************************************************************************************************************************
39
40 #region Properties
41
42 public string NewWorkspaceFolder
43 {
44 get { return (string)GetValue(NewWorkspaceFolderProperty); }
45 set { SetValue(NewWorkspaceFolderProperty, value); }
46 }
47 public static readonly DependencyProperty NewWorkspaceFolderProperty = DependencyProperty.Register(nameof(NewWorkspaceFolder), typeof(string), typeof(NewWorkspaceSettingsDialog), new PropertyMetadata("", OnPropertyChanged));
48
49 public bool CopyDefaultTemplates
50 {
51 get { return (bool)GetValue(CopyDefaultTemplatesProperty); }
52 set { SetValue(CopyDefaultTemplatesProperty, value); }
53 }
54 public static readonly DependencyProperty CopyDefaultTemplatesProperty = DependencyProperty.Register(nameof(CopyDefaultTemplates), typeof(bool), typeof(NewWorkspaceSettingsDialog), new PropertyMetadata(true, OnPropertyChanged));
55
56 public string PreviousWorkspaceFolder
57 {
58 get { return (string)GetValue(PreviousWorkspaceFolderProperty); }
59 set { SetValue(PreviousWorkspaceFolderProperty, value); }
60 }
61 public static readonly DependencyProperty PreviousWorkspaceFolderProperty = DependencyProperty.Register(nameof(PreviousWorkspaceFolder), typeof(string), typeof(NewWorkspaceSettingsDialog), new PropertyMetadata("", OnPropertyChanged));
62
63 public bool CopyCompetitions
64 {
65 get { return (bool)GetValue(CopyCompetitionsProperty); }
66 set { SetValue(CopyCompetitionsProperty, value); }
67 }
68 public static readonly DependencyProperty CopyCompetitionsProperty = DependencyProperty.Register(nameof(CopyCompetitions), typeof(bool), typeof(NewWorkspaceSettingsDialog), new PropertyMetadata(false, OnPropertyChanged));
69
70 public bool CopyCompetitionDistanceRules
71 {
72 get { return (bool)GetValue(CopyCompetitionDistanceRulesProperty); }
73 set { SetValue(CopyCompetitionDistanceRulesProperty, value); }
74 }
75 public static readonly DependencyProperty CopyCompetitionDistanceRulesProperty = DependencyProperty.Register(nameof(CopyCompetitionDistanceRules), typeof(bool), typeof(NewWorkspaceSettingsDialog), new PropertyMetadata(false, OnPropertyChanged));
76
77 public bool CopyTemplates
78 {
79 get { return (bool)GetValue(CopyTemplatesProperty); }
80 set { SetValue(CopyTemplatesProperty, value); }
81 }
82 public static readonly DependencyProperty CopyTemplatesProperty = DependencyProperty.Register(nameof(CopyTemplates), typeof(bool), typeof(NewWorkspaceSettingsDialog), new PropertyMetadata(false, OnPropertyChanged));
83
84
85 private static void OnPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
86 {
87 NewWorkspaceSettingsDialog dialog = d as NewWorkspaceSettingsDialog;
88 if(dialog == null) { return; }
89 ((RelayCommand)dialog.DialogResultAffirmativeCommand).NotifyCanExecuteChanged();
90
91 dialog.Validate();
92 }
93 #endregion
94
95 // **********************************************************************************************************************************************
96
97 #region Dialog Handling
98
104 public Task<MessageDialogResult> WaitForDialogButtonPressAsync()
105 => _tcs.Task;
106
107 private ICommand _dialogResultNegativeCommand;
111 public ICommand DialogResultNegativeCommand => _dialogResultNegativeCommand ?? (_dialogResultNegativeCommand = new RelayCommand(() =>
112 {
113 _tcs.TrySetResult(MessageDialogResult.Negative);
114 }));
115
116 private ICommand _dialogResultAffirmativeCommand;
117
121 public ICommand DialogResultAffirmativeCommand => _dialogResultAffirmativeCommand ?? (_dialogResultAffirmativeCommand = new RelayCommand(() =>
122 {
123 _tcs.TrySetResult(MessageDialogResult.Affirmative);
124 }, () => !string.IsNullOrEmpty(NewWorkspaceFolder) &&
125 !(CopyTemplates && CopyDefaultTemplates)));
126
127 #endregion
128
129 // **********************************************************************************************************************************************
130
131 #region Validation
132
133 private readonly Dictionary<string, List<string>> _errors = new();
134
135 public bool HasErrors => _errors.Any();
136
137 public event EventHandler<DataErrorsChangedEventArgs> ErrorsChanged;
138
139 public IEnumerable GetErrors(string propertyName)
140 {
141 if (propertyName != null && _errors.ContainsKey(propertyName))
142 {
143 return _errors[propertyName];
144 }
145 return Enumerable.Empty<string>();
146 }
147
148 private void AddError(string propertyName, string error)
149 {
150 if (!_errors.ContainsKey(propertyName))
151 {
152 _errors[propertyName] = new List<string>();
153 }
154 _errors[propertyName].Add(error);
155 ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
156 }
157
158 private void ClearErrors(string propertyName)
159 {
160 if (_errors.Remove(propertyName))
161 {
162 ErrorsChanged?.Invoke(this, new DataErrorsChangedEventArgs(propertyName));
163 }
164 }
165
166 private void Validate()
167 {
168 ClearErrors(nameof(NewWorkspaceFolder));
169 ClearErrors(nameof(CopyTemplates));
170 ClearErrors(nameof(CopyDefaultTemplates));
171
172 if (string.IsNullOrEmpty(NewWorkspaceFolder))
173 {
174 AddError(nameof(NewWorkspaceFolder), Properties.Resources.EmptyPathString);
175 }
176
177 if (CopyTemplates && CopyDefaultTemplates)
178 {
179 AddError(nameof(CopyTemplates), Properties.Resources.OnlyOneOptionCanBeActiveString);
180 AddError(nameof(CopyDefaultTemplates), Properties.Resources.OnlyOneOptionCanBeActiveString);
181 }
182 }
183
184 #endregion
185 }
186}
ICommand DialogResultNegativeCommand
Command called by the negative button (cancel)
ICommand DialogResultAffirmativeCommand
Command called by the affirmative button (ok)
Task< MessageDialogResult > WaitForDialogButtonPressAsync()
Wait until the cancel or ok button is pressed.
Eine stark typisierte Ressourcenklasse zum Suchen von lokalisierten Zeichenfolgen usw.
static string NewWorkspaceString
Sucht eine lokalisierte Zeichenfolge, die New Workspace ähnelt.