From 2de1a12e425ebc76313caa1189eda9ea8ecfccf5 Mon Sep 17 00:00:00 2001 From: rmbgame Date: Sat, 3 Jul 2021 09:00:25 +0800 Subject: [PATCH] ConsoleShell --- references/ArchiSteamFarm | 2 +- .../UI/Views/Controls/AvaloniaShell.axaml | 18 ---- .../UI/Views/Controls/AvaloniaShell.axaml.cs | 19 ---- .../UI/Views/Controls/ConsoleShell.axaml | 34 +++++++ .../UI/Views/Controls/ConsoleShell.axaml.cs | 96 +++++++++++++++++++ .../Application/UI/Views/MainView.axaml | 2 +- .../Views/Pages/ArchiSteamFarmPlusPage.axaml | 10 +- .../Pages/ArchiSteamFarmPlusPage.axaml.cs | 15 ++- .../ST.Client.Desktop.Avalonia.csproj | 6 ++ 9 files changed, 155 insertions(+), 47 deletions(-) delete mode 100644 src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/AvaloniaShell.axaml delete mode 100644 src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/AvaloniaShell.axaml.cs create mode 100644 src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/ConsoleShell.axaml create mode 100644 src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/ConsoleShell.axaml.cs diff --git a/references/ArchiSteamFarm b/references/ArchiSteamFarm index 0e8796909..11705eb67 160000 --- a/references/ArchiSteamFarm +++ b/references/ArchiSteamFarm @@ -1 +1 @@ -Subproject commit 0e8796909b3debe4759bdb202b109375cbcf2615 +Subproject commit 11705eb67e702ac35cf951baa4aedc4af8c2c5df diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/AvaloniaShell.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/AvaloniaShell.axaml deleted file mode 100644 index 0cdeb5b16..000000000 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/AvaloniaShell.axaml +++ /dev/null @@ -1,18 +0,0 @@ - - - diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/AvaloniaShell.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/AvaloniaShell.axaml.cs deleted file mode 100644 index 054eaec53..000000000 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/AvaloniaShell.axaml.cs +++ /dev/null @@ -1,19 +0,0 @@ -using Avalonia; -using Avalonia.Controls; -using Avalonia.Markup.Xaml; - -namespace System.Application.UI.Views.Controls -{ - public partial class AvaloniaShell : UserControl - { - public AvaloniaShell() - { - InitializeComponent(); - } - - private void InitializeComponent() - { - AvaloniaXamlLoader.Load(this); - } - } -} diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/ConsoleShell.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/ConsoleShell.axaml new file mode 100644 index 000000000..77423af34 --- /dev/null +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/ConsoleShell.axaml @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/ConsoleShell.axaml.cs b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/ConsoleShell.axaml.cs new file mode 100644 index 000000000..0d61dcb15 --- /dev/null +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/Controls/ConsoleShell.axaml.cs @@ -0,0 +1,96 @@ +using Avalonia; +using Avalonia.Controls; +using Avalonia.Markup.Xaml; +using ReactiveUI; +using System.Collections.ObjectModel; +using System.Text; + +namespace System.Application.UI.Views.Controls +{ + public partial class ConsoleShell : UserControl + { + public const string InputIndicator = "> "; + public const string OutputIndicator = "< "; + + ///// + ///// Defines the property. + ///// + //public static readonly StyledProperty LogTextsProperty = + // AvaloniaProperty.Register(nameof(LogTexts), null); + + ///// + ///// 输出日志字符串集合 + ///// + //public IEnumerable? LogTexts + //{ + // get => GetValue(LogTextsProperty); + // set => SetValue(LogTextsProperty, value); + //} + + public StringBuilder LogText { get; set; } = new StringBuilder(); + + private CommandEventArgs? _commandSubmitArgs; + /// + /// 输入命令后按下回车触发 + /// + public event EventHandler? CommandSubmit; + + + private TextBox commandTextbox; + private TextBox logTextbox; + + public ConsoleShell() + { + InitializeComponent(); + + logTextbox = this.FindControl("LogTextbox"); + + commandTextbox = this.FindControl("CommandTextbox"); + commandTextbox.KeyUp += CommandTextbox_KeyUp; + + //this.WhenAnyValue(x=>x.LogTexts) + // .Subscribe(x=>x.); + } + + private void CommandTextbox_KeyUp(object? sender, Avalonia.Input.KeyEventArgs e) + { + if (e.Key == Avalonia.Input.Key.Enter) + { + OnCommandSubmit(commandTextbox.Text); + commandTextbox.Text = string.Empty; + } + } + + internal void OnCommandSubmit(string command) + { + if (CommandSubmit != null) + { + if (_commandSubmitArgs == null) + { + _commandSubmitArgs = new CommandEventArgs(); + } + else + { + _commandSubmitArgs.Command = command; + } + CommandSubmit(this, _commandSubmitArgs); + } + } + + public void AppendLogText(string text) + { + LogText.AppendLine(OutputIndicator + text); + logTextbox.Text = LogText.ToString(); + } + + private void InitializeComponent() + { + AvaloniaXamlLoader.Load(this); + } + } + + public class CommandEventArgs : EventArgs + { + public string? Command { get; set; } + } +} diff --git a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/MainView.axaml b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/MainView.axaml index 901f28dea..25f6aa3e6 100644 --- a/src/ST.Client.Desktop.Avalonia/Application/UI/Views/MainView.axaml +++ b/src/ST.Client.Desktop.Avalonia/Application/UI/Views/MainView.axaml @@ -99,7 +99,7 @@ - +