Files
2dust_v2rayN/v2rayN/v2rayN.Desktop/Views/SubSettingWindow.axaml.cs
T
DHR60 9664ee380e ViewModel-First (#9621)
* Interaction

* Remove view action

* ViewModel-first

* MainGirdOrientation Hot Reload

* Fix avalonia preview

* Remove CloseWindowInteraction

* Fix

* Avoid threading issues

* Fix

* ProfilesSelect

* Try fix previewer

* Remove AppEvents.ProfilesRefreshRequested

* Remove AppEvents.SubscriptionsRefreshRequested

* Remove AppEvents.ProxiesReloadRequested

* Remove AppEvents.AdjustMainLvColWidthRequested

* Remove AppEvents.SetDefaultServerRequested

* Remove AppEvents.RoutingsMenuRefreshRequested

* Remove AppEvents.TestServerRequested

* Remove AppEvents.InboundDisplayRequested

* Remove AppEvents.SubscriptionsUpdateRequested

* Remove AppEvents.ShowHideWindowRequested

* Remove AppEvents.ReloadRequested

* Remove AppEvents.AddServerRequested

* Fix
2026-07-14 09:05:05 +08:00

111 lines
3.8 KiB
C#

using DialogHostAvalonia;
using v2rayN.Desktop.Base;
using v2rayN.Desktop.Common;
namespace v2rayN.Desktop.Views;
public partial class SubSettingWindow : WindowBase<SubSettingViewModel>
{
private bool _manualClose = false;
public SubSettingWindow()
{
InitializeComponent();
menuClose.Click += menuClose_Click;
Loaded += Window_Loaded;
Closing += SubSettingWindow_Closing;
KeyDown += SubSettingWindow_KeyDown;
lstSubscription.DoubleTapped += LstSubscription_DoubleTapped;
lstSubscription.SelectionChanged += LstSubscription_SelectionChanged;
this.WhenActivated(disposables =>
{
this.OneWayBind(ViewModel, vm => vm.SubItems, v => v.lstSubscription.ItemsSource).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.SelectedSource, v => v.lstSubscription.SelectedItem).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SubAddCmd, v => v.menuSubAdd).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SubDeleteCmd, v => v.menuSubDelete).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SubEditCmd, v => v.menuSubEdit).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SubShareCmd, v => v.menuSubShare).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SubAddCmd, v => v.menuSubAdd2).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SubDeleteCmd, v => v.menuSubDelete2).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SubEditCmd, v => v.menuSubEdit2).DisposeWith(disposables);
this.BindCommand(ViewModel, vm => vm.SubShareCmd, v => v.menuSubShare2).DisposeWith(disposables);
ViewModel.ShowYesNoInteraction.RegisterHandler(async interaction =>
{
var message = interaction.Input;
var result = await UI.ShowYesNo(message);
interaction.SetOutput(result == ButtonResult.Yes);
}).DisposeWith(disposables);
ViewModel.ShareSubInteraction.RegisterHandler(async interaction =>
{
var url = interaction.Input;
if (url.IsNullOrEmpty())
{
interaction.SetOutput(Unit.Default);
return;
}
await ShareSub(url);
interaction.SetOutput(Unit.Default);
}).DisposeWith(disposables);
});
}
private async Task ShareSub(string url)
{
if (url.IsNullOrEmpty())
{
return;
}
var dialog = new QrcodeView(url);
await DialogHost.Show(dialog, "dialogHostSub");
}
private void LstSubscription_DoubleTapped(object? sender, Avalonia.Input.TappedEventArgs e)
{
ViewModel?.EditSubAsync(false);
}
private void LstSubscription_SelectionChanged(object? sender, SelectionChangedEventArgs e)
{
if (ViewModel != null)
{
ViewModel.SelectedSources = lstSubscription.SelectedItems.Cast<SubItem>().ToList();
}
}
private void menuClose_Click(object? sender, RoutedEventArgs e)
{
_manualClose = true;
Close(ViewModel?.IsModified);
}
private void SubSettingWindow_Closing(object? sender, WindowClosingEventArgs e)
{
if (ViewModel?.IsModified == true)
{
if (!_manualClose)
{
menuClose_Click(null, null);
}
}
}
private void SubSettingWindow_KeyDown(object? sender, KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
menuClose_Click(null, null);
}
}
private void Window_Loaded(object? sender, RoutedEventArgs e)
{
lstSubscription.Focus();
}
}