-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
052ee9b
commit a178956
Showing
14 changed files
with
347 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitChangesContextMenu.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@using Luthetus.Common.RazorLib.Menus.Displays | ||
|
||
@{ var localMenuRecord = _menuRecord; } | ||
|
||
@if (localMenuRecord is null) | ||
{ | ||
// TODO: Should something be displayed while the MenuRecord is loading? | ||
} | ||
else | ||
{ | ||
<CascadingValue Name="ReturnFocusToParentFuncAsync" Value="TreeViewCommandArgs.RestoreFocusToTreeView.Invoke"> | ||
<MenuDisplay MenuRecord="localMenuRecord" /> | ||
</CascadingValue> | ||
} |
90 changes: 90 additions & 0 deletions
90
Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitChangesContextMenu.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using Fluxor; | ||
using Microsoft.AspNetCore.Components; | ||
using System.Collections.Immutable; | ||
using Luthetus.Ide.RazorLib.Terminals.States; | ||
using Luthetus.Common.RazorLib.Commands.Models; | ||
using Luthetus.Common.RazorLib.Menus.Models; | ||
using Luthetus.Common.RazorLib.Dropdowns.Models; | ||
using Luthetus.Common.RazorLib.Keys.Models; | ||
using Luthetus.Common.RazorLib.Dimensions.Models; | ||
using Luthetus.Ide.RazorLib.TreeViewImplementations.Models; | ||
using Luthetus.Ide.RazorLib.CommandLines.Models; | ||
using Luthetus.Ide.RazorLib.Terminals.Models; | ||
using Luthetus.Common.RazorLib.BackgroundTasks.Models; | ||
using System.Text; | ||
using Luthetus.Ide.RazorLib.Gits.States; | ||
|
||
namespace Luthetus.Ide.RazorLib.Gits.Displays; | ||
|
||
public partial class GitChangesContextMenu : ComponentBase | ||
{ | ||
[Inject] | ||
private IState<TerminalState> TerminalStateWrap { get; set; } = null!; | ||
[Inject] | ||
private IBackgroundTaskService BackgroundTaskService { get; set; } = null!; | ||
|
||
[CascadingParameter] | ||
public GitState GitState { get; set; } = null!; | ||
|
||
[Parameter, EditorRequired] | ||
public TreeViewCommandArgs TreeViewCommandArgs { get; set; } = null!; | ||
|
||
public static readonly Key<DropdownRecord> ContextMenuEventDropdownKey = Key<DropdownRecord>.NewKey(); | ||
|
||
private MenuRecord? _menuRecord = null; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
// Usage of 'OnInitializedAsync' lifecycle method ensure the context menu is only rendered once. | ||
// Otherwise, one might have the context menu's options change out from under them. | ||
_menuRecord = await GetMenuRecord(TreeViewCommandArgs); | ||
await InvokeAsync(StateHasChanged); | ||
|
||
await base.OnInitializedAsync(); | ||
} | ||
|
||
private async Task<MenuRecord> GetMenuRecord(TreeViewCommandArgs commandArgs, bool isRecursiveCall = false) | ||
{ | ||
if (!isRecursiveCall && commandArgs.TreeViewContainer.SelectedNodeList.Count > 1) | ||
{ | ||
return await GetMultiSelectionMenuRecord(commandArgs); | ||
} | ||
|
||
if (commandArgs.NodeThatReceivedMouseEvent is null) | ||
return MenuRecord.Empty; | ||
|
||
var menuRecordsList = new List<MenuOptionRecord>(); | ||
|
||
if (!menuRecordsList.Any()) | ||
return MenuRecord.Empty; | ||
|
||
return new MenuRecord(menuRecordsList.ToImmutableArray()); | ||
} | ||
|
||
private async Task<MenuRecord> GetMultiSelectionMenuRecord(TreeViewCommandArgs commandArgs) | ||
{ | ||
var menuOptionRecordList = new List<MenuOptionRecord>(); | ||
Func<Task> runAllOnClicksWithinSelection = () => Task.CompletedTask; | ||
bool runAllOnClicksWithinSelectionHasEffect = false; | ||
|
||
if (!menuOptionRecordList.Any()) | ||
return MenuRecord.Empty; | ||
|
||
return new MenuRecord(menuOptionRecordList.ToImmutableArray()); | ||
} | ||
|
||
|
||
public static string GetContextMenuCssStyleString(TreeViewCommandArgs? commandArgs) | ||
{ | ||
if (commandArgs?.ContextMenuFixedPosition is null) | ||
return "display: none;"; | ||
|
||
var left = | ||
$"left: {commandArgs.ContextMenuFixedPosition.LeftPositionInPixels.ToCssValue()}px;"; | ||
|
||
var top = | ||
$"top: {commandArgs.ContextMenuFixedPosition.TopPositionInPixels.ToCssValue()}px;"; | ||
|
||
return $"{left} {top}"; | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitChangesTreeViewDisplay.razor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@using Luthetus.Common.RazorLib.Dropdowns.Displays | ||
@using Luthetus.Common.RazorLib.Dropdowns.Models | ||
@using Luthetus.Common.RazorLib.TreeViews.Displays | ||
@using Luthetus.Common.RazorLib.TreeViews.Models | ||
@using Luthetus.Ide.RazorLib.Terminals.Models | ||
@using System.Collections.Immutable | ||
|
||
<div class="luth_ide_test-explorer-tree-view" | ||
style="height: 100%;"> | ||
|
||
@{ var appOptionsState = AppOptionsStateWrap.Value; } | ||
|
||
<CascadingValue Name="LuthetusTreeViewIconWidth" Value="appOptionsState.Options.IconSizeInPixels"> | ||
<CascadingValue Name="LuthetusTreeViewIconHeight" Value="appOptionsState.Options.IconSizeInPixels"> | ||
<CascadingValue Name="OffsetPerDepthInPixels" Value="OffsetPerDepthInPixels"> | ||
<TreeViewContainerDisplay TreeViewContainerKey="Gits.States.GitState.TreeViewGitChangesKey" | ||
CssStyleString="height: 100%;" | ||
OnContextMenuFunc="OnTreeViewContextMenuFunc" | ||
TreeViewKeyboardEventHandler="_treeViewKeyboardEventHandler" | ||
TreeViewMouseEventHandler="_treeViewMouseEventHandler" /> | ||
</CascadingValue> | ||
</CascadingValue> | ||
</CascadingValue> | ||
|
||
<DropdownDisplay DropdownKey="GitChangesContextMenu.ContextMenuEventDropdownKey" | ||
DropdownPositionKind="DropdownPositionKind.Unset" | ||
CssStyleString="@GitChangesContextMenu.GetContextMenuCssStyleString(_mostRecentTreeViewCommandArgs)"> | ||
|
||
<GitChangesContextMenu TreeViewCommandArgs="_mostRecentTreeViewCommandArgs" /> | ||
</DropdownDisplay> | ||
</div> |
58 changes: 58 additions & 0 deletions
58
Source/Lib/Ide/Ide.RazorLib/Gits/Displays/GitChangesTreeViewDisplay.razor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using Fluxor; | ||
using Luthetus.Common.RazorLib.BackgroundTasks.Models; | ||
using Luthetus.Common.RazorLib.Commands.Models; | ||
using Luthetus.Common.RazorLib.Dropdowns.States; | ||
using Luthetus.Common.RazorLib.Options.States; | ||
using Luthetus.Common.RazorLib.TreeViews.Models; | ||
using Luthetus.Ide.RazorLib.Gits.States; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
namespace Luthetus.Ide.RazorLib.Gits.Displays; | ||
|
||
public partial class GitChangesTreeViewDisplay : ComponentBase | ||
{ | ||
[Inject] | ||
private ITreeViewService TreeViewService { get; set; } = null!; | ||
[Inject] | ||
private IDispatcher Dispatcher { get; set; } = null!; | ||
[Inject] | ||
private IState<AppOptionsState> AppOptionsStateWrap { get; set; } = null!; | ||
[Inject] | ||
private IBackgroundTaskService BackgroundTaskService { get; set; } = null!; | ||
|
||
[CascadingParameter] | ||
public GitState GitState { get; set; } = null!; | ||
|
||
private TreeViewCommandArgs? _mostRecentTreeViewCommandArgs; | ||
private TreeViewKeyboardEventHandler _treeViewKeyboardEventHandler = null!; | ||
private TreeViewMouseEventHandler _treeViewMouseEventHandler = null!; | ||
|
||
private int OffsetPerDepthInPixels => (int)Math.Ceiling( | ||
AppOptionsStateWrap.Value.Options.IconSizeInPixels * (2.0 / 3.0)); | ||
|
||
protected override void OnInitialized() | ||
{ | ||
_treeViewKeyboardEventHandler = new TreeViewKeyboardEventHandler( | ||
TreeViewService, | ||
BackgroundTaskService); | ||
|
||
_treeViewMouseEventHandler = new TreeViewMouseEventHandler( | ||
TreeViewService, | ||
BackgroundTaskService); | ||
|
||
base.OnInitialized(); | ||
} | ||
|
||
private async Task OnTreeViewContextMenuFunc(TreeViewCommandArgs treeViewCommandArgs) | ||
{ | ||
_mostRecentTreeViewCommandArgs = treeViewCommandArgs; | ||
|
||
// The order of 'StateHasChanged(...)' and 'AddActiveDropdownKey(...)' is important. | ||
// The ChildContent renders nothing, unless the provider of the child content | ||
// re-renders now that there is a given '_mostRecentTreeViewContextMenuCommandArgs' | ||
await InvokeAsync(StateHasChanged); | ||
|
||
Dispatcher.Dispatch(new DropdownState.AddActiveAction( | ||
GitChangesContextMenu.ContextMenuEventDropdownKey)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
namespace Luthetus.Ide.RazorLib.Gits.States; | ||
using Luthetus.Common.RazorLib.FileSystems.Models; | ||
using Luthetus.Ide.RazorLib.Gits.Models; | ||
using System.Collections.Immutable; | ||
|
||
namespace Luthetus.Ide.RazorLib.Gits.States; | ||
|
||
public partial record GitState | ||
{ | ||
/// <summary> | ||
/// If the expected path is not the actual path, then the git file list will NOT be changed. | ||
/// </summary> | ||
public record SetGitFileListAction(IAbsolutePath ExpectedGitFolderAbsolutePath, ImmutableList<GitFile> GitFileList); | ||
public record SetGitStateWithAction(Func<GitState, GitState> GitStateWithFunc); | ||
} |
77 changes: 77 additions & 0 deletions
77
Source/Lib/Ide/Ide.RazorLib/Gits/States/GitState.Effector.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
using Fluxor; | ||
using Luthetus.Common.RazorLib.Reactives.Models; | ||
using Luthetus.Common.RazorLib.TreeViews.Models; | ||
using Luthetus.Ide.RazorLib.ComponentRenderers.Models; | ||
using Luthetus.Ide.RazorLib.TreeViewImplementations.Models; | ||
using System.Collections.Immutable; | ||
|
||
namespace Luthetus.Ide.RazorLib.Gits.States; | ||
|
||
public partial record GitState | ||
{ | ||
public class Effector | ||
{ | ||
private readonly IState<GitState> _gitStateWrap; | ||
private readonly ILuthetusIdeComponentRenderers _ideComponentRenderers; | ||
private readonly ITreeViewService _treeViewService; | ||
private readonly IThrottle _throttle = new Throttle(TimeSpan.FromMilliseconds(300)); | ||
|
||
public Effector( | ||
IState<GitState> gitStateWrap, | ||
ILuthetusIdeComponentRenderers ideComponentRenderers, | ||
ITreeViewService treeViewService) | ||
{ | ||
_gitStateWrap = gitStateWrap; | ||
_ideComponentRenderers = ideComponentRenderers; | ||
_treeViewService = treeViewService; | ||
} | ||
|
||
[EffectMethod(typeof(SetGitFileListAction))] | ||
public Task HandleSetGitStateWithAction(IDispatcher dispatcher) | ||
{ | ||
// Suppress unused variable warning | ||
_ = dispatcher; | ||
|
||
_throttle.PushEvent(_ => | ||
{ | ||
var gitState = _gitStateWrap.Value; | ||
|
||
var treeViewList = gitState.GitFileList.Select(x => new TreeViewGitFile( | ||
x, | ||
_ideComponentRenderers, | ||
false, | ||
false)) | ||
.ToArray(); | ||
|
||
var adhocRoot = TreeViewAdhoc.ConstructTreeViewAdhoc(treeViewList); | ||
var firstNode = treeViewList.FirstOrDefault(); | ||
|
||
var activeNodes = firstNode is null | ||
? Array.Empty<TreeViewNoType>() | ||
: new[] { firstNode }; | ||
|
||
if (!_treeViewService.TryGetTreeViewContainer(TreeViewGitChangesKey, out var container)) | ||
{ | ||
_treeViewService.RegisterTreeViewContainer(new TreeViewContainer( | ||
TreeViewGitChangesKey, | ||
adhocRoot, | ||
activeNodes.ToImmutableList())); | ||
} | ||
else | ||
{ | ||
_treeViewService.SetRoot(TreeViewGitChangesKey, adhocRoot); | ||
|
||
_treeViewService.SetActiveNode( | ||
TreeViewGitChangesKey, | ||
firstNode, | ||
true, | ||
false); | ||
} | ||
|
||
return Task.CompletedTask; | ||
}); | ||
|
||
return Task.CompletedTask; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.