Persist message auto-scroll setting

This commit is contained in:
Vinny 2026-05-08 07:42:26 +03:00
parent e6f1efd4f4
commit 9326a4ad79
4 changed files with 17 additions and 5 deletions

View file

@ -83,6 +83,7 @@ public class MsgUIItem
{
public string? MainMsgFilter { get; set; }
public bool? AutoRefresh { get; set; }
public bool? AutoScrollToEnd { get; set; }
}
[Serializable]

View file

@ -13,12 +13,16 @@ public class MsgViewModel : MyReactiveObject
[Reactive]
public bool AutoRefresh { get; set; }
[Reactive]
public bool AutoScrollToEnd { get; set; }
public MsgViewModel(Func<EViewAction, object?, Task<bool>>? updateView)
{
_config = AppManager.Instance.Config;
_updateView = updateView;
MsgFilter = _config.MsgUIItem.MainMsgFilter ?? string.Empty;
AutoRefresh = _config.MsgUIItem.AutoRefresh ?? true;
AutoScrollToEnd = _config.MsgUIItem.AutoScrollToEnd ?? true;
this.WhenAnyValue(
x => x.MsgFilter)
@ -29,6 +33,11 @@ public class MsgViewModel : MyReactiveObject
y => y == true)
.Subscribe(c => _config.MsgUIItem.AutoRefresh = AutoRefresh);
this.WhenAnyValue(
x => x.AutoScrollToEnd,
y => y == true)
.Subscribe(c => _config.MsgUIItem.AutoScrollToEnd = AutoScrollToEnd);
AppEvents.SendMsgViewRequested
.AsObservable()
//.ObserveOn(RxSchedulers.MainThreadScheduler)

View file

@ -16,6 +16,7 @@ public partial class MsgView : ReactiveUserControl<MsgViewModel>
{
this.Bind(ViewModel, vm => vm.MsgFilter, v => v.cmbMsgFilter.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.AutoRefresh, v => v.togAutoRefresh.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.AutoScrollToEnd, v => v.togScrollToEnd.IsChecked).DisposeWith(disposables);
});
TextEditorKeywordHighlighter.Attach(txtMsg, Global.LogLevelColors.ToDictionary(
@ -55,7 +56,7 @@ public partial class MsgView : ReactiveUserControl<MsgViewModel>
}
txtMsg.AppendText(msg.ToString());
if (togScrollToEnd.IsChecked ?? true)
if (ViewModel?.AutoScrollToEnd == true)
{
txtMsg.ScrollToEnd();
}

View file

@ -12,6 +12,7 @@ public partial class MsgView
{
this.Bind(ViewModel, vm => vm.MsgFilter, v => v.cmbMsgFilter.Text).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.AutoRefresh, v => v.togAutoRefresh.IsChecked).DisposeWith(disposables);
this.Bind(ViewModel, vm => vm.AutoScrollToEnd, v => v.togScrollToEnd.IsChecked).DisposeWith(disposables);
});
btnCopy.Click += menuMsgViewCopyAll_Click;
@ -51,7 +52,7 @@ public partial class MsgView
}
txtMsg.AppendText(msg.ToString());
if (togScrollToEnd.IsChecked ?? true)
if (ViewModel?.AutoScrollToEnd == true)
{
txtMsg.ScrollToEnd();
}