How to hide a disabled 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: 1370
Joined: Thu Sep 05, 2019 12:35 pm

How to hide a disabled CommandItem?

Post by zarkogajic »

Hi support,

There are multiple topics asking how to hide some command/command items on various panes.

In most cases the suggestion is to use IUIX_CmdItem.Delete, like in here: viewtopic.php?f=66&t=27821

This does the trick of "hiding" a command item, but once deleted, no way to have it back (as it no longer appears in its IUIX_CmdItemBox.Items collection).

[Q1] So, is there a way to really hide a command item (and not delete)?

I've tried using:

Code: Select all

cmdItem : IUIX_CmdItem;
...
cmdItem.Show(false);

cmdItem.Set_Style(UIX_CmdItemStyle_Hidden)

cmdItem.SetStyle(UIX_CmdItemStyle_Hidden, UIX_CmdItemStyle_Hidden)

InstUI.CmdManager.UpdateCmdItems(UIX_CmdItemUpdate_Style, cmdItem.Cmd.ID);

but nothing works (i.e. the command item is still visible).

Hiding the icon, using UIX_CmdItemStyle_HideIcon does work though - but I simply cannot hide the entire item.


[Q2] Also, how come that cmdItem.IsDisabled can be true but the state is not UIX_CmdItemState_Disabled.

Example (BookmarksView command bar), having "New Bookmark" (appears as) not enabled (as document opened in "read-only" mode):

Code: Select all

 ID:cmd.bookmarksView.new, cmdItem.IsDisabled : True, UIX_CmdItemState_Disabled: False
The state returned by

Code: Select all

//maybe this is not the correct call?
cmdItem.Cmd.Handler.OnGetItemState(cmdItem.Cmd, cmdItem, pxv_Control.Doc.ActiveView.BookmarksView.Obj, cmdItemState);

//cmdItemState is $FF, not UIX_CmdItemState_Disabled.
However, for "Delete" command item (also appears as not enabled):

Code: Select all

ID:cmd.delete, cmdItem.IsDisabled : False, UIX_CmdItemState_Disabled: True

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

Re: How to hide a disabled CommandItem?

Post by Sasha - Tracker Dev Team »

Hello žarko,

You can set the hidden state by using a custom command handler.
The command can be disabled by setting the Offline property, not just state.

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

Re: How to hide a disabled CommandItem?

Post by zarkogajic »

Hi Alex,

Thanks, and sorry for the long post now but please stay with me ... as surely there must be a more straight forward approach than custom handling each and every possible command for the sake of just hiding the command item "hosting" that command.

Let me repeat what I want to do: when opening a document in read-only mode most of commands/command items will be offline/disabled (done by the pxv_control itself). I want to remove/hide all those items from the end user (but also show when needed).

Now, for the sake of simplicity, say we are targeting the BookmarsView pane. My initial idea was: once a document is loaded (since the BookmarksView pane is per document) iterate over all command panes -> command lines -> command bars -> command item boxes and finally -> command items "holding" commands. Hide the command item I do not want to be visible. Done.

Yes, there are at least three types of "ui elements" hosting commands in BookmarsView: right-click context menu (it is regenerated so deleting menu item works in e.beforeShowContextMenu ), fixed command items (buttons) and command items with popup menus (bookmark "options" command item) - those seem to be fixed - items not re-generated every time the menu shows. Of course, I want to also hide all those popup items that are disabled.

Now, as stated before, in the cmd bar, I can delete a command item but then it is gone for good (until document closed/reopened) - I do not want this - I want to be able to show/hide command items (/commands). Also, as stated in the first post, there appear to be CommandItem methods to Show() or SetStyle() - but nothing seems to work?!

Now, if I really must implement a custom command handler for each an every possible command - I first need to collect all the commands. This must not be done by hand-picking (command ids or string names like "cmd.document.exportBookmarks") what command items appear on the bar of BookmarksView (like expand, collapse, new bookmark) - as with a new version of the SDK you might add more command items to the bar - so this needs to be dynamic.

So, once a first document is loaded, get its BookmarksView, iterate over command panes -> ... -> command items. Collect them all and implement a custom handler for each and every. Do this once - as for a new document the commands on the BookmarksView will be the same and are already custom handled.

And this is only for BookmarsView. I need to do this for all document related panes and their command items / commands.

[Q] Is this really what you are telling me? As this might end by custom handling each and every possible command there is.

If this is a must, I find that hard to believe, but ok!

Can you then please provide some code on how to then hide a commandItem when custom handling the command it hosts? What code to put into, I guess, my custom implementation of OnGetItemState?

Also, say I'm custom handling "cmd.document.exportBookmarks". How do I go to (get reference to) the document from my IUIX_CmdHandler as for some documents I want to enable/hide this and for some I do not.

And also, when implementing OnGetItemSubMenu (for the "Options..." command item displaying a sub menu) - how do I get the Owner for the OnGetItemState for the items of the popup menu?

And more "how do I ..." probably to come...

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

Re: How to hide a disabled CommandItem?

Post by zarkogajic »

Hi support,

Any comments here?

Question is (in short): how to hide a command item (not delete) ?

-žarko
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: How to hide a disabled CommandItem?

Post by Vasyl-Tracker Dev Team »

Hi žarko.

To hide all cmd-items corresponding to the certain cmd you need to use:
cmd.Hidden = true;
or
cmdItem.Cmd.Hidden = true;

Note: each cmd may have many different instances(cmdItems) on the toolbars. For example in EU-Editor you may open two documents in separate mainframes and each frame will have own set of toolbars(or own Ribbon pane). As result - application will independently control two different cmdItems for each cmd-object. Also it means that for the same cmd the different cmdItems may have different states: while one is disabled(for first document) the second one can be enabled (for second document).

