Skip to content

Commit

Permalink
Git commit
Browse files Browse the repository at this point in the history
  • Loading branch information
huntercfreeman committed May 3, 2024
1 parent 104f72c commit e8c8b77
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -46,9 +46,11 @@ protected override void OnInitialized()
GitStateWrap,
Dispatcher);

_treeViewMouseEventHandler = new TreeViewMouseEventHandler(
_treeViewMouseEventHandler = new GitTreeViewMouseEventHandler(
TreeViewService,
BackgroundTaskService);
BackgroundTaskService,
GitStateWrap,
Dispatcher);

base.OnInitialized();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -25,7 +24,8 @@ public partial class GitControlsDisplay : ComponentBase

private string _summary = string.Empty;

public Key<TerminalCommand> NewDotNetSolutionTerminalCommandKey { get; } = Key<TerminalCommand>.NewKey();
public Key<TerminalCommand> GitStatusTerminalCommandKey { get; } = Key<TerminalCommand>.NewKey();
public Key<TerminalCommand> GitCommitTerminalCommandKey { get; } = Key<TerminalCommand>.NewKey();

private async Task ExecuteGitStatusTerminalCommandOnClick()
{
Expand All @@ -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];
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div class="luth_ide_git-diff">
GitDiffDisplay

<button class="luth_button" @onclick="ShowOriginalFromGitOnClick">
ShowOriginalFromGitOnClick
</button>
</div>
55 changes: 55 additions & 0 deletions Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitDiffDisplay.razor.cs
Original file line number Diff line number Diff line change
@@ -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<TerminalState> TerminalStateWrap { get; set; } = null!;
[Inject]
private IDispatcher Dispatcher { get; set; } = null!;
[Inject]
private IEnvironmentProvider EnvironmentProvider { get; set; } = null!;
[Inject]
private IState<GitState> GitStateWrap { get; set; } = null!;

[Parameter, EditorRequired]
public GitFile GitFile { get; set; } = null!;

public Key<TerminalCommand> GitLogTerminalCommandKey { get; } = Key<TerminalCommand>.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);
}
}
Original file line number Diff line number Diff line change
@@ -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<GitState> _gitStateWrap;
private readonly IDispatcher _dispatcher;

public GitTreeViewMouseEventHandler(
ITreeViewService treeViewService,
IBackgroundTaskService backgroundTaskService,
IState<GitState> 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<IDynamicViewModel>.NewKey(),
$"Diff: {treeViewGitFile.Item.AbsolutePath.NameWithExtension}",
typeof(GitDiffDisplay),
new Dictionary<string, object?>
{
{
nameof(GitDiffDisplay.GitFile),
treeViewGitFile.Item
}
},
null,
true);

_dispatcher.Dispatch(new DialogState.RegisterAction(dialogViewModel));
}
}

0 comments on commit e8c8b77

Please sign in to comment.