✨ Navigation History
This commit is contained in:
@@ -12,9 +12,13 @@ public class IdeNavigationHistoryService
|
|||||||
public bool CanGoBack => _backStack.Count > 0;
|
public bool CanGoBack => _backStack.Count > 0;
|
||||||
public bool CanGoForward => _forwardStack.Count > 0;
|
public bool CanGoForward => _forwardStack.Count > 0;
|
||||||
public IdeNavigationLocation? Current => _current;
|
public IdeNavigationLocation? Current => _current;
|
||||||
|
public bool EnableRecording { get; set; } = false;
|
||||||
|
|
||||||
|
public void StartRecording() => EnableRecording = true;
|
||||||
|
|
||||||
public void RecordNavigation(SharpIdeFile file, SharpIdeFileLinePosition linePosition)
|
public void RecordNavigation(SharpIdeFile file, SharpIdeFileLinePosition linePosition)
|
||||||
{
|
{
|
||||||
|
if (EnableRecording is false) return;
|
||||||
var location = new IdeNavigationLocation(file, linePosition);
|
var location = new IdeNavigationLocation(file, linePosition);
|
||||||
if (location == _current)
|
if (location == _current)
|
||||||
{
|
{
|
||||||
@@ -29,13 +33,6 @@ public class IdeNavigationHistoryService
|
|||||||
_forwardStack.Clear();
|
_forwardStack.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearHistory()
|
|
||||||
{
|
|
||||||
_backStack.Clear();
|
|
||||||
_forwardStack.Clear();
|
|
||||||
_current = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void GoBack()
|
public void GoBack()
|
||||||
{
|
{
|
||||||
if (!CanGoBack) throw new InvalidOperationException("Cannot go back, no history available.");
|
if (!CanGoBack) throw new InvalidOperationException("Cannot go back, no history available.");
|
||||||
@@ -44,7 +41,6 @@ public class IdeNavigationHistoryService
|
|||||||
_forwardStack.Push(_current);
|
_forwardStack.Push(_current);
|
||||||
}
|
}
|
||||||
_current = _backStack.Pop();
|
_current = _backStack.Pop();
|
||||||
// TODO: Fire event
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GoForward()
|
public void GoForward()
|
||||||
@@ -56,10 +52,7 @@ public class IdeNavigationHistoryService
|
|||||||
}
|
}
|
||||||
|
|
||||||
_current = _forwardStack.Pop();
|
_current = _forwardStack.Pop();
|
||||||
// TODO: Fire event
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public record IdeNavigationLocation(SharpIdeFile File, SharpIdeFileLinePosition LinePosition)
|
public record IdeNavigationLocation(SharpIdeFile File, SharpIdeFileLinePosition LinePosition);
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -29,10 +29,14 @@ public partial class ForwardBackwardButtonContainer : HBoxContainer
|
|||||||
private void OnBackwardButtonPressed()
|
private void OnBackwardButtonPressed()
|
||||||
{
|
{
|
||||||
_navigationHistoryService.GoBack();
|
_navigationHistoryService.GoBack();
|
||||||
|
var current = _navigationHistoryService.Current;
|
||||||
|
GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelFireAndForget(current!.File, current.LinePosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnForwardButtonPressed()
|
private void OnForwardButtonPressed()
|
||||||
{
|
{
|
||||||
_navigationHistoryService.GoForward();
|
_navigationHistoryService.GoForward();
|
||||||
|
var current = _navigationHistoryService.Current;
|
||||||
|
GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelFireAndForget(current!.File, current.LinePosition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,7 +170,7 @@ public partial class IdeRoot : Control
|
|||||||
{
|
{
|
||||||
await GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelAsync(file, linePosition);
|
await GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelAsync(file, linePosition);
|
||||||
}
|
}
|
||||||
_navigationHistoryService.ClearHistory();
|
_navigationHistoryService.StartRecording();
|
||||||
// Select the selected tab
|
// Select the selected tab
|
||||||
var selectedFile = filesToOpen.SingleOrDefault(f => f.IsSelected);
|
var selectedFile = filesToOpen.SingleOrDefault(f => f.IsSelected);
|
||||||
if (selectedFile.Item1 is not null) await GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelAsync(selectedFile.Item1, selectedFile.Item2);
|
if (selectedFile.Item1 is not null) await GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelAsync(selectedFile.Item1, selectedFile.Item2);
|
||||||
|
|||||||
Reference in New Issue
Block a user