Hide Offline commands in e.beforeShowContextMenu  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: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic »

Hi,

This question is an extension to this one: viewtopic.php?f=66&t=33227

So, I have a document opened in read-only mode - no changes allowed.

Example: bookmarks pane has all the editing commands nicely disabled:
image.png
Now, I would like to hide all the disabled commands (from the bar and from the menu).

I'm looking for e.beforeShowContextMenu, iterating over Commands - but all are reported not to be offline?
e_beforeShowContextMenu: menu.bookmarksView
0, ID:cmd.bookmarksView.new cmd.Title: &New Bookmark..., IsOffline : False
2, ID:cmd.paste cmd.Title: &Paste, IsOffline : False
4, ID:cmd.bookmarksView.textSize cmd.Title: Text Si&ze, IsOffline : False
5, ID:cmd.bookmarksView.wrapTitles cmd.Title: &Wrap Long Bookmarks, IsOffline : False
6, ID:cmd.bookmarksView.showIcons cmd.Title: Show/Hide &Icons, IsOffline : False
7, ID:cmd.bookmarksView.useInheritedZoom cmd.Title: &Use Inherited Zoom, IsOffline : False
8, ID:cmd.bookmarksView.autoExpandBookmarks cmd.Title: Automatically Expand Bookmarks, IsOffline : False
10, ID:cmd.document.importBookmarks cmd.Title: Import Bookmarks..., IsOffline : False
11, ID:cmd.document.exportBookmarks cmd.Title: Export All Bookmarks..., IsOffline : False
13, ID:cmd.showPaneInfoBar cmd.Title: Show Info Bar, IsOffline : False
So, this means they get disabled (set to offline) after this event. When?

p.s.
I've also tried with custom IEventHandler (Inst.EventServer.RegisterNativeEventHandler) with same results.

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team »

Hello žarko,

From what I remember, you have disabled these commands via Document Restrictions. Thus they are not offline but the security protected.
Now about how to remove them:
1) You can mark the correspondent IUIX_Cmd as Hidden - thus every IUIX_CmdItem that has such ID on every IUIX_CmdBar will be hidden. Though this will be in all of your frames.
2) You can simply remove them from the menu in the e_beforeShowContextMenu event by their ID's, or alternatively, you can remove every command except the needed ones (this will ensure the customization block and also, when the new features will be added).

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic »

Hi Alex,

I said:
I'm using IPXC_Inst's OpenDocumentFromFile with nRestrictPerms set to (PXC_SecurityPermissions) Permit_All.
As a result, all the "edit" commands in menus and bars in various various panes are disabled / offline - this is done by the pxv_control itself.

You say:
Thus they are not offline but the security protected.
As you can see from my screen shot they do display as offline. And their Offline property is true.
[Q] If I need to check for "security protected" how do I do that?


You also said:
You can mark the correspondent IUIX_Cmd as Hidden..
This is exactly what I'm trying to do for those Commands that are made offline by the Control itself.

[Q] I want to make them Hidden if they are Offline - but all are reported not to be offline in e.beforeShowContextMenu - where I catch the menu being displayed.

I hope this is more clear no.

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team »

Hello žarko,

They are not offline - they are just disabled - you can check that in the https://sdkhelp.pdf-xchange.com/vi ... Item_State property.
Making a command Offline will disable it everywhere in the Editor that that command is being used and it's not being done by the Control, but by the developer.
If you show a popup menu, you can simply remove the disabled commands from it as I suggested before.

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic »

Hi Alex,

Ah .. I thought Offline and Disabled are the same .. ok my bad.

Anyhow, I'm going in circles...

How do I go from IUIX_Cmd to IUIX_CmdItem to read the State property?

Again, I'm iterating over menu items in e.beforeShowContextMenu. I get the command of a menu item and I can read Offline and Title and the rest.

My code (I think you can read Delphi code):

Code: Select all

  if (nEventID = EventID[e_beforeShowContextMenu]) then
  begin
    bscmEvent := IPXV_BeforeShowContextMenuEvent(pEvent);

    cmdMenu := bscmEvent.Menu;

      for idx := 0 to -1 + cmdMenu.Count do
      begin
        cmd := cmdMenu.Item[idx].Cmd;

        cis := cmdMenu.Item[idx].State;

        if Assigned(cmd) then
          DoNotifyWithMessage(Format('%d, cis: %d, ID:%s, cmd.Title: %s, IsOffline : %s', [idx, cis, PDFXHelper.Inst.ID2Str(cmd.ID), cmd.Title, BoolToStr(cmd.Offline, true)]));
      end;
  end;
So, how do I iterate over the items in the below menu, get the IUIX_CmdItems and read their state?
image.png
image.png (48.75 KiB) Viewed 4022 times

-žarko
Last edited by zarkogajic on Mon Oct 07, 2019 12:00 pm, edited 1 time in total.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic »

Alex,

Ok, found it: viewtopic.php?f=66&t=28916&p=112187&hil ... ed#p112187

So, to get the State value of the CMD, one can use: cmd.Handler.OnGetItemState (....).


-žarko
Last edited by zarkogajic on Mon Oct 07, 2019 12:00 pm, edited 1 time in total.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team »

Hello žarko,

Yes, that's the way of doing it.

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic »

Hi Alex,

Btw, How can I set the state of a CommandItem? Say I want to disable (not delete nor make it offline) a menu item?

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team »

Hello žarko,

Only though a command handler. In your case, when you want to remove the needed items from the popup menu, you can look at the state of the IUIX_CmdItem and then remove it from the IUIX_CmdMenu - it will be generated again there on the next time it's shown and you will have to do the same logic again.

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic »

Hi Alex,

For removing/deleting: ok.

This is how BookmarksView context menu looks when disabled items are removed:
image.png
image.png (14.01 KiB) Viewed 3988 times

Just to confirm: to make a (context) menu item disabled I would need to code a custom command handler for that particular command and disable it there by setting UIX_CmdItemState_Disabled?

For example, if I want to disable "Export All Bookmarks..." that would be custom handling the "cmd.document.exportBookmarks"

No other (simpler) way (just double checking)?


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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team »

Hello žarko,

Doing it via the Command Handler is a correct way - you have all of the needed data there to check, and you can disable the needed command.

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic »

Hi Alex,

Some code perhaps, please? How do I set UIX_CmdItemState_Disabled (if that's what's needed) in my custom command handler (I guess in OnGetItemState)?

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team »

Hello žarko,

Here's the sample:

Code: Select all

public void OnGetItemState(PDFXEdit.IUIX_Cmd pCmd, PDFXEdit.IUIX_CmdItem pItem, PDFXEdit.IUIX_Obj pOwner, out int nState)
{
	nState = (int)PDFXEdit.UIX_CmdItemState.UIX_CmdItemState_Disabled;

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic »

Hi Alex,

Thanks. That does it.

Now, I only need to know how to hide a command item....


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

Re: Hide Offline commands in e.beforeShowContextMenu  SOLVED

Post by Sasha - Tracker Dev Team »

Hello žarko,

That is a big one - I will forward this to my teammate - probably he can tell more and there is an easier way.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply