nav history v2

This commit is contained in:
Matt Parker
2025-10-29 20:40:13 +10:00
parent 45946bce8c
commit c3069b0e41
5 changed files with 33 additions and 3 deletions

View File

@@ -29,6 +29,13 @@ public class IdeNavigationHistoryService
_forwardStack.Clear();
}
public void ClearHistory()
{
_backStack.Clear();
_forwardStack.Clear();
_current = null;
}
public void GoBack()
{
if (!CanGoBack) throw new InvalidOperationException("Cannot go back, no history available.");

View File

@@ -1,4 +1,5 @@
using Godot;
using R3;
using SharpIDE.Application.Features.NavigationHistory;
namespace SharpIDE.Godot.Features.Navigation;
@@ -14,5 +15,24 @@ public partial class ForwardBackwardButtonContainer : HBoxContainer
{
_backwardButton = GetNode<Button>("BackwardButton");
_forwardButton = GetNode<Button>("ForwardButton");
_backwardButton.Pressed += OnBackwardButtonPressed;
_forwardButton.Pressed += OnForwardButtonPressed;
Observable.EveryValueChanged(_navigationHistoryService, navigationHistoryService => navigationHistoryService.Current)
.Where(s => s is not null)
.Subscribe(s =>
{
_backwardButton.Disabled = !_navigationHistoryService.CanGoBack;
_forwardButton.Disabled = !_navigationHistoryService.CanGoForward;
}).AddTo(this);
}
private void OnBackwardButtonPressed()
{
_navigationHistoryService.GoBack();
}
private void OnForwardButtonPressed()
{
_navigationHistoryService.GoForward();
}
}

View File

@@ -5,12 +5,12 @@
[node name="ForwardBackwardButtonContainer" type="HBoxContainer"]
script = ExtResource("1_vep4b")
[node name="ForwardButton" type="Button" parent="."]
[node name="BackwardButton" type="Button" parent="."]
layout_mode = 2
size_flags_vertical = 4
text = " < "
[node name="BackwardButton" type="Button" parent="."]
[node name="ForwardButton" type="Button" parent="."]
layout_mode = 2
size_flags_vertical = 4
text = " > "

View File

@@ -104,7 +104,6 @@ public partial class SolutionExplorerPanel : MarginContainer
_tree.QueueRedraw();
});
}
_navigationHistoryService.RecordNavigation(file, fileLinePosition ?? new SharpIdeFileLinePosition(0, 0));
await task.ConfigureAwait(false);
}

View File

@@ -6,6 +6,7 @@ using SharpIDE.Application.Features.Build;
using SharpIDE.Application.Features.Events;
using SharpIDE.Application.Features.FilePersistence;
using SharpIDE.Application.Features.FileWatching;
using SharpIDE.Application.Features.NavigationHistory;
using SharpIDE.Application.Features.Run;
using SharpIDE.Application.Features.SolutionDiscovery;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
@@ -47,6 +48,7 @@ public partial class IdeRoot : Control
[Inject] private readonly IdeOpenTabsFileManager _openTabsFileManager = null!;
[Inject] private readonly RoslynAnalysis _roslynAnalysis = null!;
[Inject] private readonly SharpIdeSolutionModificationService _sharpIdeSolutionModificationService = null!;
[Inject] private readonly IdeNavigationHistoryService _navigationHistoryService = null!;
[Inject] private readonly ILogger<IdeRoot> _logger = null!;
public override void _EnterTree()
@@ -131,6 +133,7 @@ public partial class IdeRoot : Control
private async Task OnSolutionExplorerPanelOnFileSelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition)
{
await _codeEditorPanel.SetSharpIdeFile(file, fileLinePosition);
_navigationHistoryService.RecordNavigation(file, fileLinePosition ?? new SharpIdeFileLinePosition(0, 0));
}
public void SetSlnFilePath(string path)
@@ -167,6 +170,7 @@ public partial class IdeRoot : Control
{
await GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelAsync(file, linePosition);
}
_navigationHistoryService.ClearHistory();
// Select the selected tab
var selectedFile = filesToOpen.SingleOrDefault(f => f.IsSelected);
if (selectedFile.Item1 is not null) await GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelAsync(selectedFile.Item1, selectedFile.Item2);