Skip to content

Events

Plugins react to editor activity through IEventBus. Events are plain structs defined in PluginEvents.h:

Event Payload
DocumentOpened DocumentId, std::filesystem::path
DocumentClosed DocumentId
DocumentSaved DocumentId
TextChanged DocumentId, pos, addedBytes, removedBytes
SelectionChanged DocumentId
ActiveDocumentChanged DocumentId
AppAboutToQuit (none)
CommandShortcutChanged commandId, sequence (new portable chord; "" = unbound)

CommandShortcutChanged fires when a command's effective shortcut changes — a user remap in the Shortcut Mapper, a keymap import/reset, or a conflict suppression engaging/lifting. Menu-bound commands need nothing (the host rebinds their action); commands registered with scope = command_scope::kPluginWindow subscribe and re-apply the sequence to their own widgets (see Commands & menus).

Subscribing

subscribe is a template that returns a Subscription (RAII). Keep the subscription alive as a member for as long as you want the callback to fire; destroying it unsubscribes.

m_sub = ctx.events().subscribe<MTE::plugin::DocumentSaved>(
    [this](const MTE::plugin::DocumentSaved& e) {
        // react to e.id ...
    });
class IEventBus {
public:
    template <class Event>
    Subscription subscribe(std::function<void(const Event&)> cb);
    // Forwards to a type-erased subscribeRaw(std::type_index, ...) internally.
};

Tip

Hold every Subscription as a plugin member so all callbacks are torn down automatically in shutdown().