diff --git a/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs b/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs new file mode 100644 index 0000000..5f08817 --- /dev/null +++ b/src/SharpIDE.Application/Features/NavigationHistory/IdeNavigationHistoryService.cs @@ -0,0 +1,58 @@ +using SharpIDE.Application.Features.Analysis; +using SharpIDE.Application.Features.SolutionDiscovery; + +namespace SharpIDE.Application.Features.NavigationHistory; + +public class IdeNavigationHistoryService +{ + private readonly Stack _backStack = new(); + private IdeNavigationLocation? _current; + private readonly Stack _forwardStack = new(); + + public bool CanGoBack => _backStack.Count > 0; + public bool CanGoForward => _forwardStack.Count > 0; + public IdeNavigationLocation? Current => _current; + + public void RecordNavigation(SharpIdeFile file, SharpIdeFileLinePosition linePosition) + { + var location = new IdeNavigationLocation(file, linePosition); + if (location == _current) + { + // perhaps we filter out our forward and back navigations like this? + return; + } + if (_current is not null) + { + _backStack.Push(_current); + } + _current = location; + _forwardStack.Clear(); + } + + public void GoBack() + { + if (!CanGoBack) throw new InvalidOperationException("Cannot go back, no history available."); + if (_current is not null) + { + _forwardStack.Push(_current); + } + _current = _backStack.Pop(); + // TODO: Fire event + } + + public void GoForward() + { + if (!CanGoForward) throw new InvalidOperationException("Cannot go forward, no history available."); + if (_current is not null) + { + _backStack.Push(_current); + } + + _current = _forwardStack.Pop(); + // TODO: Fire event + } +} + +public record IdeNavigationLocation(SharpIdeFile File, SharpIdeFileLinePosition LinePosition) +{ +} diff --git a/src/SharpIDE.Godot/DiAutoload.cs b/src/SharpIDE.Godot/DiAutoload.cs index 1b12286..31d005c 100644 --- a/src/SharpIDE.Godot/DiAutoload.cs +++ b/src/SharpIDE.Godot/DiAutoload.cs @@ -8,6 +8,7 @@ using SharpIDE.Application.Features.Build; using SharpIDE.Application.Features.Evaluation; using SharpIDE.Application.Features.FilePersistence; using SharpIDE.Application.Features.FileWatching; +using SharpIDE.Application.Features.NavigationHistory; using SharpIDE.Application.Features.Run; using SharpIDE.Application.Features.Search; @@ -36,6 +37,7 @@ public partial class DiAutoload : Node services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/SharpIDE.Godot/Features/Navigation/ForwardBackwardButtonContainer.cs b/src/SharpIDE.Godot/Features/Navigation/ForwardBackwardButtonContainer.cs new file mode 100644 index 0000000..c8eff57 --- /dev/null +++ b/src/SharpIDE.Godot/Features/Navigation/ForwardBackwardButtonContainer.cs @@ -0,0 +1,18 @@ +using Godot; +using SharpIDE.Application.Features.NavigationHistory; + +namespace SharpIDE.Godot.Features.Navigation; + +public partial class ForwardBackwardButtonContainer : HBoxContainer +{ + private Button _backwardButton = null!; + private Button _forwardButton = null!; + + [Inject] private readonly IdeNavigationHistoryService _navigationHistoryService = null!; + + public override void _Ready() + { + _backwardButton = GetNode