project context menu v1

This commit is contained in:
Matt Parker
2025-10-10 20:41:30 +10:00
parent c833527c23
commit 4846c37eac
4 changed files with 19 additions and 11 deletions

View File

@@ -18,7 +18,7 @@ public class BuildService
{ {
public event Func<Task> BuildStarted = () => Task.CompletedTask; public event Func<Task> BuildStarted = () => Task.CompletedTask;
public ChannelTextWriter BuildTextWriter { get; } = new ChannelTextWriter(); public ChannelTextWriter BuildTextWriter { get; } = new ChannelTextWriter();
public async Task MsBuildSolutionAsync(string solutionFilePath, BuildType buildType = BuildType.Build, CancellationToken cancellationToken = default) public async Task MsBuildAsync(string solutionOrProjectFilePath, BuildType buildType = BuildType.Build, CancellationToken cancellationToken = default)
{ {
var normalOut = Console.Out; var normalOut = Console.Out;
Console.SetOut(BuildTextWriter); Console.SetOut(BuildTextWriter);
@@ -41,7 +41,7 @@ public class BuildService
var targetsToBuild = TargetsToBuild(buildType); var targetsToBuild = TargetsToBuild(buildType);
var buildRequest = new BuildRequestData( var buildRequest = new BuildRequestData(
projectFullPath : solutionFilePath, projectFullPath : solutionOrProjectFilePath,
globalProperties: new Dictionary<string, string?>(), globalProperties: new Dictionary<string, string?>(),
toolsVersion: null, toolsVersion: null,
targetsToBuild: targetsToBuild, targetsToBuild: targetsToBuild,

View File

@@ -1,5 +1,8 @@
using Godot; using Godot;
using SharpIDE.Application.Features.Build;
using SharpIDE.Application.Features.Events;
using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence; using SharpIDE.Application.Features.SolutionDiscovery.VsPersistence;
using SharpIDE.Godot.Features.BottomPanel;
namespace SharpIDE.Godot.Features.SolutionExplorer; namespace SharpIDE.Godot.Features.SolutionExplorer;
@@ -36,19 +39,19 @@ public partial class SolutionExplorerPanel
} }
if (actionId is ProjectContextMenuOptions.Build) if (actionId is ProjectContextMenuOptions.Build)
{ {
_ = Task.GodotRun(async () => await MsBuildProject(project, BuildType.Build));
} }
else if (actionId is ProjectContextMenuOptions.Rebuild) else if (actionId is ProjectContextMenuOptions.Rebuild)
{ {
_ = Task.GodotRun(async () => await MsBuildProject(project, BuildType.Rebuild));
} }
else if (actionId is ProjectContextMenuOptions.Clean) else if (actionId is ProjectContextMenuOptions.Clean)
{ {
_ = Task.GodotRun(async () => await MsBuildProject(project, BuildType.Clean));
} }
else if (actionId is ProjectContextMenuOptions.Restore) else if (actionId is ProjectContextMenuOptions.Restore)
{ {
_ = Task.GodotRun(async () => await MsBuildProject(project, BuildType.Restore));
} }
}; };
@@ -56,4 +59,9 @@ public partial class SolutionExplorerPanel
menu.Position = new Vector2I((int)globalMousePosition.X, (int)globalMousePosition.Y); menu.Position = new Vector2I((int)globalMousePosition.X, (int)globalMousePosition.Y);
menu.Popup(); menu.Popup();
} }
private static async Task MsBuildProject(SharpIdeProjectModel project, BuildType buildType)
{
GodotGlobalEvents.Instance.BottomPanelTabExternallySelected.InvokeParallelFireAndForget(BottomPanelType.Build);
await Singletons.BuildService.MsBuildAsync(project.FilePath, buildType);
}
} }

View File

@@ -88,22 +88,22 @@ public partial class IdeRoot : Control
private async void OnBuildSlnButtonPressed() private async void OnBuildSlnButtonPressed()
{ {
GodotGlobalEvents.Instance.BottomPanelTabExternallySelected.InvokeParallelFireAndForget(BottomPanelType.Build); GodotGlobalEvents.Instance.BottomPanelTabExternallySelected.InvokeParallelFireAndForget(BottomPanelType.Build);
await Singletons.BuildService.MsBuildSolutionAsync(_solutionExplorerPanel.SolutionModel.FilePath); await Singletons.BuildService.MsBuildAsync(_solutionExplorerPanel.SolutionModel.FilePath);
} }
private async void OnRebuildSlnButtonPressed() private async void OnRebuildSlnButtonPressed()
{ {
GodotGlobalEvents.Instance.BottomPanelTabExternallySelected.InvokeParallelFireAndForget(BottomPanelType.Build); GodotGlobalEvents.Instance.BottomPanelTabExternallySelected.InvokeParallelFireAndForget(BottomPanelType.Build);
await Singletons.BuildService.MsBuildSolutionAsync(_solutionExplorerPanel.SolutionModel.FilePath, BuildType.Rebuild); await Singletons.BuildService.MsBuildAsync(_solutionExplorerPanel.SolutionModel.FilePath, BuildType.Rebuild);
} }
private async void OnCleanSlnButtonPressed() private async void OnCleanSlnButtonPressed()
{ {
GodotGlobalEvents.Instance.BottomPanelTabExternallySelected.InvokeParallelFireAndForget(BottomPanelType.Build); GodotGlobalEvents.Instance.BottomPanelTabExternallySelected.InvokeParallelFireAndForget(BottomPanelType.Build);
await Singletons.BuildService.MsBuildSolutionAsync(_solutionExplorerPanel.SolutionModel.FilePath, BuildType.Clean); await Singletons.BuildService.MsBuildAsync(_solutionExplorerPanel.SolutionModel.FilePath, BuildType.Clean);
} }
private async void OnRestoreSlnButtonPressed() private async void OnRestoreSlnButtonPressed()
{ {
GodotGlobalEvents.Instance.BottomPanelTabExternallySelected.InvokeParallelFireAndForget(BottomPanelType.Build); GodotGlobalEvents.Instance.BottomPanelTabExternallySelected.InvokeParallelFireAndForget(BottomPanelType.Build);
await Singletons.BuildService.MsBuildSolutionAsync(_solutionExplorerPanel.SolutionModel.FilePath, BuildType.Restore); await Singletons.BuildService.MsBuildAsync(_solutionExplorerPanel.SolutionModel.FilePath, BuildType.Restore);
} }
private async Task OnSolutionExplorerPanelOnFileSelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition) private async Task OnSolutionExplorerPanelOnFileSelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition)

View File

@@ -196,7 +196,7 @@
{ {
if (AppState.IdeSettings.OpenTerminalOnBuildRebuildRestore) SelectBottomPanel(BottomPanelType.Build); if (AppState.IdeSettings.OpenTerminalOnBuildRebuildRestore) SelectBottomPanel(BottomPanelType.Build);
_cancellationTokenSource = new CancellationTokenSource(); _cancellationTokenSource = new CancellationTokenSource();
await BuildService.MsBuildSolutionAsync(_solutionFilePath!, buildType, _cancellationTokenSource.Token); await BuildService.MsBuildAsync(_solutionFilePath!, buildType, _cancellationTokenSource.Token);
_cancellationTokenSource = null; _cancellationTokenSource = null;
} }
private async Task CancelBuild() => await _cancellationTokenSource!.CancelAsync(); private async Task CancelBuild() => await _cancellationTokenSource!.CancelAsync();