mirror of
https://github.com/2dust/v2rayN.git
synced 2025-10-13 20:09:12 +00:00
Update MsgView.axaml.cs
This commit is contained in:
parent
004c695b6a
commit
10b18efcaf
1 changed files with 18 additions and 11 deletions
|
@ -9,10 +9,12 @@ namespace v2rayN.Desktop.Views;
|
||||||
|
|
||||||
public partial class MsgView : ReactiveUserControl<MsgViewModel>
|
public partial class MsgView : ReactiveUserControl<MsgViewModel>
|
||||||
{
|
{
|
||||||
|
private const int MaxLines = 350;
|
||||||
|
private const int KeepLines = 320;
|
||||||
|
|
||||||
public MsgView()
|
public MsgView()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
|
|
||||||
ViewModel = new MsgViewModel(UpdateViewHandler);
|
ViewModel = new MsgViewModel(UpdateViewHandler);
|
||||||
|
|
||||||
this.WhenActivated(disposables =>
|
this.WhenActivated(disposables =>
|
||||||
|
@ -30,8 +32,7 @@ public partial class MsgView : ReactiveUserControl<MsgViewModel>
|
||||||
if (obj is null)
|
if (obj is null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
Dispatcher.UIThread.Post(() =>
|
Dispatcher.UIThread.Post(() => ShowMsg(obj),
|
||||||
ShowMsg(obj),
|
|
||||||
DispatcherPriority.ApplicationIdle);
|
DispatcherPriority.ApplicationIdle);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -40,29 +41,35 @@ public partial class MsgView : ReactiveUserControl<MsgViewModel>
|
||||||
|
|
||||||
private void ShowMsg(object msg)
|
private void ShowMsg(object msg)
|
||||||
{
|
{
|
||||||
if (txtMsg.Document.LineCount > ViewModel?.NumMaxMsg)
|
txtMsg.AppendText(msg.ToString());
|
||||||
|
|
||||||
|
if (txtMsg.Document.LineCount > MaxLines)
|
||||||
{
|
{
|
||||||
ClearMsg();
|
var lc = txtMsg.Document.LineCount;
|
||||||
|
var cutLineNumber = lc - KeepLines;
|
||||||
|
var cutLine = txtMsg.Document.GetLineByNumber(cutLineNumber);
|
||||||
|
txtMsg.Document.Remove(0, cutLine.Offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (togScrollToEnd.IsChecked ?? true)
|
if (togScrollToEnd.IsChecked ?? true)
|
||||||
{
|
{
|
||||||
//txtMsg.ScrollToLine(txtMsg.Document.LineCount);
|
|
||||||
txtMsg.ScrollToEnd();
|
txtMsg.ScrollToEnd();
|
||||||
}
|
}
|
||||||
txtMsg.AppendText(msg.ToString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearMsg()
|
public void ClearMsg()
|
||||||
{
|
{
|
||||||
txtMsg.Clear();
|
txtMsg.Text = string.Empty;
|
||||||
txtMsg.AppendText("----- Message cleared -----\n");
|
txtMsg.AppendText("----- Message cleared -----\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void menuMsgViewSelectAll_Click(object? sender, RoutedEventArgs e)
|
private void menuMsgViewSelectAll_Click(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
txtMsg.Focus();
|
Dispatcher.UIThread.Post(() =>
|
||||||
|
{
|
||||||
|
txtMsg.TextArea.Focus();
|
||||||
txtMsg.SelectAll();
|
txtMsg.SelectAll();
|
||||||
|
}, DispatcherPriority.Render);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void menuMsgViewCopy_Click(object? sender, RoutedEventArgs e)
|
private async void menuMsgViewCopy_Click(object? sender, RoutedEventArgs e)
|
||||||
|
|
Loading…
Reference in a new issue