Skip to content

Commit

Permalink
feat: Fill OutputHistoryModel from FormStatus
Browse files Browse the repository at this point in the history
  • Loading branch information
mstv committed May 27, 2024
1 parent ce4f255 commit 844ecc1
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 7 deletions.
2 changes: 0 additions & 2 deletions src/app/GitUI/HelperDialogs/FormProcess.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ namespace GitUI.HelperDialogs
public partial class FormProcess : FormStatus
{
public string Remote { get; set; }
public string ProcessString { get; }
public string ProcessArguments { get; set; }
public string? ProcessInput { get; }
public readonly string WorkingDirectory;
public HandleOnExit? HandleOnExitCallback { get; set; }
Expand Down
27 changes: 22 additions & 5 deletions src/app/GitUI/HelperDialogs/FormStatus.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using System.Diagnostics;
using GitCommands;
using GitExtensions.Extensibility.Git;
using GitExtUtils;
using GitUI.Models;
using GitUI.Properties;
using GitUI.UserControls;
using Microsoft.WindowsAPICodePack.Taskbar;
Expand Down Expand Up @@ -51,6 +54,9 @@ public FormStatus(IGitUICommands commands, ConsoleOutputControl? consoleOutput,
InitializeComplete();
}

public string? ProcessString { get; protected init; }
public string? ProcessArguments { get; set; }

/// <summary>
/// Clean up any resources being used.
/// </summary>
Expand Down Expand Up @@ -121,7 +127,7 @@ public static void ShowErrorDialog(IWin32Window owner, IGitUICommands commands,
form.StartPosition = FormStartPosition.CenterParent;

// We know that an operation (whatever it may have been) has failed, so set the error state.
form.Done(false);
form.Done(isSuccess: false);

form.ShowDialog(owner);
}
Expand Down Expand Up @@ -156,6 +162,18 @@ private protected void Done(bool isSuccess)
{
try
{
_errorOccurred = !isSuccess;

try
{
RunProcessInfo runProcessInfo = new(ProcessString, ProcessArguments, GetOutputString(), DateTime.Now);
UICommands.GetRequiredService<IOutputHistoryModel>().Trace(runProcessInfo);
}
catch (Exception exception)
{
Trace.WriteLine(exception);
}

AppendMessage("Done");
ProgressBar.Visible = false;
Ok.Enabled = true;
Expand All @@ -167,16 +185,15 @@ private protected void Done(bool isSuccess)
Bitmap image = isSuccess ? Images.StatusBadgeSuccess : Images.StatusBadgeError;
SetIcon(image);

_errorOccurred = !isSuccess;

if (isSuccess && (_useDialogSettings && AppSettings.CloseProcessDialog))
{
Close();
}
}
catch (ConEmu.WinForms.GuiMacroExecutor.GuiMacroException)
catch (ConEmu.WinForms.GuiMacroExecutor.GuiMacroException guiMacroException)
{
// Do nothing
Trace.WriteLine(guiMacroException);
}
}

Expand Down Expand Up @@ -242,7 +259,7 @@ private void Abort_Click(object sender, EventArgs e)
{
AbortCallback?.Invoke(this);
OutputLog.Append(Environment.NewLine + "Aborted"); // TODO: write to display control also, if we pull the function up to this base class
Done(false);
Done(isSuccess: false);
DialogResult = DialogResult.Abort;
}
catch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using GitExtUtils;
using GitUI;
using GitUI.Hotkey;
using GitUI.Models;
using GitUI.ScriptsEngine;
using NSubstitute;
using ResourceManager;
Expand All @@ -15,6 +16,9 @@ public static class GlobalServiceContainer
public static ServiceContainer CreateDefaultMockServiceContainer()
{
ServiceContainer serviceContainer = new();

serviceContainer.AddService(Substitute.For<IOutputHistoryModel>());

serviceContainer.AddService(Substitute.For<IAppTitleGenerator>());
serviceContainer.AddService(Substitute.For<IWindowsJumpListManager>());
serviceContainer.AddService(Substitute.For<ILinkFactory>());
Expand Down

0 comments on commit 844ecc1

Please sign in to comment.