Browse Source

added auto scroll to end on console

pull/55/head
JT 1 year ago
parent
commit
61de972f31
  1. 1
      StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs
  2. 4
      StabilityMatrix.Avalonia/Views/LaunchPageView.axaml
  3. 19
      StabilityMatrix.Avalonia/Views/LaunchPageView.axaml.cs
  4. 3
      StabilityMatrix.Core/Helper/EventManager.cs

1
StabilityMatrix.Avalonia/ViewModels/LaunchPageViewModel.cs

@ -263,6 +263,7 @@ public partial class LaunchPageViewModel : PageViewModelBase, IDisposable
private void OnProcessOutputReceived(object? sender, ProcessOutput output)
{
consoleUpdateBuffer.Post(output);
EventManager.Instance.OnScrollToBottomRequested();
}
private void OnOneClickInstallFinished(object? sender, bool e)

4
StabilityMatrix.Avalonia/Views/LaunchPageView.axaml

@ -94,9 +94,7 @@
ShowLineNumbers="True"
VerticalScrollBarVisibility="Auto"
WordWrap="True" />
<!-- Command="{Binding LaunchWebUiCommand}" -->
<!-- Visibility="{Binding ShowWebUiButton, Converter={StaticResource BoolToVisConverter}}" -->
<Button
Grid.Row="2"
Grid.ColumnSpan="2"

19
StabilityMatrix.Avalonia/Views/LaunchPageView.axaml.cs

@ -1,15 +1,19 @@
using System;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using Avalonia.Threading;
using AvaloniaEdit;
using AvaloniaEdit.TextMate;
using StabilityMatrix.Avalonia.Controls;
using StabilityMatrix.Core.Helper;
using TextMateSharp.Grammars;
namespace StabilityMatrix.Avalonia.Views;
public partial class LaunchPageView : UserControlBase
{
private const int LineOffset = 5;
public LaunchPageView()
{
InitializeComponent();
@ -23,8 +27,21 @@ public partial class LaunchPageView : UserControlBase
textMate.SetGrammar(scope);
textMate.SetTheme(options.LoadTheme(ThemeName.DarkPlus));
EventManager.Instance.ScrollToBottomRequested += OnScrollToBottomRequested;
}
private void OnScrollToBottomRequested(object? sender, EventArgs e)
{
Dispatcher.UIThread.Invoke(() =>
{
var editor = this.FindControl<TextEditor>("Console");
if (editor == null) return;
var line = Math.Max(editor.Document.LineCount - LineOffset, 1);
editor.ScrollToLine(line);
});
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);

3
StabilityMatrix.Core/Helper/EventManager.cs

@ -19,6 +19,7 @@ public class EventManager
public event EventHandler<bool>? DevModeSettingChanged;
public event EventHandler<UpdateInfo>? UpdateAvailable;
public event EventHandler<Guid> PackageLaunchRequested;
public event EventHandler? ScrollToBottomRequested;
public void OnGlobalProgressChanged(int progress) => GlobalProgressChanged?.Invoke(this, progress);
public void RequestPageChange(Type pageType) => PageChangeRequested?.Invoke(this, pageType);
public void OnInstalledPackagesChanged() => InstalledPackagesChanged?.Invoke(this, EventArgs.Empty);
@ -28,4 +29,6 @@ public class EventManager
public void OnUpdateAvailable(UpdateInfo args) => UpdateAvailable?.Invoke(this, args);
public void OnPackageLaunchRequested(Guid packageId) =>
PackageLaunchRequested?.Invoke(this, packageId);
public void OnScrollToBottomRequested() =>
ScrollToBottomRequested?.Invoke(this, EventArgs.Empty);
}

Loading…
Cancel
Save