Disable context menu on multiple documents view  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

Disable context menu on multiple documents view

Post by zarkogajic »

Hi devs,

I'm following the below topic (custom event handler for the DocViewsArea object) to get notified when the tab menu appears for multi document view:

viewtopic.php?f=66&t=25064&p=97975&hili ... rea#p97975

If I got it right I should only set pEvent.Handled = true to stop the tab context menu from being displayed?

The below code is Delphi, pEvent.Handled IS set to true, but the menu still appears.

Code: Select all

procedure TIUIX_ObjImplEvent.OnEvent(const pSender: IUIX_Obj;  const pEvent: IUIX_Event);
var
  ni : UIX_NotifyInfo;
begin
  pEvent.Handled := false;

  if (pEvent.Code = e_Notify) then
  begin
    ni := UIX_NotifyInfo(Pointer(pEvent.Param1)^);

    if (ni.nCode = UIX_Notify_BeforeShowPopup) then pEvent.Handled := true;
  end;
end;
Anything else to do here?
zarkogajic
User
Posts: 1372
Joined: Thu Sep 05, 2019 12:35 pm

Re: Disable context menu on multiple documents view

Post by zarkogajic »

Ah ah ah ....

According to :
viewtopic.php?f=66&t=29426&p=120629&hil ... nu#p115630

It should be "UIX_Notify_Layout_ShowContextMenu" and not "UIX_Notify_BeforeShowPopup" (this one to deal with menu items)

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

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

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

Re: Disable context menu on multiple documents view

Post by zarkogajic »

Hi,

ah was too fast ..

According to this: viewtopic.php?f=66&t=29757&p=117713&hil ... et#p125468
Check the evt.MenuID that comes when you click on the DocViewsArea, convert the ID to string ID and use it to compare it with other menu IDs that can come through this event. If it's your menu ID then get the IUIX_CmdMenu from the event and remove/add all of the needed items.
Some code (any language would do :) perhaps?

1. How to convert ID to string (as no access to IPSV_Inst from IUIX_ObjImpl), or?
2. Once I get IUIX_CmdMenu, how do I remove the first item?

Code: Select all

    if (ni.nCode = UIX_Notify_BeforeShowPopup) then
    begin
      evt := IPXV_BeforeShowContextMenuEvent(pEvent);

      //evt.MenuID to String?

      //if MenuID is the one then:
      evt.Menu.DeleteItem(0); //this does not work


      pEvent.Handled := true;
    end
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

Here's a sample code how to get the numeric value of the ID:

Code: Select all

PDFXEdit.IPXV_BeforeShowContextMenuEvent evt = (PDFXEdit.IPXV_BeforeShowContextMenuEvent)e.pEvent;
int nID = pdfCtl.Inst.Str2ID("menu.pagesView", false);
string sID = pdfCtl.Inst.ID2Str(evt.MenuID);
if (evt.MenuID == nID) { ... }
As for the item removal - try IUIX_CmdMenu::DeleteItemsByCmdID so that you won't always remove the first item but the needed 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: Disable context menu on multiple documents view

Post by zarkogajic »

Alex,

Thanks.

But how do I get the nCmdId for DeleteItemsByCmdID, say for "Move to trash" menu item (and the rest, of course)?

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

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

You can get all of the command IDs by using the Customize Toolbars feature.

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

Re: Disable context menu on multiple documents view

Post by zarkogajic »

Hi Alex,

This is what my first action was. If I'm correct the "Move to Trash" menu item should be "cmd.moveToTrash". However, this code does nothing:

Code: Select all

    if (ni.nCode = UIX_Notify_Layout_ShowContextMenu) then
    begin
      bscmEvt := IPXV_BeforeShowContextMenuEvent(pEvent);

      nID := ipxvInst.Str2ID('menu.pagesView', false);

      if bscmEvt.MenuID = nID  then
      begin
        nID := ipxvInst.Str2ID('cmd.MoveToTrash', false);

        bscmEvt.Menu.DeleteItemsByCmdID(nID,false,true);

        pEvent.Handled := true;
      end;
    end
"Move to trash" still appears.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

Well, if it works for you, you can put the IUIX_Cmd for hidden state, then every place that the needed command is used, it will be hidden from the end-user.

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

Re: Disable context menu on multiple documents view

Post by zarkogajic »

Hi Alex,

Ok, will try that.

But, is my code wrong, i.e. why does the "move to trash" not get removed/deleted?

I need it to work in that way, as I want to use the same approach for other menu items then.

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

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

