diff --git a/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs b/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs index 69a75c6..c04390e 100644 --- a/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs +++ b/src/SharpIDE.Application/Features/Debugging/DebuggingService.cs @@ -76,7 +76,7 @@ public class DebuggingService var filePath = dict?["source"]?["path"]!.Value()!; var line = (dict?["line"]?.Value()!).Value; var executionStopInfo = new ExecutionStopInfo { FilePath = filePath, Line = line, ThreadId = @event.ThreadId!.Value }; - GlobalEvents.InvokeDebuggerExecutionStopped(executionStopInfo); + GlobalEvents.Instance.InvokeDebuggerExecutionStopped(executionStopInfo); if (@event.Reason is StoppedEvent.ReasonValue.Exception) { Console.WriteLine("Stopped due to exception, continuing"); diff --git a/src/SharpIDE.Application/Features/Events/GlobalEvents.cs b/src/SharpIDE.Application/Features/Events/GlobalEvents.cs index 40842f9..9dd687b 100644 --- a/src/SharpIDE.Application/Features/Events/GlobalEvents.cs +++ b/src/SharpIDE.Application/Features/Events/GlobalEvents.cs @@ -3,28 +3,29 @@ using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; namespace SharpIDE.Application.Features.Events; -public static class GlobalEvents +public class GlobalEvents { - public static event Func ProjectsRunningChanged = () => Task.CompletedTask; - public static void InvokeProjectsRunningChanged() => ProjectsRunningChanged?.InvokeParallelFireAndForget(); + public static GlobalEvents Instance { get; set; } = null!; + public event Func ProjectsRunningChanged = () => Task.CompletedTask; + public void InvokeProjectsRunningChanged() => ProjectsRunningChanged?.InvokeParallelFireAndForget(); - public static event Func StartedRunningProject = () => Task.CompletedTask; - public static void InvokeStartedRunningProject() => StartedRunningProject?.InvokeParallelFireAndForget(); + public event Func StartedRunningProject = () => Task.CompletedTask; + public void InvokeStartedRunningProject() => StartedRunningProject?.InvokeParallelFireAndForget(); - public static event Func ProjectStartedDebugging = _ => Task.CompletedTask; - public static void InvokeProjectStartedDebugging(SharpIdeProjectModel project) => ProjectStartedDebugging?.InvokeParallelFireAndForget(project); + public event Func ProjectStartedDebugging = _ => Task.CompletedTask; + public void InvokeProjectStartedDebugging(SharpIdeProjectModel project) => ProjectStartedDebugging?.InvokeParallelFireAndForget(project); - public static event Func ProjectStoppedDebugging = _ => Task.CompletedTask; - public static void InvokeProjectStoppedDebugging(SharpIdeProjectModel project) => ProjectStoppedDebugging?.InvokeParallelFireAndForget(project); + public event Func ProjectStoppedDebugging = _ => Task.CompletedTask; + public void InvokeProjectStoppedDebugging(SharpIdeProjectModel project) => ProjectStoppedDebugging?.InvokeParallelFireAndForget(project); - public static event Func ProjectStartedRunning = _ => Task.CompletedTask; - public static void InvokeProjectStartedRunning(SharpIdeProjectModel project) => ProjectStartedRunning?.InvokeParallelFireAndForget(project); + public event Func ProjectStartedRunning = _ => Task.CompletedTask; + public void InvokeProjectStartedRunning(SharpIdeProjectModel project) => ProjectStartedRunning?.InvokeParallelFireAndForget(project); - public static event Func ProjectStoppedRunning = _ => Task.CompletedTask; - public static void InvokeProjectStoppedRunning(SharpIdeProjectModel project) => ProjectStoppedRunning?.InvokeParallelFireAndForget(project); + public event Func ProjectStoppedRunning = _ => Task.CompletedTask; + public void InvokeProjectStoppedRunning(SharpIdeProjectModel project) => ProjectStoppedRunning?.InvokeParallelFireAndForget(project); - public static event Func DebuggerExecutionStopped = _ => Task.CompletedTask; - public static void InvokeDebuggerExecutionStopped(ExecutionStopInfo executionStopInfo) => DebuggerExecutionStopped?.InvokeParallelFireAndForget(executionStopInfo); + public event Func DebuggerExecutionStopped = _ => Task.CompletedTask; + public void InvokeDebuggerExecutionStopped(ExecutionStopInfo executionStopInfo) => DebuggerExecutionStopped?.InvokeParallelFireAndForget(executionStopInfo); } public static class AsyncEventExtensions diff --git a/src/SharpIDE.Application/Features/Run/RunService.cs b/src/SharpIDE.Application/Features/Run/RunService.cs index ec277d8..5bd2b55 100644 --- a/src/SharpIDE.Application/Features/Run/RunService.cs +++ b/src/SharpIDE.Application/Features/Run/RunService.cs @@ -93,13 +93,13 @@ public class RunService project.OpenInRunPanel = true; if (isDebug) { - GlobalEvents.InvokeProjectStartedDebugging(project); + GlobalEvents.Instance.InvokeProjectStartedDebugging(project); } else { - GlobalEvents.InvokeProjectsRunningChanged(); - GlobalEvents.InvokeStartedRunningProject(); - GlobalEvents.InvokeProjectStartedRunning(project); + GlobalEvents.Instance.InvokeProjectsRunningChanged(); + GlobalEvents.Instance.InvokeStartedRunningProject(); + GlobalEvents.Instance.InvokeProjectStartedRunning(project); } project.InvokeProjectStartedRunning(); await process.WaitForExitAsync().WaitAsync(project.RunningCancellationTokenSource.Token).ConfigureAwait(ConfigureAwaitOptions.SuppressThrowing); @@ -115,12 +115,12 @@ public class RunService project.Running = false; if (isDebug) { - GlobalEvents.InvokeProjectStoppedDebugging(project); + GlobalEvents.Instance.InvokeProjectStoppedDebugging(project); } else { - GlobalEvents.InvokeProjectsRunningChanged(); - GlobalEvents.InvokeProjectStoppedRunning(project); + GlobalEvents.Instance.InvokeProjectsRunningChanged(); + GlobalEvents.Instance.InvokeProjectStoppedRunning(project); } project.InvokeProjectStoppedRunning(); diff --git a/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs b/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs index 08a40b1..ab345c6 100644 --- a/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs +++ b/src/SharpIDE.Godot/Features/CodeEditor/CodeEditorPanel.cs @@ -25,7 +25,7 @@ public partial class CodeEditorPanel : MarginContainer var tabBar = _tabContainer.GetTabBar(); tabBar.TabCloseDisplayPolicy = TabBar.CloseButtonDisplayPolicy.ShowAlways; tabBar.TabClosePressed += OnTabClosePressed; - GlobalEvents.DebuggerExecutionStopped += OnDebuggerExecutionStopped; + GlobalEvents.Instance.DebuggerExecutionStopped += OnDebuggerExecutionStopped; } public override void _UnhandledKeyInput(InputEvent @event) diff --git a/src/SharpIDE.Godot/Features/Debug_/DebugPanel.cs b/src/SharpIDE.Godot/Features/Debug_/DebugPanel.cs index c0620fe..e55902f 100644 --- a/src/SharpIDE.Godot/Features/Debug_/DebugPanel.cs +++ b/src/SharpIDE.Godot/Features/Debug_/DebugPanel.cs @@ -22,11 +22,11 @@ public partial class DebugPanel : Control //_tabBar.TabClosePressed _tabBar.TabClicked += OnTabBarTabClicked; _tabsPanel = GetNode("%TabsPanel"); - GlobalEvents.ProjectStartedDebugging += async projectModel => + GlobalEvents.Instance.ProjectStartedDebugging += async projectModel => { await this.InvokeAsync(() => ProjectStartedDebugging(projectModel)); }; - GlobalEvents.ProjectStoppedDebugging += async projectModel => + GlobalEvents.Instance.ProjectStoppedDebugging += async projectModel => { await this.InvokeAsync(() => ProjectStoppedDebugging(projectModel)); }; diff --git a/src/SharpIDE.Godot/Features/Debug_/Tab/SubTabs/ThreadsVariablesSubTab.cs b/src/SharpIDE.Godot/Features/Debug_/Tab/SubTabs/ThreadsVariablesSubTab.cs index 15abcf1..b32e99c 100644 --- a/src/SharpIDE.Godot/Features/Debug_/Tab/SubTabs/ThreadsVariablesSubTab.cs +++ b/src/SharpIDE.Godot/Features/Debug_/Tab/SubTabs/ThreadsVariablesSubTab.cs @@ -20,7 +20,7 @@ public partial class ThreadsVariablesSubTab : Control _threadsVboxContainer = GetNode("%ThreadsPanel/VBoxContainer"); _stackFramesVboxContainer = GetNode("%StackFramesPanel/VBoxContainer"); _variablesVboxContainer = GetNode("%VariablesPanel/VBoxContainer"); - GlobalEvents.DebuggerExecutionStopped += OnDebuggerExecutionStopped; + GlobalEvents.Instance.DebuggerExecutionStopped += OnDebuggerExecutionStopped; } diff --git a/src/SharpIDE.Godot/Features/Run/RunPanel.cs b/src/SharpIDE.Godot/Features/Run/RunPanel.cs index 01f3b54..151a8a8 100644 --- a/src/SharpIDE.Godot/Features/Run/RunPanel.cs +++ b/src/SharpIDE.Godot/Features/Run/RunPanel.cs @@ -21,11 +21,11 @@ public partial class RunPanel : Control //_tabBar.TabClosePressed _tabBar.TabClicked += OnTabBarTabClicked; _tabsPanel = GetNode("%TabsPanel"); - GlobalEvents.ProjectStartedRunning += async projectModel => + GlobalEvents.Instance.ProjectStartedRunning += async projectModel => { await this.InvokeAsync(() => ProjectStartedRunning(projectModel)); }; - GlobalEvents.ProjectStoppedRunning += async projectModel => + GlobalEvents.Instance.ProjectStoppedRunning += async projectModel => { await this.InvokeAsync(() => ProjectStoppedRunning(projectModel)); }; diff --git a/src/SharpIDE.Godot/IdeRoot.cs b/src/SharpIDE.Godot/IdeRoot.cs index 8756bdd..5020c4c 100644 --- a/src/SharpIDE.Godot/IdeRoot.cs +++ b/src/SharpIDE.Godot/IdeRoot.cs @@ -2,6 +2,7 @@ using Godot; using Microsoft.Build.Locator; using Microsoft.Extensions.Hosting; using SharpIDE.Application.Features.Analysis; +using SharpIDE.Application.Features.Events; using SharpIDE.Application.Features.SolutionDiscovery; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; using SharpIDE.Godot.Features.BottomPanel; @@ -34,6 +35,7 @@ public partial class IdeRoot : Control public override void _EnterTree() { GodotGlobalEvents.Instance = new GodotGlobalEvents(); + GlobalEvents.Instance = new GlobalEvents(); } public override void _Ready() diff --git a/src/SharpIDE.Photino/Components/Run/RunPanel.razor b/src/SharpIDE.Photino/Components/Run/RunPanel.razor index 32336a2..874d321 100644 --- a/src/SharpIDE.Photino/Components/Run/RunPanel.razor +++ b/src/SharpIDE.Photino/Components/Run/RunPanel.razor @@ -54,7 +54,7 @@ { var tasks = SolutionModel.AllProjects.Select(p => p.MsBuildEvaluationProjectTask); await Task.WhenAll(tasks); - GlobalEvents.ProjectsRunningChanged += OnProjectsRunningChanged; + GlobalEvents.Instance.ProjectsRunningChanged += OnProjectsRunningChanged; } private void CloseTab(SharpIdeProjectModel project) @@ -67,7 +67,7 @@ await InvokeAsync(StateHasChanged); } - public void Dispose() => GlobalEvents.ProjectsRunningChanged -= OnProjectsRunningChanged; + public void Dispose() => GlobalEvents.Instance.ProjectsRunningChanged -= OnProjectsRunningChanged; private void SetActiveTab(SharpIdeProjectModel project) { diff --git a/src/SharpIDE.Photino/Components/Run/RunPopover.razor b/src/SharpIDE.Photino/Components/Run/RunPopover.razor index 57c9c17..51d4eb9 100644 --- a/src/SharpIDE.Photino/Components/Run/RunPopover.razor +++ b/src/SharpIDE.Photino/Components/Run/RunPopover.razor @@ -57,7 +57,7 @@ protected override void OnInitialized() { - GlobalEvents.ProjectsRunningChanged += OnProjectsRunningChanged; + GlobalEvents.Instance.ProjectsRunningChanged += OnProjectsRunningChanged; } protected override async Task OnParametersSetAsync() @@ -73,5 +73,5 @@ await InvokeAsync(StateHasChanged); } - public void Dispose() => GlobalEvents.ProjectsRunningChanged -= OnProjectsRunningChanged; + public void Dispose() => GlobalEvents.Instance.ProjectsRunningChanged -= OnProjectsRunningChanged; } diff --git a/src/SharpIDE.Photino/Layout/MainLayout.razor b/src/SharpIDE.Photino/Layout/MainLayout.razor index 51f015e..d77379c 100644 --- a/src/SharpIDE.Photino/Layout/MainLayout.razor +++ b/src/SharpIDE.Photino/Layout/MainLayout.razor @@ -136,8 +136,9 @@ protected override async Task OnInitializedAsync() { + GlobalEvents.Instance = new GlobalEvents(); await LoadSolutionFromInteractivePicker(AppState.IdeSettings.AutoOpenLastSolution); - GlobalEvents.StartedRunningProject += OnStartedRunningProject; + GlobalEvents.Instance.StartedRunningProject += OnStartedRunningProject; } private void OnProblemSelected(SharpIdeFile file)