mirror of
https://github.com/2dust/v2rayN.git
synced 2026-10-30 09:05:01 +03:00
fix: remove Save/Cancel from routing settings, save edits immediately (#9133)
This commit is contained in:
@@ -5,15 +5,12 @@ namespace v2rayN.Desktop.Views;
|
||||
|
||||
public partial class RoutingSettingWindow : WindowBase<RoutingSettingViewModel>
|
||||
{
|
||||
private bool _manualClose = false;
|
||||
|
||||
public RoutingSettingWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Loaded += Window_Loaded;
|
||||
Closing += RoutingSettingWindow_Closing;
|
||||
btnCancel.Click += (s, e) => Close();
|
||||
KeyDown += RoutingSettingWindow_KeyDown;
|
||||
lstRoutings.SelectionChanged += lstRoutings_SelectionChanged;
|
||||
lstRoutings.DoubleTapped += LstRoutings_DoubleTapped;
|
||||
@@ -38,8 +35,6 @@ public partial class RoutingSettingWindow : WindowBase<RoutingSettingViewModel>
|
||||
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedSetDefaultCmd, v => v.menuRoutingAdvancedSetDefault).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedImportRulesCmd, v => v.menuRoutingAdvancedImportRules).DisposeWith(disposables);
|
||||
this.BindCommand(ViewModel, vm => vm.RoutingAdvancedImportRulesCmd, v => v.menuRoutingAdvancedImportRules2).DisposeWith(disposables);
|
||||
|
||||
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -47,10 +42,6 @@ public partial class RoutingSettingWindow : WindowBase<RoutingSettingViewModel>
|
||||
{
|
||||
switch (action)
|
||||
{
|
||||
case EViewAction.CloseWindow:
|
||||
Close(true);
|
||||
break;
|
||||
|
||||
case EViewAction.ShowYesNo:
|
||||
if (await UI.ShowYesNo(this, ResUI.RemoveRules) != ButtonResult.Yes)
|
||||
{
|
||||
@@ -69,6 +60,21 @@ public partial class RoutingSettingWindow : WindowBase<RoutingSettingViewModel>
|
||||
return await Task.FromResult(true);
|
||||
}
|
||||
|
||||
private bool _closed = false;
|
||||
|
||||
private void RoutingSettingWindow_Closing(object? sender, WindowClosingEventArgs e)
|
||||
{
|
||||
if (_closed) return;
|
||||
|
||||
// DomainStrategy is auto-saved reactively; just ensure the caller knows changes were made
|
||||
if (ViewModel?.IsModified == true)
|
||||
{
|
||||
e.Cancel = true;
|
||||
_closed = true;
|
||||
Close(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void RoutingSettingWindow_KeyDown(object? sender, KeyEventArgs e)
|
||||
{
|
||||
if (e.KeyModifiers is KeyModifiers.Control or KeyModifiers.Meta)
|
||||
@@ -125,25 +131,7 @@ public partial class RoutingSettingWindow : WindowBase<RoutingSettingViewModel>
|
||||
ProcUtils.ProcessStart("https://sing-box.sagernet.org/zh/configuration/route/rule_action/#strategy");
|
||||
}
|
||||
|
||||
private void btnCancel_Click(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
_manualClose = true;
|
||||
Close(ViewModel?.IsModified);
|
||||
}
|
||||
|
||||
private void RoutingSettingWindow_Closing(object? sender, WindowClosingEventArgs e)
|
||||
{
|
||||
if (ViewModel?.IsModified == true)
|
||||
{
|
||||
if (!_manualClose)
|
||||
{
|
||||
btnCancel_Click(null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Window_Loaded(object? sender, RoutedEventArgs e)
|
||||
{
|
||||
btnCancel.Focus();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user