Sadly, that method won't work for you as the context menu itself is being created after this notification takes place. The event handler overload for the DocumentViewsArea works for disabling the popup appearance, but won't work for menu item hiding. So the best method here would be to use the Hidden property of the command itself.

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

Re: Disable context menu on multiple documents view

Post by zarkogajic »

Hi Alex,

Thanks, but now I lost you.

What event to catch and when to then set the hidden property of IUIX_Cmd ?

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

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

Get the IUIX_CmdManager from the IUIX_Inst. Then get the IUIX_Cmd from the IUIX_CmdManager by it's ID. Then set the Hidden property of the IUIX_Cmd to true.

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

Re: Disable context menu on multiple documents view

Post by zarkogajic »

HI Alex,

I have this code, but it does not work as cmdMoveToTrashID has the value of "0" (zero) and an AV is raised.

Code: Select all

var
  uiInst : IUIX_Inst;
  cmdMan : IUIX_CmdManager;
  cmdMoveToTrashID : integer;
begin
  uiInst := IUIX_Inst(PXV_Control1.Inst.GetExtension('UIX'));

  cmdMan := uiInst.CmdManager;
  cmdMoveToTrashID := PXV_Control1.Inst.Str2ID('cmd.MoveToTrash', false); // using IPXV_Inst, or maybe should go with:
  cmdMoveToTrashID := uiInst.Str2ID('cmd.MoveToTrash', false); //using IUIX_Inst
  // cmdMoveToTrashID is 0 in any case?
  cmdMan.Cmd[cmdMoveToTrashID].Hidden := true; //and then this raises an AV
 end;
Maybe 'cmd.MoveToTrash' is not to be used but something else?

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

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

Well you have spelled the ID of the command incorrectly - that's why you have 0:
cmd.moveToTrash

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

Re: Disable context menu on multiple documents view

Post by zarkogajic »

omg. Ok, now the code passes, but the menu item is still there:
image.png
image.png (30.84 KiB) Viewed 4866 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

I've been trying to remove this with different methods but no luck yet. This is a dynamically created command that is not in the CommandManager and it's id is cmd.moveTabToTrash not cmd.moveToTrash (that is in the File menu). So you cannot get it from the manager and disable it manually.

Also, I don't see how did you manage to do this cast:

Code: Select all

 if (ni.nCode = UIX_Notify_Layout_ShowContextMenu) then
    begin
      bscmEvt := IPXV_BeforeShowContextMenuEvent(pEvent);
The event there is e_Notify not IPXV_BeforeShowContextMenuEvent.
Sadly, you cannot get the popup itself from neither of the UIX_Notify events.
The only thing that is left is to either disable the popup menu or construct and show your own popup menu.

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

Re: Disable context menu on multiple documents view

Post by zarkogajic »

Alex,

Any way to get notified when that "cmd.moveTabToTrash" is about to be executed and somehow "cancel" it ?

Regarding:
I don't see how did you manage to do this cast
In some previous forum post I found code like that (cant remember the exact post).

Anyhow, I'm following this (please correct if wrong):

In IUIX_ObjImplEvent.OnEvent handler:

If pEvent.Code is e_Notify then pEvent.Param1 is UIX_NotifyInfo.

Then UIX_NotifyInfo's nCode is the actual notification like UIX_Notify_Layout_Changed or UIX_Notify_Layout_ShowContextMenu or UIX_Notify_Layout_AddNewTabs, ....

Now, say nCode is UIX_Notify_Layout_ShowContextMenu OR UIX_Notify_MenuItemClicked - how to get to the actual context menu (item) to be displayed/clicked - cast pEvent into what?

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

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

Hello zarkogajic,

The thing is - you cannot. I have wrote that in the previous post.

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

Re: Disable context menu on multiple documents view

Post by zarkogajic »

Hi Alex,

I thought what you said applies only to that tab popup menu.

What is then the idea behind being able to react on UIX_Notify_MenuItemClicked (as example) ?

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

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

Hello žarko,

There is some inner logic that uses majority of those notifications. The one that you are talking about is fired after the popup command is clicked with the cmd ID as it's result.

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

Re: Disable context menu on multiple documents view

Post by zarkogajic »

Ok, and how can I react on that with some code of mine?

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

Re: Disable context menu on multiple documents view  SOLVED

Post by Sasha - Tracker Dev Team »

Hello žarko,

Well, you can listen that the command was executed, but you cannot change the outcome - that's the problem.

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

Re: Disable context menu on multiple documents view

Post by zarkogajic »

:)

ok.

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

Re: Disable context menu on multiple documents view

Post by Sasha - Tracker Dev Team »

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