Has anyone tried detecting event when document (
MSDocument) becomes active (main)? In fact, I want to catch this to enable/disable commands in plugin menu based by checking certain condition in current instance of
I already managed to implement enabling/disabling of menu commands by inspecting elements in
NSApplication.sharedApplication.mainMenu() and executing
menuItem.setEnabled(true/false). So that's not a problem.
Ultimately I want to execute this enabling/disabling logic once again when user jumps between Sketch documents.
What I already tried is adding a handler for
OpenDocument Sketch's event in
manifest.json, and then inside handler adding observer for
NSNotificationCenter.defaultCenter() listening to
NSWindowBecomeMainNotification events. Even though it works, and delegate method
windowDidBecomeMain: is called correctly after document becomes active, observers are duplicated. Because
OpenDocument is obviously fired for each opened document. And it leads to some memory-leaking that I would like to avoid.
I also found mentions for AppKit's
validateMenuItem method, but I have no idea how I can implement this inside plugin runtime.
Does anyone knows how this can be solved?