Multiple instances of pdf editor with multiple custom PdfEditorCommandHandlers

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
coblejesse
User
Posts: 34
Joined: Thu May 16, 2019 7:44 pm

Multiple instances of pdf editor with multiple custom PdfEditorCommandHandlers

Post by coblejesse »

Hi,

I have multiple instances of the pdf editor control in different forms, and a custom PdfEditorCommandHandler for the cmd.save command. But it seems as though only the last PdfEditorCommandHandler instance gets called when hitting save in any open pdf editor control.

So if I have two instances of the pdf editor control open, A and B. If first A is opened, and the cmd.save cmd.Handler is set to an instance of PdfEditorCommandHandler, and then B is opened, and it's instance of PdfEditorCommandHandler is set to it's cmd.save cmd.Handler, then when hitting save in A, then B's PdfEditorCommandHandler is called, and B's document is saved. Not A.

Code: Select all

            //this is set for each instance of the pdf editor control
	    PdfEditorCommandHandler cmdHandler = new PdfEditorCommandHandler();
            PDFXEdit.IUIX_Cmd cmd;
            cmd = GetIUIX_Cmd("cmd.save");
            cmd.Handler = cmdHandler;
            
            //when firing the event OnSaveEvent in cmdHandler, the last instance of pdf editor control that was set to the 
            //last instance of PdfEditorCommandHandler instantiated is being called, and then subsequently the wrong document is saved.
            cmdHandler.OnSaveEvent += SaveEvent;
            
            public PDFXEdit.IUIX_Cmd GetIUIX_Cmd(string cmd)
            {
                  return uiInst.CmdManager.Cmds.Find(cmd);
       	    }
Thanks in advance for the help. I have been working on this for about a day and a half now, and am not sure where to go from here.
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Multiple instances of pdf editor with multiple custom PdfEditorCommandHandlers

Post by zarkogajic »

Hi,
cmd.Handler = cmdHandler;
This is why. A command is "a singleton" and by this line of code you assign this cmdHandler to the command (never mind in what Control and all previous handlers are ignored).

Anyhow, why having multiple instances of IUIX_CmdHandler?

You can have only one to handle each and every command - never mind how many pxv_Controls you have.

When the command is executed use IPXV_Inst's GetMainViewFromUIObj(pOwner, false) this will return the MainView. Compare this to the Frame.View of your pxvControls and you will know in what Control the cmd.save was executed.

-žarko
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Multiple instances of pdf editor with multiple custom PdfEditorCommandHandlers

Post by Sasha - Tracker Dev Team »

Thanks for the assistance žarko.
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
coblejesse
User
Posts: 34
Joined: Thu May 16, 2019 7:44 pm

Re: Multiple instances of pdf editor with multiple custom PdfEditorCommandHandlers

Post by coblejesse »

Thanks very much for the information!

This helps so much:
"When the command is executed use IPXV_Inst's GetMainViewFromUIObj(pOwner, false) this will return the MainView. Compare this to the Frame.View of your pxvControls and you will know in what Control the cmd.save was executed."
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Multiple instances of pdf editor with multiple custom PdfEditorCommandHandlers

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply