Custom command - how to "copy" state (UIX_CmdItemState) from another Command / CommandItem  SOLVED

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
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Custom command - how to "copy" state (UIX_CmdItemState) from another Command / CommandItem

Post by zarkogajic »

Hi Support,

I'm adding my custom commands to a custom command bar and custom handling them (IUIX_CmdHandler).

I need to set the state of the item (enabled/disabled) to be the same as one of the existing commands, let's call it "enableAs".

My idea was to handle the OnGetItemState method and read the state of the "enableAs", so something like:

Code: Select all

enabledAs : IUIX_Cmd;
...
    enabledAs := InstUI.CmdManager.Cmds.Find('cmd.close'); //so "hijacking" cmd.close to gets its state

    enabledAs.Handler.OnGetItemState(enabledAs, nil, pOwner, cmdItemState);
    
    ... // fails on the above line / no bar displayed and weird stuff like that
    
    nState := cmdItemState;
    
The "enabledAs.Handler.OnGetItemState" line fails whatever I use for the parameters to that method call.

In short: I want to get the state of the "cmd.close" command (as example) and set its state for my custom command's state. How?



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

Re: Custom command - how to "copy" state (UIX_CmdItemState) from another Command / CommandItem

Post by Sasha - Tracker Dev Team »

Hello žarko,

In your custom command handler's class, int the OnGetItemState method, you should execute the old handler's method first, and then read it's state value. After that you can add your own logic.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Custom command - how to "copy" state (UIX_CmdItemState) from another Command / CommandItem

Post by zarkogajic »

Hi Alex,

But there's no "oldhandler" for my custom command.

As the handler for my custom command is my custom handler.

In the OnGetItemState I'm trying to read the state of another command (as per my code above) - then set the state for my command's item.

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

Re: Custom command - how to "copy" state (UIX_CmdItemState) from another Command / CommandItem

Post by Sasha - Tracker Dev Team »

Hello žarko,

Well you can save that command's handler in your custom handler's class and then call it's OnGetItemState method and get the results - this should give more adequate behavior in this case (as you have your command near that one).

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Custom command - how to "copy" state (UIX_CmdItemState) from another Command / CommandItem

Post by zarkogajic »

Hi Alex,

The thing is that for both commands the command handler is my custom handler.

So, after a call to (enabledAs is IUIX_Cmd)

Code: Select all

enabledAs := InstUI.CmdManager.Cmds.Find('cmd.close');
The next line of code fails (weird display results):

Code: Select all

enabledAs.Handler.OnGetItemState(enabledAs, nil, pOwner, cmdItemState);
Note that in the above the "Handler" is actually my custom handler / also handling the "cmd.close".

However, if I do:

Code: Select all

//OriginalHandler is the "old hander" for cmd.close
OriginalHandler.OnGetItemState(enabledAs, nil, pOwner, cmdItemState);
Then I get the state and this seems to work.

However, I'm not sure what parameters to pass for pOwner? As in the above pOwner is the owner of my custom command - and obviously not of the command I want to get the state from.

Finally, what is pOwner when handling my custom command ?

zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Custom command - how to "copy" state (UIX_CmdItemState) from another Command / CommandItem

Post by zarkogajic »

Alex,

Can you provide some help on the pOwner parameter?

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

Re: Custom command - how to "copy" state (UIX_CmdItemState) from another Command / CommandItem  SOLVED

Post by Sasha - Tracker Dev Team »

Hello žarko,

When we are talking about the commands above the DocumentViewsArea - the owner would be MainView's object. If, for example, the command is in the BookmarksView command bar, the owner is bookmarksView.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Custom command - how to "copy" state (UIX_CmdItemState) from another Command / CommandItem

Post by zarkogajic »

Alex,

Ok, thanks, makes sense.

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

Re: Custom command - how to "copy" state (UIX_CmdItemState) from another Command / CommandItem

Post by Sasha - Tracker Dev Team »

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