Friday, September 12, 2003

Illustrator Notifiers

I'm still fighting with Illustrator. Now it's time of events (or notifiers in Illustrator terms).

Adding a notifiers is pretty easy, just a call on the appropriate interface (ops ... suite) and you are done. You have some predefined events like kAIDocumentOpenedNotifier to catch events when a document has been opened by the user or kAIDocumentClosedNotifier to be notified when the document has been closed.

When you are processing the event, you can access to the document itself and ask for some of its properties (like GetDocumentFileSpecification), unfortunately in the close event seems like that GetDocumentModified is the only functions that can be called without errors. That's pretty bad.

Digging trough SDK examples I found that you can have other types of notifiers, basically every command have it's own notifiers before and after the command has been called, for example for the Close command you can have "AI Command Notifier: Before Close" and "AI Command Notifier: After Close", but to my great surprise the Close command must be written according to the UI locale, so I've installed Illustrator in Italian and the correct event is "AI Command Notifier: Before Chiudi". I hate it. Obviously is seems like there is no way to obtain the command string according to the locale, I'll end up obtaining the correct command string with plain win32 API, I think it'll be easier.

This event is fired before the document has been really closed, so you can do you own save, ask questions to user about the closing, etc. that's fine until I discovered that when you have documents opened and you quit the application, that event will not be fired but only the onClose for each document. That makes my plugin's life more difficult because it looks like I can't understand which document is about to be closed. At this time I give up reading the pdf documentation that seems not updated and I looked directly at *.h files in the SDK include directory and I found that there is an interface that let you browse the list of open documents. That's really helped me.

Back to coding for now, I let you know who will win the war.

No comments: