Hide Offline commands in e.beforeShowContextMenu

PDF-XChange Editor SDK for Developers

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

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: 152
Joined: Thu Sep 05, 2019 12:35 pm

Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic » Wed Oct 02, 2019 11:49 am

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

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team » Thu Oct 03, 2019 6:54 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic » Thu Oct 03, 2019 7:53 am

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

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team » Mon Oct 07, 2019 9:45 am

Hello žarko,

They are not offline - they are just disabled - you can check that in the https://sdkhelp.tracker-software.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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic » Mon Oct 07, 2019 10:42 am

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 76 times

-žarko
Last edited by zarkogajic on Mon Oct 07, 2019 12:00 pm, edited 1 time in total.

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic » Mon Oct 07, 2019 11:49 am

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.

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team » Mon Oct 07, 2019 11:57 am

Hello žarko,

Yes, that's the way of doing it.

Cheers,
Alex
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic » Tue Oct 08, 2019 3:03 pm

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

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team » Thu Oct 10, 2019 2:22 pm

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic » Thu Oct 10, 2019 3:18 pm

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 42 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

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team » Fri Oct 11, 2019 7:33 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic » Fri Oct 11, 2019 7:35 pm

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)?


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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team » Tue Oct 15, 2019 8:56 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by zarkogajic » Tue Oct 15, 2019 9:14 am

Hi Alex,

Thanks. That does it.

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


-žarko

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

Re: Hide Offline commands in e.beforeShowContextMenu

Post by Sasha - Tracker Dev Team » Tue Oct 15, 2019 9:24 am

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
Join us at Google+:
https://plus.google.com/+PDFXChangeEditorTS
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ

Post Reply