diff --git a/src/SharpIDE.Application/Features/Events/GlobalEvents.cs b/src/SharpIDE.Application/Features/Events/GlobalEvents.cs index 8befc23..a27a7dc 100644 --- a/src/SharpIDE.Application/Features/Events/GlobalEvents.cs +++ b/src/SharpIDE.Application/Features/Events/GlobalEvents.cs @@ -14,59 +14,3 @@ public class GlobalEvents public EventWrapper ProjectStoppedRunning { get; private set; } = new(_ => Task.CompletedTask); public EventWrapper DebuggerExecutionStopped { get; private set; } = new(_ => Task.CompletedTask); } - -public static class AsyncEventExtensions -{ - public static void InvokeParallelFireAndForget(this MulticastDelegate @event) => FireAndForget(() => @event.InvokeParallelAsync()); - public static void InvokeParallelFireAndForget(this MulticastDelegate @event, T arg) => FireAndForget(() => @event.InvokeParallelAsync(arg)); - public static void InvokeParallelFireAndForget(this MulticastDelegate @event, T arg, U arg2) => FireAndForget(() => @event.InvokeParallelAsync(arg, arg2)); - - private static async void FireAndForget(Func action) - { - try - { - await action().ConfigureAwait(false); - } - catch (Exception ex) - { - Console.WriteLine($"An exception occurred in an event handler: {ex}"); - } - } - - public static Task InvokeParallelAsync(this MulticastDelegate @event) - { - return InvokeDelegatesAsync(@event.GetInvocationList(), del => ((Func)del)()); - } - - public static Task InvokeParallelAsync(this MulticastDelegate @event, T arg) - { - return InvokeDelegatesAsync(@event.GetInvocationList(), del => ((Func)del)(arg)); - } - public static Task InvokeParallelAsync(this MulticastDelegate @event, T arg, U arg2) - { - return InvokeDelegatesAsync(@event.GetInvocationList(), del => ((Func)del)(arg, arg2)); - } - - private static async Task InvokeDelegatesAsync(IEnumerable invocationList, Func delegateExecutorDelegate) - { - var tasks = invocationList.Select(async del => - { - try - { - await delegateExecutorDelegate(del).ConfigureAwait(false); - return null; - } - catch (Exception ex) - { - return ex; - } - }); - - var results = await Task.WhenAll(tasks).ConfigureAwait(false); - var exceptions = results.Where(r => r is not null).Select(r => r!).ToList(); - if (exceptions.Count != 0) - { - throw new AggregateException(exceptions); - } - } -} diff --git a/src/SharpIDE.Godot/Features/BottomPanel/BottomPanelManager.cs b/src/SharpIDE.Godot/Features/BottomPanel/BottomPanelManager.cs index 09a8eb5..b81d947 100644 --- a/src/SharpIDE.Godot/Features/BottomPanel/BottomPanelManager.cs +++ b/src/SharpIDE.Godot/Features/BottomPanel/BottomPanelManager.cs @@ -42,12 +42,12 @@ public partial class BottomPanelManager : Panel { BottomPanelType.IdeDiagnostics, _ideDiagnosticsPanel } }; - GodotGlobalEvents.Instance.BottomPanelTabSelected += OnBottomPanelTabSelected; + GodotGlobalEvents.Instance.BottomPanelTabSelected.Subscribe(OnBottomPanelTabSelected); } public override void _ExitTree() { - GodotGlobalEvents.Instance.BottomPanelTabSelected -= OnBottomPanelTabSelected; + GodotGlobalEvents.Instance.BottomPanelTabSelected.Subscribe(OnBottomPanelTabSelected); } private async Task OnBottomPanelTabSelected(BottomPanelType? type) @@ -56,11 +56,11 @@ public partial class BottomPanelManager : Panel { if (type == null) { - GodotGlobalEvents.Instance.InvokeBottomPanelVisibilityChangeRequested(false); + GodotGlobalEvents.Instance.BottomPanelVisibilityChangeRequested.InvokeParallelFireAndForget(false); } else { - GodotGlobalEvents.Instance.InvokeBottomPanelVisibilityChangeRequested(true); + GodotGlobalEvents.Instance.BottomPanelVisibilityChangeRequested.InvokeParallelFireAndForget(true); } foreach (var kvp in _panelTypeMap) { diff --git a/src/SharpIDE.Godot/Features/BottomPanel/BottomPanelType.cs b/src/SharpIDE.Godot/Features/BottomPanel/BottomPanelType.cs new file mode 100644 index 0000000..98d8e7d --- /dev/null +++ b/src/SharpIDE.Godot/Features/BottomPanel/BottomPanelType.cs @@ -0,0 +1,10 @@ +namespace SharpIDE.Godot.Features.BottomPanel; + +public enum BottomPanelType +{ + Run, + Debug, + Build, + Problems, + IdeDiagnostics +} \ No newline at end of file diff --git a/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs b/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs index 2e8ab3b..4bc0850 100644 --- a/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs +++ b/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs @@ -39,7 +39,7 @@ public partial class CodeEditorPanel : MarginContainer private void OnTabClicked(long tab) { var sharpIdeFile = _tabContainer.GetChild((int)tab).SharpIdeFile; - GodotGlobalEvents.Instance.InvokeFileExternallySelected(sharpIdeFile); + GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelFireAndForget(sharpIdeFile, null); } private void OnTabClosePressed(long tabIndex) @@ -87,7 +87,7 @@ public partial class CodeEditorPanel : MarginContainer if (executionStopInfo.FilePath != currentSharpIdeFile?.Path) { var file = Solution.AllFiles.Single(s => s.Path == executionStopInfo.FilePath); - await GodotGlobalEvents.Instance.InvokeFileExternallySelectedAndWait(file).ConfigureAwait(false); + await GodotGlobalEvents.Instance.FileExternallySelected.InvokeParallelAsync(file, null).ConfigureAwait(false); } var lineInt = executionStopInfo.Line - 1; // Debugging is 1-indexed, Godot is 0-indexed Guard.Against.Negative(lineInt, nameof(lineInt)); diff --git a/src/SharpIDE.Godot/Features/LeftSideBar/LeftSideBar.cs b/src/SharpIDE.Godot/Features/LeftSideBar/LeftSideBar.cs index 4034527..1d4dba7 100644 --- a/src/SharpIDE.Godot/Features/LeftSideBar/LeftSideBar.cs +++ b/src/SharpIDE.Godot/Features/LeftSideBar/LeftSideBar.cs @@ -1,4 +1,5 @@ using Godot; +using SharpIDE.Godot.Features.BottomPanel; namespace SharpIDE.Godot.Features.LeftSideBar; @@ -21,12 +22,12 @@ public partial class LeftSideBar : Panel _debugButton = GetNode