When opening multiple files, the control obtained in the right-click menu listening event is not the control on the current file plug-in

I create a GlyphsPalette Plugins,There are multiple CheckBox on the panel. I add MenuTtems use

- (void)addMenuItemsForEvent:(NSEvent *)theEvent controller:(NSViewController<GSGlyphEditViewControllerProtocol>*)controller toMenu:(NSMenu *)theMenu

by addCallback:DrawBackground;
when I open more glyphsfiles,In the listening event of the menu I created, I cannot correctly obtain the status of the chebkbox in the active document’s PaletteView. No matter which file, the PaletteView of the first open document is always obtained, and the button operation on the PaletteView is correctly obtained.
Where do I need to set that the control obtained in this callback listening event is the control on the current file window?
I wonder if I have described it clearly?

You should only register the menu-callback with a dedicated instance and only once. Palette plugins will be loaded for each open document and will be removed when that document is closed. That can mess up the callback system.

What kind of state do you need to access from the menu callback?

Could you store that state in the user defaults instead (that would sync it between all open documents)?

The callback gives you the active editViewController. From it, you can access the windowController that has access to all palette instances. I can give you the details later today.

I tested many methods,and achieved it through ‘defaults’ finally. and thank you for your reply.