From ff920250260c89840bfee3f514d79d5a2a82a61d Mon Sep 17 00:00:00 2001 From: Guilherme Ornel <86210200+joshepvodka@users.noreply.github.com> Date: Tue, 13 Feb 2024 22:14:51 -0300 Subject: [PATCH] Fax machines can print from text file (#23262) * added * checks tweaking * fixed what sloth wanted * fixed? * dialog diposing fix * checks tweaking * more changes * dispose streamreader * Update Content.Client/Fax/UI/FaxBoundUi.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Fax/FaxSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * fix minor typo --------- Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> --- Content.Client/Fax/UI/FaxBoundUi.cs | 28 ++++++++++++++++++++++ Content.Client/Fax/UI/FaxWindow.xaml | 8 +++++++ Content.Client/Fax/UI/FaxWindow.xaml.cs | 19 +++++++++++++++ Content.Server/Fax/FaxSystem.cs | 31 +++++++++++++++++++++++++ Content.Shared/Fax/SharedFax.cs | 18 ++++++++++++++ Resources/Locale/en-US/fax/fax.ftl | 5 ++++ 6 files changed, 109 insertions(+) diff --git a/Content.Client/Fax/UI/FaxBoundUi.cs b/Content.Client/Fax/UI/FaxBoundUi.cs index ef6661b3ef..9b57595d7b 100644 --- a/Content.Client/Fax/UI/FaxBoundUi.cs +++ b/Content.Client/Fax/UI/FaxBoundUi.cs @@ -1,15 +1,22 @@ +using System.IO; +using System.Threading.Tasks; using Content.Shared.Fax; using JetBrains.Annotations; using Robust.Client.GameObjects; +using Robust.Client.UserInterface; namespace Content.Client.Fax.UI; [UsedImplicitly] public sealed class FaxBoundUi : BoundUserInterface { + [Dependency] private readonly IFileDialogManager _fileDialogManager = default!; + [ViewVariables] private FaxWindow? _window; + private bool _dialogIsOpen = false; + public FaxBoundUi(EntityUid owner, Enum uiKey) : base(owner, uiKey) { } @@ -22,12 +29,33 @@ public sealed class FaxBoundUi : BoundUserInterface _window.OpenCentered(); _window.OnClose += Close; + _window.FileButtonPressed += OnFileButtonPressed; _window.CopyButtonPressed += OnCopyButtonPressed; _window.SendButtonPressed += OnSendButtonPressed; _window.RefreshButtonPressed += OnRefreshButtonPressed; _window.PeerSelected += OnPeerSelected; } + private async void OnFileButtonPressed() + { + if (_dialogIsOpen) + return; + + _dialogIsOpen = true; + var filters = new FileDialogFilters(new FileDialogFilters.Group("txt")); + await using var file = await _fileDialogManager.OpenFile(filters); + _dialogIsOpen = false; + + if (_window == null || _window.Disposed || file == null) + { + return; + } + + using var reader = new StreamReader(file); + var content = await reader.ReadToEndAsync(); + SendMessage(new FaxFileMessage(content[..Math.Min(content.Length, FaxFileMessageValidation.MaxContentSize)], _window.OfficePaper)); + } + private void OnSendButtonPressed() { SendMessage(new FaxSendMessage()); diff --git a/Content.Client/Fax/UI/FaxWindow.xaml b/Content.Client/Fax/UI/FaxWindow.xaml index 1e6ef23376..ce22b0e412 100644 --- a/Content.Client/Fax/UI/FaxWindow.xaml +++ b/Content.Client/Fax/UI/FaxWindow.xaml @@ -19,6 +19,14 @@ + +