From e8c8b77279b1bd1884eb4e807e6d9576221acbf5 Mon Sep 17 00:00:00 2001 From: Luthetus <45454132+huntercfreeman@users.noreply.github.com> Date: Fri, 3 May 2024 16:15:58 -0400 Subject: [PATCH] Git commit --- .../GitChangesTreeViewDisplay.razor.cs | 10 ++-- .../Gits/Displays/GitControlsDisplay.razor.cs | 44 +++++++++++---- .../Gits/Displays/GitDiffDisplay.razor | 7 +++ .../Gits/Displays/GitDiffDisplay.razor.cs | 55 +++++++++++++++++++ .../Models/GitTreeViewMouseEventHandler.cs | 55 +++++++++++++++++++ 5 files changed, 156 insertions(+), 15 deletions(-) create mode 100644 Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitDiffDisplay.razor create mode 100644 Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitDiffDisplay.razor.cs create mode 100644 Source/Lib/Ide/Ide.RazorLib/Gits/Models/GitTreeViewMouseEventHandler.cs diff --git a/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitChangesTreeViewDisplay.razor.cs b/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitChangesTreeViewDisplay.razor.cs index c0e518fbd..c8ecb5148 100644 --- a/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitChangesTreeViewDisplay.razor.cs +++ b/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitChangesTreeViewDisplay.razor.cs @@ -32,8 +32,8 @@ public partial class GitChangesTreeViewDisplay : ComponentBase public GitState GitState { get; set; } = null!; private TreeViewCommandArgs? _mostRecentTreeViewCommandArgs; - private TreeViewKeyboardEventHandler _treeViewKeyboardEventHandler = null!; - private TreeViewMouseEventHandler _treeViewMouseEventHandler = null!; + private GitTreeViewKeyboardEventHandler _treeViewKeyboardEventHandler = null!; + private GitTreeViewMouseEventHandler _treeViewMouseEventHandler = null!; private int OffsetPerDepthInPixels => (int)Math.Ceiling( AppOptionsStateWrap.Value.Options.IconSizeInPixels * (2.0 / 3.0)); @@ -46,9 +46,11 @@ protected override void OnInitialized() GitStateWrap, Dispatcher); - _treeViewMouseEventHandler = new TreeViewMouseEventHandler( + _treeViewMouseEventHandler = new GitTreeViewMouseEventHandler( TreeViewService, - BackgroundTaskService); + BackgroundTaskService, + GitStateWrap, + Dispatcher); base.OnInitialized(); } diff --git a/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitControlsDisplay.razor.cs b/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitControlsDisplay.razor.cs index 0e46caf96..de1103f73 100644 --- a/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitControlsDisplay.razor.cs +++ b/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitControlsDisplay.razor.cs @@ -6,7 +6,6 @@ using Luthetus.Ide.RazorLib.Terminals.Models; using Luthetus.Ide.RazorLib.Terminals.States; using Microsoft.AspNetCore.Components; -using System.Collections.Immutable; using System.Text; namespace Luthetus.Ide.RazorLib.Gits.Displays; @@ -25,7 +24,8 @@ public partial class GitControlsDisplay : ComponentBase private string _summary = string.Empty; - public Key NewDotNetSolutionTerminalCommandKey { get; } = Key.NewKey(); + public Key GitStatusTerminalCommandKey { get; } = Key.NewKey(); + public Key GitCommitTerminalCommandKey { get; } = Key.NewKey(); private async Task ExecuteGitStatusTerminalCommandOnClick() { @@ -46,18 +46,14 @@ private async Task ExecuteGitStatusTerminalCommandOnClick() var gitCliOutputParser = new GitCliOutputParser( Dispatcher, - GitState, + localGitState, EnvironmentProvider.AbsolutePathFactory(parentDirectory.Value, true), EnvironmentProvider); var gitStatusCommand = new TerminalCommand( - NewDotNetSolutionTerminalCommandKey, + GitStatusTerminalCommandKey, formattedCommand, parentDirectory.Value, - ContinueWith: () => - { - return Task.CompletedTask; - }, OutputParser: gitCliOutputParser); var generalTerminal = TerminalStateWrap.Value.TerminalMap[TerminalFacts.GENERAL_TERMINAL_KEY]; @@ -66,7 +62,8 @@ private async Task ExecuteGitStatusTerminalCommandOnClick() private async Task SubmitOnClick(GitState localGitState) { - if (string.IsNullOrWhiteSpace(_summary)) + var localSummary = _summary; + if (string.IsNullOrWhiteSpace(localSummary)) return; if (localGitState.GitFolderAbsolutePath?.ParentDirectory is null) @@ -108,11 +105,36 @@ private async Task SubmitOnClick(GitState localGitState) }; var gitAddCommand = new TerminalCommand( - NewDotNetSolutionTerminalCommandKey, + GitStatusTerminalCommandKey, formattedCommand, - parentDirectory.Value); + parentDirectory.Value, + ContinueWith: () => CommitChanges(localGitState, localSummary)); var generalTerminal = TerminalStateWrap.Value.TerminalMap[TerminalFacts.GENERAL_TERMINAL_KEY]; await generalTerminal.EnqueueCommandAsync(gitAddCommand); } + + private async Task CommitChanges(GitState localGitState, string localSummary) + { + if (localGitState.GitFolderAbsolutePath?.ParentDirectory is null) + return; + + var parentDirectory = localGitState.GitFolderAbsolutePath.ParentDirectory; + var argumentsString = $"commit -m \"{localSummary}\""; + + var formattedCommand = new FormattedCommand( + GitCliFacts.TARGET_FILE_NAME, + new string[] { argumentsString }) + { + HACK_ArgumentsString = argumentsString + }; + + var gitCommitCommand = new TerminalCommand( + GitCommitTerminalCommandKey, + formattedCommand, + parentDirectory.Value); + + var generalTerminal = TerminalStateWrap.Value.TerminalMap[TerminalFacts.GENERAL_TERMINAL_KEY]; + await generalTerminal.EnqueueCommandAsync(gitCommitCommand); + } } \ No newline at end of file diff --git a/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitDiffDisplay.razor b/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitDiffDisplay.razor new file mode 100644 index 000000000..dc533a597 --- /dev/null +++ b/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitDiffDisplay.razor @@ -0,0 +1,7 @@ +
+ GitDiffDisplay + + +
diff --git a/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitDiffDisplay.razor.cs b/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitDiffDisplay.razor.cs new file mode 100644 index 000000000..b7db18df7 --- /dev/null +++ b/Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitDiffDisplay.razor.cs @@ -0,0 +1,55 @@ +using Fluxor; +using Luthetus.Common.RazorLib.FileSystems.Models; +using Luthetus.Common.RazorLib.Keys.Models; +using Luthetus.Ide.RazorLib.CommandLines.Models; +using Luthetus.Ide.RazorLib.Gits.Models; +using Luthetus.Ide.RazorLib.Gits.States; +using Luthetus.Ide.RazorLib.Terminals.Models; +using Luthetus.Ide.RazorLib.Terminals.States; +using Microsoft.AspNetCore.Components; + +namespace Luthetus.Ide.RazorLib.Gits.Displays; + +public partial class GitDiffDisplay : ComponentBase +{ + [Inject] + private IState TerminalStateWrap { get; set; } = null!; + [Inject] + private IDispatcher Dispatcher { get; set; } = null!; + [Inject] + private IEnvironmentProvider EnvironmentProvider { get; set; } = null!; + [Inject] + private IState GitStateWrap { get; set; } = null!; + + [Parameter, EditorRequired] + public GitFile GitFile { get; set; } = null!; + + public Key GitLogTerminalCommandKey { get; } = Key.NewKey(); + + private async Task ShowOriginalFromGitOnClick() + { + var localGitState = GitStateWrap.Value; + var localGitFile = GitFile; + + if (localGitState.GitFolderAbsolutePath?.ParentDirectory is null) + return; + + var parentDirectory = localGitState.GitFolderAbsolutePath.ParentDirectory; + + var gitLogArgs = $"log -p {localGitFile.RelativePathString}"; + var formattedCommand = new FormattedCommand( + GitCliFacts.TARGET_FILE_NAME, + new string[] { gitLogArgs }) + { + HACK_ArgumentsString = gitLogArgs + }; + + var gitStatusCommand = new TerminalCommand( + GitLogTerminalCommandKey, + formattedCommand, + parentDirectory.Value); + + var generalTerminal = TerminalStateWrap.Value.TerminalMap[TerminalFacts.GENERAL_TERMINAL_KEY]; + await generalTerminal.EnqueueCommandAsync(gitStatusCommand); + } +} \ No newline at end of file diff --git a/Source/Lib/Ide/Ide.RazorLib/Gits/Models/GitTreeViewMouseEventHandler.cs b/Source/Lib/Ide/Ide.RazorLib/Gits/Models/GitTreeViewMouseEventHandler.cs new file mode 100644 index 000000000..95afb1657 --- /dev/null +++ b/Source/Lib/Ide/Ide.RazorLib/Gits/Models/GitTreeViewMouseEventHandler.cs @@ -0,0 +1,55 @@ +using Fluxor; +using Luthetus.Common.RazorLib.BackgroundTasks.Models; +using Luthetus.Common.RazorLib.Commands.Models; +using Luthetus.Common.RazorLib.Dialogs.Models; +using Luthetus.Common.RazorLib.Dialogs.States; +using Luthetus.Common.RazorLib.Dynamics.Models; +using Luthetus.Common.RazorLib.Keys.Models; +using Luthetus.Common.RazorLib.TreeViews.Models; +using Luthetus.Ide.RazorLib.Gits.Displays; +using Luthetus.Ide.RazorLib.Gits.States; +using Luthetus.Ide.RazorLib.TreeViewImplementations.Models; +using System.Reactive; + +namespace Luthetus.Ide.RazorLib.Gits.Models; + +public class GitTreeViewMouseEventHandler : TreeViewMouseEventHandler +{ + private readonly IState _gitStateWrap; + private readonly IDispatcher _dispatcher; + + public GitTreeViewMouseEventHandler( + ITreeViewService treeViewService, + IBackgroundTaskService backgroundTaskService, + IState gitStateWrap, + IDispatcher dispatcher) + : base(treeViewService, backgroundTaskService) + { + _gitStateWrap = gitStateWrap; + _dispatcher = dispatcher; + } + + public override void OnDoubleClick(TreeViewCommandArgs commandArgs) + { + base.OnDoubleClick(commandArgs); + + if (commandArgs.NodeThatReceivedMouseEvent is not TreeViewGitFile treeViewGitFile) + return; + + var dialogViewModel = new DialogViewModel( + Key.NewKey(), + $"Diff: {treeViewGitFile.Item.AbsolutePath.NameWithExtension}", + typeof(GitDiffDisplay), + new Dictionary + { + { + nameof(GitDiffDisplay.GitFile), + treeViewGitFile.Item + } + }, + null, + true); + + _dispatcher.Dispatch(new DialogState.RegisterAction(dialogViewModel)); + } +}