using DialogHostAvalonia; using v2rayN.Desktop.Base; using v2rayN.Desktop.Common; namespace v2rayN.Desktop.Views; public partial class SubSettingWindow : WindowBase { 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(RxVoid.Default); return; } await ShareSub(url); interaction.SetOutput(RxVoid.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().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(); } }