Move Godot events to instance
This commit is contained in:
@@ -42,12 +42,12 @@ public partial class BottomPanelManager : Panel
|
|||||||
{ BottomPanelType.IdeDiagnostics, _ideDiagnosticsPanel }
|
{ BottomPanelType.IdeDiagnostics, _ideDiagnosticsPanel }
|
||||||
};
|
};
|
||||||
|
|
||||||
GodotGlobalEvents.BottomPanelTabSelected += OnBottomPanelTabSelected;
|
GodotGlobalEvents.Instance.BottomPanelTabSelected += OnBottomPanelTabSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void _ExitTree()
|
public override void _ExitTree()
|
||||||
{
|
{
|
||||||
GodotGlobalEvents.BottomPanelTabSelected -= OnBottomPanelTabSelected;
|
GodotGlobalEvents.Instance.BottomPanelTabSelected -= OnBottomPanelTabSelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnBottomPanelTabSelected(BottomPanelType? type)
|
private async Task OnBottomPanelTabSelected(BottomPanelType? type)
|
||||||
@@ -56,11 +56,11 @@ public partial class BottomPanelManager : Panel
|
|||||||
{
|
{
|
||||||
if (type == null)
|
if (type == null)
|
||||||
{
|
{
|
||||||
GodotGlobalEvents.InvokeBottomPanelVisibilityChangeRequested(false);
|
GodotGlobalEvents.Instance.InvokeBottomPanelVisibilityChangeRequested(false);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
GodotGlobalEvents.InvokeBottomPanelVisibilityChangeRequested(true);
|
GodotGlobalEvents.Instance.InvokeBottomPanelVisibilityChangeRequested(true);
|
||||||
}
|
}
|
||||||
foreach (var kvp in _panelTypeMap)
|
foreach (var kvp in _panelTypeMap)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public partial class CodeEditorPanel : MarginContainer
|
|||||||
private void OnTabClicked(long tab)
|
private void OnTabClicked(long tab)
|
||||||
{
|
{
|
||||||
var sharpIdeFile = _tabContainer.GetChild<SharpIdeCodeEdit>((int)tab).SharpIdeFile;
|
var sharpIdeFile = _tabContainer.GetChild<SharpIdeCodeEdit>((int)tab).SharpIdeFile;
|
||||||
GodotGlobalEvents.InvokeFileExternallySelected(sharpIdeFile);
|
GodotGlobalEvents.Instance.InvokeFileExternallySelected(sharpIdeFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnTabClosePressed(long tabIndex)
|
private void OnTabClosePressed(long tabIndex)
|
||||||
@@ -87,7 +87,7 @@ public partial class CodeEditorPanel : MarginContainer
|
|||||||
if (executionStopInfo.FilePath != currentSharpIdeFile?.Path)
|
if (executionStopInfo.FilePath != currentSharpIdeFile?.Path)
|
||||||
{
|
{
|
||||||
var file = Solution.AllFiles.Single(s => s.Path == executionStopInfo.FilePath);
|
var file = Solution.AllFiles.Single(s => s.Path == executionStopInfo.FilePath);
|
||||||
await GodotGlobalEvents.InvokeFileExternallySelectedAndWait(file).ConfigureAwait(false);
|
await GodotGlobalEvents.Instance.InvokeFileExternallySelectedAndWait(file).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
var lineInt = executionStopInfo.Line - 1; // Debugging is 1-indexed, Godot is 0-indexed
|
var lineInt = executionStopInfo.Line - 1; // Debugging is 1-indexed, Godot is 0-indexed
|
||||||
Guard.Against.Negative(lineInt, nameof(lineInt));
|
Guard.Against.Negative(lineInt, nameof(lineInt));
|
||||||
|
|||||||
@@ -21,12 +21,12 @@ public partial class LeftSideBar : Panel
|
|||||||
_debugButton = GetNode<Button>("%DebugButton");
|
_debugButton = GetNode<Button>("%DebugButton");
|
||||||
_ideDiagnosticsButton = GetNode<Button>("%IdeDiagnosticsButton");
|
_ideDiagnosticsButton = GetNode<Button>("%IdeDiagnosticsButton");
|
||||||
|
|
||||||
_problemsButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Problems : null);
|
_problemsButton.Toggled += toggledOn => GodotGlobalEvents.Instance.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Problems : null);
|
||||||
_runButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Run : null);
|
_runButton.Toggled += toggledOn => GodotGlobalEvents.Instance.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Run : null);
|
||||||
_buildButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Build : null);
|
_buildButton.Toggled += toggledOn => GodotGlobalEvents.Instance.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Build : null);
|
||||||
_debugButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Debug : null);
|
_debugButton.Toggled += toggledOn => GodotGlobalEvents.Instance.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Debug : null);
|
||||||
_ideDiagnosticsButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.IdeDiagnostics : null);
|
_ideDiagnosticsButton.Toggled += toggledOn => GodotGlobalEvents.Instance.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.IdeDiagnostics : null);
|
||||||
GodotGlobalEvents.BottomPanelTabExternallySelected += OnBottomPanelTabExternallySelected;
|
GodotGlobalEvents.Instance.BottomPanelTabExternallySelected += OnBottomPanelTabExternallySelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnBottomPanelTabExternallySelected(BottomPanelType arg)
|
private async Task OnBottomPanelTabExternallySelected(BottomPanelType arg)
|
||||||
|
|||||||
@@ -124,6 +124,6 @@ public partial class ProblemsPanel : Control
|
|||||||
var file = projectModel.Files
|
var file = projectModel.Files
|
||||||
.Concat(projectModel.Folders.SelectMany(f => f.GetAllFiles()))
|
.Concat(projectModel.Folders.SelectMany(f => f.GetAllFiles()))
|
||||||
.Single(s => s.Path == diagnostic.Location.SourceTree?.GetMappedLineSpan(diagnostic.Location.SourceSpan).Path);
|
.Single(s => s.Path == diagnostic.Location.SourceTree?.GetMappedLineSpan(diagnostic.Location.SourceSpan).Path);
|
||||||
GodotGlobalEvents.InvokeFileExternallySelected(file);
|
GodotGlobalEvents.Instance.InvokeFileExternallySelected(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -51,13 +51,13 @@ public partial class RunMenuItem : HBoxContainer
|
|||||||
|
|
||||||
private async void OnRunButtonPressed()
|
private async void OnRunButtonPressed()
|
||||||
{
|
{
|
||||||
GodotGlobalEvents.InvokeBottomPanelTabExternallySelected(BottomPanelType.Run);
|
GodotGlobalEvents.Instance.InvokeBottomPanelTabExternallySelected(BottomPanelType.Run);
|
||||||
await Singletons.RunService.RunProject(Project).ConfigureAwait(false);
|
await Singletons.RunService.RunProject(Project).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async void OnDebugButtonPressed()
|
private async void OnDebugButtonPressed()
|
||||||
{
|
{
|
||||||
GodotGlobalEvents.InvokeBottomPanelTabExternallySelected(BottomPanelType.Debug);
|
GodotGlobalEvents.Instance.InvokeBottomPanelTabExternallySelected(BottomPanelType.Debug);
|
||||||
await Singletons.RunService.RunProject(Project, true).ConfigureAwait(false);
|
await Singletons.RunService.RunProject(Project, true).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,7 +27,7 @@ public partial class SearchResultComponent : MarginContainer
|
|||||||
private void OnButtonPressed()
|
private void OnButtonPressed()
|
||||||
{
|
{
|
||||||
var fileLinePosition = new SharpIdeFileLinePosition { Line = Result.Line, Column = Result.StartColumn };
|
var fileLinePosition = new SharpIdeFileLinePosition { Line = Result.Line, Column = Result.StartColumn };
|
||||||
GodotGlobalEvents.InvokeFileExternallySelected(Result.File, fileLinePosition);
|
GodotGlobalEvents.Instance.InvokeFileExternallySelected(Result.File, fileLinePosition);
|
||||||
ParentSearchWindow.Hide();
|
ParentSearchWindow.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public partial class SolutionExplorerPanel : MarginContainer
|
|||||||
{
|
{
|
||||||
_tree = GetNode<Tree>("Tree");
|
_tree = GetNode<Tree>("Tree");
|
||||||
_tree.ItemMouseSelected += TreeOnItemMouseSelected;
|
_tree.ItemMouseSelected += TreeOnItemMouseSelected;
|
||||||
GodotGlobalEvents.FileExternallySelected += OnFileExternallySelected;
|
GodotGlobalEvents.Instance.FileExternallySelected += OnFileExternallySelected;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void TreeOnItemMouseSelected(Vector2 mousePosition, long mouseButtonIndex)
|
private void TreeOnItemMouseSelected(Vector2 mousePosition, long mouseButtonIndex)
|
||||||
@@ -36,13 +36,13 @@ public partial class SolutionExplorerPanel : MarginContainer
|
|||||||
if (sharpIdeFileContainer is null) return;
|
if (sharpIdeFileContainer is null) return;
|
||||||
var sharpIdeFile = sharpIdeFileContainer.File;
|
var sharpIdeFile = sharpIdeFileContainer.File;
|
||||||
Guard.Against.Null(sharpIdeFile, nameof(sharpIdeFile));
|
Guard.Against.Null(sharpIdeFile, nameof(sharpIdeFile));
|
||||||
GodotGlobalEvents.InvokeFileSelected(sharpIdeFile);
|
GodotGlobalEvents.Instance.InvokeFileSelected(sharpIdeFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnFileExternallySelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition)
|
private async Task OnFileExternallySelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition)
|
||||||
{
|
{
|
||||||
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding);
|
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding);
|
||||||
var task = GodotGlobalEvents.InvokeFileSelectedAndWait(file, fileLinePosition);
|
var task = GodotGlobalEvents.Instance.InvokeFileSelectedAndWait(file, fileLinePosition);
|
||||||
var item = FindItemRecursive(_tree.GetRoot(), file);
|
var item = FindItemRecursive(_tree.GetRoot(), file);
|
||||||
if (item is not null)
|
if (item is not null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,23 +4,24 @@ using SharpIDE.Application.Features.SolutionDiscovery;
|
|||||||
|
|
||||||
namespace SharpIDE.Godot;
|
namespace SharpIDE.Godot;
|
||||||
|
|
||||||
public static class GodotGlobalEvents
|
public class GodotGlobalEvents
|
||||||
{
|
{
|
||||||
public static event Func<BottomPanelType, Task> BottomPanelTabExternallySelected = _ => Task.CompletedTask;
|
public static GodotGlobalEvents Instance { get; set; } = null!;
|
||||||
public static void InvokeBottomPanelTabExternallySelected(BottomPanelType type) => BottomPanelTabExternallySelected.InvokeParallelFireAndForget(type);
|
public event Func<BottomPanelType, Task> BottomPanelTabExternallySelected = _ => Task.CompletedTask;
|
||||||
|
public void InvokeBottomPanelTabExternallySelected(BottomPanelType type) => BottomPanelTabExternallySelected.InvokeParallelFireAndForget(type);
|
||||||
|
|
||||||
public static event Func<BottomPanelType?, Task> BottomPanelTabSelected = _ => Task.CompletedTask;
|
public event Func<BottomPanelType?, Task> BottomPanelTabSelected = _ => Task.CompletedTask;
|
||||||
public static void InvokeBottomPanelTabSelected(BottomPanelType? type) => BottomPanelTabSelected.InvokeParallelFireAndForget(type);
|
public void InvokeBottomPanelTabSelected(BottomPanelType? type) => BottomPanelTabSelected.InvokeParallelFireAndForget(type);
|
||||||
|
|
||||||
public static event Func<bool, Task> BottomPanelVisibilityChangeRequested = _ => Task.CompletedTask;
|
public event Func<bool, Task> BottomPanelVisibilityChangeRequested = _ => Task.CompletedTask;
|
||||||
public static void InvokeBottomPanelVisibilityChangeRequested(bool show) => BottomPanelVisibilityChangeRequested.InvokeParallelFireAndForget(show);
|
public void InvokeBottomPanelVisibilityChangeRequested(bool show) => BottomPanelVisibilityChangeRequested.InvokeParallelFireAndForget(show);
|
||||||
|
|
||||||
public static event Func<SharpIdeFile, SharpIdeFileLinePosition?, Task> FileSelected = (_, _) => Task.CompletedTask;
|
public event Func<SharpIdeFile, SharpIdeFileLinePosition?, Task> FileSelected = (_, _) => Task.CompletedTask;
|
||||||
public static void InvokeFileSelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition = null) => FileSelected.InvokeParallelFireAndForget(file, fileLinePosition);
|
public void InvokeFileSelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition = null) => FileSelected.InvokeParallelFireAndForget(file, fileLinePosition);
|
||||||
public static async Task InvokeFileSelectedAndWait(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition) => await FileSelected.InvokeParallelAsync(file, fileLinePosition);
|
public async Task InvokeFileSelectedAndWait(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition) => await FileSelected.InvokeParallelAsync(file, fileLinePosition);
|
||||||
public static event Func<SharpIdeFile, SharpIdeFileLinePosition?, Task> FileExternallySelected = (_, _) => Task.CompletedTask;
|
public event Func<SharpIdeFile, SharpIdeFileLinePosition?, Task> FileExternallySelected = (_, _) => Task.CompletedTask;
|
||||||
public static void InvokeFileExternallySelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition = null) => FileExternallySelected.InvokeParallelFireAndForget(file, fileLinePosition);
|
public void InvokeFileExternallySelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition = null) => FileExternallySelected.InvokeParallelFireAndForget(file, fileLinePosition);
|
||||||
public static async Task InvokeFileExternallySelectedAndWait(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition = null) => await FileExternallySelected.InvokeParallelAsync(file, fileLinePosition);
|
public async Task InvokeFileExternallySelectedAndWait(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition = null) => await FileExternallySelected.InvokeParallelAsync(file, fileLinePosition);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,6 +30,12 @@ public partial class IdeRoot : Control
|
|||||||
|
|
||||||
private readonly PackedScene _runMenuItemScene = ResourceLoader.Load<PackedScene>("res://Features/Run/RunMenuItem.tscn");
|
private readonly PackedScene _runMenuItemScene = ResourceLoader.Load<PackedScene>("res://Features/Run/RunMenuItem.tscn");
|
||||||
private TaskCompletionSource _nodeReadyTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
private TaskCompletionSource _nodeReadyTcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
|
|
||||||
|
public override void _EnterTree()
|
||||||
|
{
|
||||||
|
GodotGlobalEvents.Instance = new GodotGlobalEvents();
|
||||||
|
}
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
_openSlnButton = GetNode<Button>("%OpenSlnButton");
|
_openSlnButton = GetNode<Button>("%OpenSlnButton");
|
||||||
@@ -45,11 +51,11 @@ public partial class IdeRoot : Control
|
|||||||
_bottomPanelManager = GetNode<BottomPanelManager>("%BottomPanel");
|
_bottomPanelManager = GetNode<BottomPanelManager>("%BottomPanel");
|
||||||
|
|
||||||
_runMenuButton.Pressed += OnRunMenuButtonPressed;
|
_runMenuButton.Pressed += OnRunMenuButtonPressed;
|
||||||
GodotGlobalEvents.FileSelected += OnSolutionExplorerPanelOnFileSelected;
|
GodotGlobalEvents.Instance.FileSelected += OnSolutionExplorerPanelOnFileSelected;
|
||||||
_fileDialog.FileSelected += SetSlnFilePath;
|
_fileDialog.FileSelected += SetSlnFilePath;
|
||||||
_openSlnButton.Pressed += () => IdeWindow.PickSolution();
|
_openSlnButton.Pressed += () => IdeWindow.PickSolution();
|
||||||
_buildSlnButton.Pressed += OnBuildSlnButtonPressed;
|
_buildSlnButton.Pressed += OnBuildSlnButtonPressed;
|
||||||
GodotGlobalEvents.BottomPanelVisibilityChangeRequested += async show => await this.InvokeAsync(() => _invertedVSplitContainer.InvertedSetCollapsed(!show));
|
GodotGlobalEvents.Instance.BottomPanelVisibilityChangeRequested += async show => await this.InvokeAsync(() => _invertedVSplitContainer.InvertedSetCollapsed(!show));
|
||||||
_nodeReadyTcs.SetResult();
|
_nodeReadyTcs.SetResult();
|
||||||
//OnSlnFileSelected(@"C:\Users\Matthew\Documents\Git\BlazorCodeBreaker\BlazorCodeBreaker.slnx");
|
//OnSlnFileSelected(@"C:\Users\Matthew\Documents\Git\BlazorCodeBreaker\BlazorCodeBreaker.slnx");
|
||||||
}
|
}
|
||||||
@@ -64,7 +70,7 @@ public partial class IdeRoot : Control
|
|||||||
|
|
||||||
private async void OnBuildSlnButtonPressed()
|
private async void OnBuildSlnButtonPressed()
|
||||||
{
|
{
|
||||||
GodotGlobalEvents.InvokeBottomPanelTabExternallySelected(BottomPanelType.Build);
|
GodotGlobalEvents.Instance.InvokeBottomPanelTabExternallySelected(BottomPanelType.Build);
|
||||||
await Singletons.BuildService.MsBuildSolutionAsync(_solutionExplorerPanel.SolutionModel.FilePath);
|
await Singletons.BuildService.MsBuildSolutionAsync(_solutionExplorerPanel.SolutionModel.FilePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -89,7 +95,7 @@ public partial class IdeRoot : Control
|
|||||||
|
|
||||||
var infraProject = solutionModel.AllProjects.SingleOrDefault(s => s.Name == "WebUi");
|
var infraProject = solutionModel.AllProjects.SingleOrDefault(s => s.Name == "WebUi");
|
||||||
var diFile = infraProject?.Folders.Single(s => s.Name == "Pages").Files.Single(s => s.Name == "TestPage.razor");
|
var diFile = infraProject?.Folders.Single(s => s.Name == "Pages").Files.Single(s => s.Name == "TestPage.razor");
|
||||||
if (diFile != null) await this.InvokeDeferredAsync(() => GodotGlobalEvents.InvokeFileExternallySelected(diFile));
|
if (diFile != null) await this.InvokeDeferredAsync(() => GodotGlobalEvents.Instance.InvokeFileExternallySelected(diFile));
|
||||||
|
|
||||||
var tasks = solutionModel.AllProjects.Select(p => p.MsBuildEvaluationProjectTask).ToList();
|
var tasks = solutionModel.AllProjects.Select(p => p.MsBuildEvaluationProjectTask).ToList();
|
||||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user