2025-01-30 09:10:05 +00:00
|
|
|
using System.Reactive.Disposables;
|
2024-08-29 07:48:51 +00:00
|
|
|
using Avalonia.Interactivity;
|
2024-09-03 08:03:26 +00:00
|
|
|
using Avalonia.ReactiveUI;
|
2024-08-29 07:48:51 +00:00
|
|
|
using Avalonia.Threading;
|
|
|
|
using ReactiveUI;
|
|
|
|
using v2rayN.Desktop.Common;
|
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
namespace v2rayN.Desktop.Views;
|
|
|
|
|
|
|
|
public partial class MsgView : ReactiveUserControl<MsgViewModel>
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
public MsgView()
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
InitializeComponent();
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
ViewModel = new MsgViewModel(UpdateViewHandler);
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
this.WhenActivated(disposables =>
|
|
|
|
{
|
|
|
|
this.Bind(ViewModel, vm => vm.MsgFilter, v => v.cmbMsgFilter.Text).DisposeWith(disposables);
|
|
|
|
this.Bind(ViewModel, vm => vm.AutoRefresh, v => v.togAutoRefresh.IsChecked).DisposeWith(disposables);
|
|
|
|
});
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private async Task<bool> UpdateViewHandler(EViewAction action, object? obj)
|
|
|
|
{
|
|
|
|
switch (action)
|
2024-09-03 08:03:26 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
case EViewAction.DispatcherShowMsg:
|
|
|
|
if (obj is null)
|
|
|
|
return false;
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
Dispatcher.UIThread.Post(() =>
|
|
|
|
ShowMsg(obj),
|
|
|
|
DispatcherPriority.ApplicationIdle);
|
|
|
|
break;
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
2025-04-02 03:44:23 +00:00
|
|
|
return await Task.FromResult(true);
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private void ShowMsg(object msg)
|
|
|
|
{
|
|
|
|
txtMsg.Text = msg.ToString();
|
|
|
|
if (togScrollToEnd.IsChecked ?? true)
|
2024-08-29 07:48:51 +00:00
|
|
|
{
|
2025-04-02 03:44:23 +00:00
|
|
|
txtMsg.CaretIndex = int.MaxValue;
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
2025-04-02 03:44:23 +00:00
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
public void ClearMsg()
|
|
|
|
{
|
|
|
|
ViewModel?.ClearMsg();
|
|
|
|
txtMsg.Clear();
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private void menuMsgViewSelectAll_Click(object? sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
txtMsg.Focus();
|
|
|
|
txtMsg.SelectAll();
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private async void menuMsgViewCopy_Click(object? sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
var data = txtMsg.SelectedText.TrimEx();
|
|
|
|
await AvaUtils.SetClipboardData(this, data);
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private async void menuMsgViewCopyAll_Click(object? sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
var data = txtMsg.Text.TrimEx();
|
|
|
|
await AvaUtils.SetClipboardData(this, data);
|
|
|
|
}
|
2024-08-29 07:48:51 +00:00
|
|
|
|
2025-04-02 03:44:23 +00:00
|
|
|
private void menuMsgViewClear_Click(object? sender, RoutedEventArgs e)
|
|
|
|
{
|
|
|
|
ClearMsg();
|
2024-08-29 07:48:51 +00:00
|
|
|
}
|
2025-01-30 09:10:05 +00:00
|
|
|
}
|