change toggle button state externally

This commit is contained in:
Matt Parker
2025-08-27 22:46:39 +10:00
parent fe10a2cd7a
commit 247989fda4
4 changed files with 21 additions and 2 deletions

View File

@@ -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);
}
});
}
}

View File

@@ -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);
}
}

View File

@@ -2,6 +2,9 @@
public static class GodotGlobalEvents
{
public static event Func<BottomPanelType, Task> BottomPanelTabExternallySelected = _ => Task.CompletedTask;
public static void InvokeBottomPanelTabExternallySelected(BottomPanelType type) => BottomPanelTabExternallySelected.Invoke(type);
public static event Func<BottomPanelType?, Task> BottomPanelTabSelected = _ => Task.CompletedTask;
public static void InvokeBottomPanelTabSelected(BottomPanelType? type) => BottomPanelTabSelected.Invoke(type);

View File

@@ -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);
}