Skip to content

Instantly share code, notes, and snippets.

@cmargroff
Created March 2, 2024 05:21
Show Gist options
  • Save cmargroff/318d826b52cb9dc64d1604b38c18d7d7 to your computer and use it in GitHub Desktop.
Save cmargroff/318d826b52cb9dc64d1604b38c18d7d7 to your computer and use it in GitHub Desktop.
Godot editor plugin extensions for getting the top menu bar items to add your own menu items
using Godot;
// This was tested against 4.2.stable.mono
#if TOOLS
[Tool]
public static class EditorPluginExtensions
{
public static PopupMenu GetTopMenuItem(this EditorPlugin editorPlugin, string name)
{
var root = EditorInterface.Singleton.GetBaseControl();
return root
.FindChild("*EditorTitleBar*", true, false)
.FindChild(name, true, false) as PopupMenu;
}
public static PopupMenu GetSceneMenu(this EditorPlugin editorPlugin)
{
return editorPlugin.GetTopMenuItem("Scene");
}
public static PopupMenu GetProjectMenu(this EditorPlugin editorPlugin)
{
return editorPlugin.GetTopMenuItem("Project");
}
public static PopupMenu GetDebugMenu(this EditorPlugin editorPlugin)
{
return editorPlugin.GetTopMenuItem("Debug");
}
public static PopupMenu GetEditorMenu(this EditorPlugin editorPlugin)
{
return editorPlugin.GetTopMenuItem("Editor");
}
public static PopupMenu GetHelpMenu(this EditorPlugin editorPlugin)
{
return editorPlugin.GetTopMenuItem("Help");
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment