From 247989fda4d603dfc8e0b9ab471058cea7088530 Mon Sep 17 00:00:00 2001 From: Matt Parker <61717342+MattParkerDev@users.noreply.github.com> Date: Wed, 27 Aug 2025 22:46:39 +1000 Subject: [PATCH] change toggle button state externally --- .../Features/LeftSideBar/LeftSideBar.cs | 16 ++++++++++++++++ src/SharpIDE.Godot/Features/Run/RunMenuItem.cs | 2 +- src/SharpIDE.Godot/GodotGlobalEvents.cs | 3 +++ src/SharpIDE.Godot/IdeRoot.cs | 2 +- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/SharpIDE.Godot/Features/LeftSideBar/LeftSideBar.cs b/src/SharpIDE.Godot/Features/LeftSideBar/LeftSideBar.cs index e8c6959..875111b 100644 --- a/src/SharpIDE.Godot/Features/LeftSideBar/LeftSideBar.cs +++ b/src/SharpIDE.Godot/Features/LeftSideBar/LeftSideBar.cs @@ -1,3 +1,4 @@ +using Ardalis.GuardClauses; using Godot; namespace SharpIDE.Godot.Features.LeftSideBar; @@ -20,5 +21,20 @@ public partial class LeftSideBar : Panel _problemsButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Problems : null); _runButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Run : null); _buildButton.Toggled += toggledOn => GodotGlobalEvents.InvokeBottomPanelTabSelected(toggledOn ? BottomPanelType.Build : null); + GodotGlobalEvents.BottomPanelTabExternallySelected += OnBottomPanelTabExternallySelected; + } + + private async Task OnBottomPanelTabExternallySelected(BottomPanelType arg) + { + await this.InvokeAsync(() => + { + switch (arg) + { + case BottomPanelType.Run: _runButton.ButtonPressed = true; break; + case BottomPanelType.Build: _buildButton.ButtonPressed = true; break; + case BottomPanelType.Problems: _problemsButton.ButtonPressed = true; break; + default: throw new ArgumentOutOfRangeException(nameof(arg), arg, null); + } + }); } } \ No newline at end of file diff --git a/src/SharpIDE.Godot/Features/Run/RunMenuItem.cs b/src/SharpIDE.Godot/Features/Run/RunMenuItem.cs index b03a162..4955d1f 100644 --- a/src/SharpIDE.Godot/Features/Run/RunMenuItem.cs +++ b/src/SharpIDE.Godot/Features/Run/RunMenuItem.cs @@ -47,7 +47,7 @@ public partial class RunMenuItem : HBoxContainer private async void OnRunButtonPressed() { - GodotGlobalEvents.InvokeBottomPanelTabSelected(BottomPanelType.Run); + GodotGlobalEvents.InvokeBottomPanelTabExternallySelected(BottomPanelType.Run); await Singletons.RunService.RunProject(Project).ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/SharpIDE.Godot/GodotGlobalEvents.cs b/src/SharpIDE.Godot/GodotGlobalEvents.cs index 181c702..5e31e1b 100644 --- a/src/SharpIDE.Godot/GodotGlobalEvents.cs +++ b/src/SharpIDE.Godot/GodotGlobalEvents.cs @@ -2,6 +2,9 @@ public static class GodotGlobalEvents { + public static event Func BottomPanelTabExternallySelected = _ => Task.CompletedTask; + public static void InvokeBottomPanelTabExternallySelected(BottomPanelType type) => BottomPanelTabExternallySelected.Invoke(type); + public static event Func BottomPanelTabSelected = _ => Task.CompletedTask; public static void InvokeBottomPanelTabSelected(BottomPanelType? type) => BottomPanelTabSelected.Invoke(type); diff --git a/src/SharpIDE.Godot/IdeRoot.cs b/src/SharpIDE.Godot/IdeRoot.cs index bb48bb5..f39a8ad 100644 --- a/src/SharpIDE.Godot/IdeRoot.cs +++ b/src/SharpIDE.Godot/IdeRoot.cs @@ -56,7 +56,7 @@ public partial class IdeRoot : Control private async void OnBuildSlnButtonPressed() { - GodotGlobalEvents.InvokeBottomPanelTabSelected(BottomPanelType.Build); + GodotGlobalEvents.InvokeBottomPanelTabExternallySelected(BottomPanelType.Build); await Singletons.BuildService.MsBuildSolutionAsync(_solutionExplorerPanel.SolutionModel.FilePath); }