You might have noticed last time that Abiathar extension objects don't have a whole lot in terms of members. Events are received through the event bus. To make your extension handle an event, create a public function on the event object that receives one of the subclasses of AbiatharEvent, and add the AbiatharEventBusAttribute attribute to the method. This makes Abiathar see the method as an event handler. All event objects have a state accessor that you can use to interact with Abiathar.
Let's look at some "lifecycle" events.
After Abiathar loads all the extensions, it sends AbiatharExtensionsLoadedEvent. Extensions may use the RequestAnother method to ask for another round of these (say, it wants to talk to another extension after the other one has initialized). Therefore, you need to check whether you've already responded appropriately to one of these events so that you don't initialize things too many times.
Soon after, AbiatharSetupMenuStripEvent is sent. This provides the main menu of the window so you can fiddle around with it and add menu items if you please.
When a new project is created, AbiatharRegisterFileConfigEvent is sent. If your extension needs to store some bookkeeping in the project, add an entry to ConfigFiles. Configuration storage will be addressed next time.
When an existing project is loaded, AbiatharLoadFileConfigEvent is sent. Check the Name property and, if the configuration object belongs to your extension, set the ConfigTemplate to a default/empty instance of your configuration type. If a configuration section is not claimed, it will be deleted.
When the application is closing, AbiatharClosingEvent is sent. In response to this, clean up any external resources, like temporary files.
No comments:
Post a Comment