Vixen
02b45cc4
csharp
public sealed class PluginContext

What a plugin is handed: the editor, and a scope that remembers what it added.

Read the guide page for this →

Remarks

Every Add… here does two things — it registers, and it records the undo. That is the difference between this and reaching for context.Shell.Commands.Add directly, which is allowed and is occasionally right: what you give up is unloadability, because a command the editor still holds is a reference into the plugin's assembly and the assembly is then loaded for the rest of the session. OnUnload is how anything registered the long way is brought back into the scope.

⚠ A registration that collides throws, and the loader lets it. CommandRegistry.Add refuses a second file.save rather than replacing it or ignoring it, so a plugin naming a command somebody already owns fails to activate and is reported with both names in the message. Prefixing your ids with your plugin id is the way not to find this out from a user.

⚠ Everything here runs on the frame thread. The shell's registries are not thread-safe and nothing in the editor's loop locks them. A plugin doing real work should put it on Shell.Tasks, which is the background-task manager the importer and the content build already use, and touch the interface from the continuation the manager pumps.

Fields and properties (6)

  • public PluginDescriptor Descriptor

    The plugin, as it was found on disk.

  • public PluginManifest Manifest

    What it says about itself.

  • public string Directory

    The plugin's own folder, which is where its assets and its settings belong.

  • public EditorShell Shell

    The editor's chrome: commands, panels, menus, notifications, background tasks.

  • public PluginServices Services

    The extension points that are not the shell's. See PluginServices.

  • public PluginRegistrations Registrations

    What will be undone when the plugin is unloaded.

Methods (15)

  • public EditorCommand AddCommand(EditorCommand command)

    Adds a command, and takes it out again on unload.

  • public EditorCommand AddCommand(string id, StringId title, Action run)

    Adds a command built from its parts.

  • public PanelDescriptor AddPanel(PanelDescriptor descriptor)

    Adds a panel and the command that shows it, and takes both out again on unload.

  • public PanelDescriptor AddPanel(string id, StringId title, Action<DockPanel> build)

    Adds a panel from its parts.

  • public IEditorMode AddMode(IEditorMode mode)

    Adds an editor mode and its button on the mode bar, and takes both out on unload.

  • public void AddLayout(string name, StringId title, Func<DockLayout> layout)

    Adds a named arrangement and the command that applies it.

  • public MenuGroup AddMenu(StringId title, int index = -1)

    Adds a menu to the bar, and takes it off again on unload.

  • public MenuGroup? FindMenu(string titleId)

    One of the editor's own menus, by the id its title carries.

  • public MenuGroup AddSubmenu(MenuGroup parent, StringId title, int index = -1)

    Adds a submenu to a menu, and takes it off again on unload.

  • public void AddMenuItem(MenuGroup group, string commandId)

    Adds a line to an existing menu, and takes it out again on unload.

  • public BindResult AddDefaultBinding(string commandId, KeyChord chord)

    Suggests a keyboard shortcut for one of the plugin's commands.

  • public void OnUpdate(Action<TimeSpan> update)

    Asks to be called once a frame, and stops being called on unload.

  • public void OnUnload(Action action)

    Records something to undo when the plugin is unloaded.

  • public T Owns<T>(T scope) where T : IDisposable

    Takes ownership of a registration scope, so unloading disposes it.

  • public TService With<TService>(Action<TService> register, Action<TService> unregister) where TService : class

    Registers with one of the host's own registries, and takes it back out on unload.

Used by (12)

  • AssetEditorsModuleVixen.Editor.AssetEditors
  • BlockoutModuleVixen.Editor.Blockout
  • DeclaredContributionsVixen.Editor.App
  • DiagnosticsModuleVixen.Editor.Diagnostics
  • IContributionScannerVixen.Editor.Plugin
  • IEditorPluginVixen.Editor.Plugin
  • ModuleVixen.Editor.Plugin.Tests
  • ModuleTestsVixen.Editor.Plugin.Tests
  • PluginHostVixen.Editor.Plugin
  • ScriptModuleVixen.Editor.Scripts
  • ScriptsModuleVixen.Editor.Scripts
  • TerrainModuleVixen.Editor.Terrain