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) |
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().