Skip to content

Commit 852c90f

Browse files
committed
Improve UI interaction for saving and applying
1 parent 4a76248 commit 852c90f

File tree

4 files changed

+68
-26
lines changed

4 files changed

+68
-26
lines changed

IPConfig/Languages/Lang.Designer.cs

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IPConfig/Languages/Lang.en.resx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@
299299
<data name="Ethernet_Lower" xml:space="preserve">
300300
<value>ethernet</value>
301301
</data>
302+
<data name="ExportFailed" xml:space="preserve">
303+
<value>Export failed</value>
304+
</data>
305+
<data name="ExportSuccessful" xml:space="preserve">
306+
<value>Export successful</value>
307+
</data>
302308
<data name="ExportToCsv_" xml:space="preserve">
303309
<value>Export to _CSV...</value>
304310
</data>
@@ -317,12 +323,6 @@
317323
<data name="ExportToPlaintext_FileDialogTitle" xml:space="preserve">
318324
<value>Export to Plaintext</value>
319325
</data>
320-
<data name="ExportFailed" xml:space="preserve">
321-
<value>Export failed</value>
322-
</data>
323-
<data name="ExportSuccessful" xml:space="preserve">
324-
<value>Export successful</value>
325-
</data>
326326
<data name="ForwardingEnabled" xml:space="preserve">
327327
<value>Forwarding Enabled</value>
328328

@@ -603,6 +603,9 @@
603603
<data name="ValidationError" xml:space="preserve">
604604
<value>Configuration contains validation errors</value>
605605
</data>
606+
<data name="ValidationErrorWarning" xml:space="preserve">
607+
<value>Warning: Configuration contains validation errors!</value>
608+
</data>
606609
<data name="ValidLifetime" xml:space="preserve">
607610
<value>Valid Lifetime</value>
608611
</data>

IPConfig/Languages/Lang.resx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,14 @@
337337
<value>以太网</value>
338338
<comment>Nic</comment>
339339
</data>
340+
<data name="ExportFailed" xml:space="preserve">
341+
<value>导出失败</value>
342+
<comment>NicConfigDetailViewModel</comment>
343+
</data>
344+
<data name="ExportSuccessful" xml:space="preserve">
345+
<value>导出成功</value>
346+
<comment>NicConfigDetailViewModel</comment>
347+
</data>
340348
<data name="ExportToCsv_" xml:space="preserve">
341349
<value>导出到 _CSV...</value>
342350
<comment>NicConfigDetailView</comment>
@@ -361,14 +369,6 @@
361369
<value>导出到 文本文档</value>
362370
<comment>NicConfigDetailViewModel</comment>
363371
</data>
364-
<data name="ExportFailed" xml:space="preserve">
365-
<value>导出失败</value>
366-
<comment>NicConfigDetailViewModel</comment>
367-
</data>
368-
<data name="ExportSuccessful" xml:space="preserve">
369-
<value>导出成功</value>
370-
<comment>NicConfigDetailViewModel</comment>
371-
</data>
372372
<data name="ForwardingEnabled" xml:space="preserve">
373373
<value>已启用转发(路由)</value>
374374
<comment>NicConfigDetailView</comment>
@@ -739,6 +739,10 @@
739739
<value>配置存在验证错误</value>
740740
<comment>IPConfigDetailViewModel</comment>
741741
</data>
742+
<data name="ValidationErrorWarning" xml:space="preserve">
743+
<value>警告:配置存在验证错误!</value>
744+
<comment>IPConfigDetailViewModel</comment>
745+
</data>
742746
<data name="ValidLifetime" xml:space="preserve">
743747
<value>有效剩余</value>
744748
<comment>NicConfigDetailView</comment>

IPConfig/ViewModels/IPConfigDetailViewModel.cs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ public partial class IPConfigDetailViewModel : ObservableRecipient, IEditableObj
4444

4545
private bool _inTxn;
4646

47+
private bool _isSaveSuccessful;
48+
4749
private bool _loaded;
4850

4951
private Nic? _nic;
5052

51-
private bool _saved;
52-
5353
#endregion Fields
5454

5555
#region ObservableProperties
@@ -391,20 +391,28 @@ private static async Task PingDnsGroupAsync(CollectionViewGroup group)
391391
[RelayCommand]
392392
private void Apply()
393393
{
394-
FormatInput();
395-
396394
if (_nic is null)
397395
{
398396
Growl.Error(Lang.ApplyFailed);
399397

400398
return;
401399
}
402400

401+
FormatInput();
402+
Validate(false);
403+
404+
string msg = Lang.ApplyAsk_Format.Format(_nic.Name, _nic.Description);
405+
406+
if (EditingIPConfig.HasErrors)
407+
{
408+
msg = $"{msg}\n\n{Lang.ValidationErrorWarning}";
409+
}
410+
403411
var result = HcMessageBox.Show(
404-
Lang.ApplyAsk_Format.Format(_nic.Name, _nic.Description),
412+
msg,
405413
App.AppName,
406414
MessageBoxButton.OKCancel,
407-
MessageBoxImage.Question,
415+
EditingIPConfig.HasErrors ? MessageBoxImage.Warning : MessageBoxImage.Question,
408416
MessageBoxResult.OK);
409417

410418
if (result != MessageBoxResult.OK)
@@ -526,7 +534,7 @@ private void Save()
526534
{
527535
Growl.Error(Lang.SaveFailedValidationError);
528536

529-
_saved = false;
537+
_isSaveSuccessful = false;
530538

531539
return;
532540
}
@@ -552,13 +560,13 @@ private void Save()
552560

553561
EditingIPConfig.AcceptChanges();
554562

555-
_saved = true;
563+
_isSaveSuccessful = true;
556564
}
557565
catch (Exception ex)
558566
{
559567
Growl.Error($"{Lang.SaveFailed}\n\n{ex.Message}");
560568

561-
_saved = false;
569+
_isSaveSuccessful = false;
562570
}
563571
}
564572

@@ -567,7 +575,7 @@ private void SaveAndApply()
567575
{
568576
Save();
569577

570-
if (_saved)
578+
if (_isSaveSuccessful)
571579
{
572580
Apply();
573581
}
@@ -616,10 +624,15 @@ private void TryAutoCompleteGateway()
616624
}
617625

618626
[RelayCommand]
619-
private void Validate()
627+
private void Validate(bool showGrowl = true)
620628
{
621629
EditingIPConfig.ValidateAllProperties();
622630

631+
if (!showGrowl)
632+
{
633+
return;
634+
}
635+
623636
if (EditingIPConfig.HasErrors)
624637
{
625638
Growl.Error(Lang.ValidationError);
@@ -726,7 +739,10 @@ private static IEnumerable<IPv4Dns> ReadIPv4DnsList()
726739

727740
private void FormatInput()
728741
{
729-
EditingIPConfig?.IPv4Config.FormatProperties();
742+
if (EditingIPConfig.IsChanged)
743+
{
744+
EditingIPConfig.IPv4Config.FormatProperties();
745+
}
730746
}
731747

732748
private string GetAutoCompleteDns1()

0 commit comments

Comments
 (0)