refactor sln explorer context menus

This commit is contained in:
Matt Parker
2025-10-10 19:35:24 +10:00
parent 416f208ae0
commit 42f9998970
4 changed files with 134 additions and 93 deletions

View File

@@ -50,99 +50,6 @@ public partial class SolutionExplorerPanel : MarginContainer
}
}
private void OpenContextMenuFolder(SharpIdeFolder folder)
{
var menu = new PopupMenu();
AddChild(menu);
menu.AddItem("Reveal in File Explorer", 0);
menu.PopupHide += () => menu.QueueFree();
menu.IdPressed += id =>
{
if (id is 0)
{
// Reveal in File Explorer
OS.ShellOpen(folder.Path);
}
};
var globalMousePosition = GetGlobalMousePosition();
menu.Position = new Vector2I((int)globalMousePosition.X, (int)globalMousePosition.Y);
menu.Popup();
}
private void OpenContextMenuProject(SharpIdeProjectModel project)
{
var menu = new PopupMenu();
AddChild(menu);
menu.AddItem("Run", 0);
menu.AddSeparator();
menu.AddItem("Build", 1);
menu.AddItem("Rebuild", 2);
menu.AddItem("Clean", 3);
menu.PopupHide += () =>
{
GD.Print("QueueFree menu");
menu.QueueFree();
};
menu.IdPressed += id =>
{
if (id is 0)
{
// Run project
}
if (id is 1)
{
// Build project
}
else if (id is 2)
{
// Rebuild project
}
else if (id is 3)
{
// Clean project
}
};
var globalMousePosition = GetGlobalMousePosition();
menu.Position = new Vector2I((int)globalMousePosition.X, (int)globalMousePosition.Y);
menu.Popup();
}
private void OpenContextMenuFile(SharpIdeFile file)
{
var menu = new PopupMenu();
AddChild(menu);
menu.AddItem("Open", 0);
menu.AddItem("Reveal in File Explorer", 1);
menu.AddSeparator();
menu.AddItem("Copy Full Path", 2);
menu.PopupHide += () =>
{
GD.Print("QueueFree menu");
menu.QueueFree();
};
menu.IdPressed += id =>
{
if (id is 0)
{
GodotGlobalEvents.Instance.FileSelected.InvokeParallelFireAndForget(file, null);
}
else if (id is 1)
{
OS.ShellOpen(Path.GetDirectoryName(file.Path)!);
}
else if (id is 2)
{
DisplayServer.ClipboardSet(file.Path);
}
};
var globalMousePosition = GetGlobalMousePosition();
menu.Position = new Vector2I((int)globalMousePosition.X, (int)globalMousePosition.Y);
menu.Popup();
}
private async Task OnFileExternallySelected(SharpIdeFile file, SharpIdeFileLinePosition? fileLinePosition)
{
await Task.CompletedTask.ConfigureAwait(ConfigureAwaitOptions.ForceYielding);