if you want to hide just one certain cmdItem object you may try to use:

cmdItem.Show(bShow);

According to you general idea: to hide cmds (cmdItems I guess instead) that are disabling and to show cmdItems that are enabling by the application.
I very doubt that this is a good idea. Because even if it will work correctly - in most cases it may cause massive and heavy UI-updates: because all 'touched' toolbars and whole Ribbon-pane too must be recalculated and redrawed each time when cmdItem-state is changed. And at the moment I'm not sure that is safe to change visibility of cmdItem inside the OnGetItemState callback. It was never tested for such unusual scenario..

And for sure - it is up to you, but I believe that the UI, which often hides or shows many toolbars/menu items, and which does it just by itself - it will look strange and chaotic to the user. Because it will be hard to remember where is something necessary to you, when it is constantly jumping or disappearing. And this strange effect definitely will confuse users and make such UI unusable...

Cheers.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: How to hide a disabled CommandItem?

Post by zarkogajic »

Hi Vasyl,

I know of the Hidden property for the Command. And yes, it is global so all CommandItems using that command will obey the Hidden property. Like, if I set Hidden for "cmd.delete" then it will be hidden everywhere in the UI (every CommandItem hosting that command - never mind the context) - so not really what one would like!

Then:
if you want to hide just one certain cmdItem object you may try to use:

cmdItem.Show(bShow);
I have tried "cmdItem.Show(false);" but it does NOT work. Maybe something else needs to be called for this method to work?

And, btw, what do you mean by "you may try"? Some method either works or does not work (and it should work) - so "you may try" is not the best support answer. Rather, "use this code to do whatever" is the expected answer. Or, "cannot be done" (of course also acceptable).

Anyhow, and as for the general idea: yes, I am talking about hiding command items (not commands).
And for sure - it is up to you, but I believe that the UI, which often hides or shows many toolbars/menu items, and which does it just by itself - it will look strange and chaotic to the user.
Ok, let's go back to the beginning ...

I'm opening a PDF document in read-only mode. pxv_control will nicely disable all command items (/commands) that as a result cannot be used, like "add bookmark", "delete bookmark", "insert page", "delete page" .. etc ... ALL editing-like command items.

Once in read only mode the UI has more disabled than enabled elements - for as long as this document is active.

To REMOVE the confusion for the user - I want the user to see only what makes sense for read-only documents, and not those options he/she cannot use in any way.

Say a document is loaded and some text selected, this is how the context menu for that selection will look:
image.png
There are more disabled/offline command items than those that will ever be enabled.

So I do this (by deleting menu items):
image.png
image.png (23.86 KiB) Viewed 2800 times
From my point of view - this is much better and more clear to the user and only displays *available* options.

Therefore, again, I'm concentrating for the moment on the Bookmarks Pane. By "handle" below, I mean "hide command items".

1. I can handle the context menu - as it is always re-generated - so deleting using IUIX_CmdMenu.DeleteItem does work.

2. I'm trying to hide some command pane/bar/box command items like "cmd.bookmarksView.new" but the IUIX_CmdItem's Show(false) method does nothing.

3. I'm also trying to process the menu that appears when you click "cmd.bookmarksView.options" - but I will not even start to try to explain what's happening in this case.

[Q] In short: can I hide a command item, or not?
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: How to hide a disabled CommandItem?

Post by Vasyl-Tracker Dev Team »

Hi žarko.
I'm opening a PDF document in read-only mode. pxv_control will nicely disable all command items (/commands) that as a result cannot be used, like "add bookmark", "delete bookmark", "insert page", "delete page" .. etc ... ALL editing-like command items.
Thanks for the explanation. Of course - it makes sense to hide all commands that can never be used in ReadOnly mode. But decide to make simple logic enabledCmdItem == visibleCmdItem - it may cause one uncomfortable situation. Because may exist some commands that are technically allowed by ReadOnly mode but according to the specific of document or/and to the specific of current context of input - they might be individually disabled or enabled, according to their current context of usage. If disabling/enabling will cause hiding/showing them and if it will be too often - it may confuse user too. Seems it is better to distinguish between commands disabled by using ReadOnly mode and all other commands. But at the moment there is no easy way to do it..
And, btw, what do you mean by "you may try"? Some method either works or does not work (and it should work) - so "you may try" is not the best support answer.
I just meant that you may try to call it inside from the cmdHandler::OnGetItemState. As I said in my previous post - we didn't test it, since it is very specific and unusual scenario of usage..
[Q] In short: can I hide a command item, or not?
It should work well, but as you said - it doesn't. We will check it urgently..

Cheers.
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: How to hide a disabled CommandItem?

Post by zarkogajic »

Hi Vasyl,

Yes, I'm aware of the context, so my idea was never to "enabledCmdItem == visibleCmdItem". That's why I asked how to hide a command item in general.
Seems it is better to distinguish between commands disabled by using ReadOnly mode and all other commands. But at the moment there is no easy way to do it..
Yes!

But the pxv_comtrol somehow knows what commands to always disable and what are context-disabled.

That's the logic I want to mimic and hide those command items that will be permanently disabled (that is their commands) for read-only-mode documents.

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

Re: How to hide a disabled CommandItem?  SOLVED

Post by Sasha - Tracker Dev Team »

Hello žarko,

Well we do have our inner checks that are based on many factors and thus some of the commands will be permanently disabled for the given document (for example Dynamic XFA forms have commands that are disabled). As Vasyl said, we will try to check this one.

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