In my applications, I have created a custom user menu (one per application) dynamically in the MenuBar. For that I've used the XUIElementSettings Interface. No problems to create them. Now, I want to have the possibilty to enabled (non greyed) or disabled (greyed) some items of my new menus like in the factory menus. I studied the UIElementSettings Service and when you use that, it is not possible to realize that. The only possibility, is to suppress or to add dynamically the Item in the menu. It is not fashion... I tryed also the using of the XmenuBar interface and the XPopupMenu interface by using the "enableItem" method. Different kind of problems encountered : With version 4.4.7 : C++ virtual call error message With version 5.x.x : crash of LO immediately. Is it possible to have in the ItemDescriptor Service the properties isVisible and/or a new one "Enable" available for Item menu entries of the Menubar?
(In reply to ThierryT from comment #0) > I tryed also the using of the XmenuBar interface and the XPopupMenu > interface by using the "enableItem" method. This isn't going to work. UI elements such as menubar are controlled internally by LO, and changing them directly will easily break that code (because it won't be aware of the changes you made). In general what you need isn't to disable the individual menu item - but to disable the *command* to which this item is bound. Disabling a command will be reflected in the UI by (usually) disabling all elements that bound to this command - be it a menu item or a toolbar button. There are several official solutions, that can be used to achieve this: - org.openoffice.Office.Commands configuration. This can be used for simple enabling/disabling [1]. - Dispatch Interception. Besides enabling/disabling, this allows you even to change the behavior of commands (e.g. you want a different thing to happen when clicking the "Save" button) [2]. Surprisingly there is even a way to use that from BASIC [3]. - Protocol Handlers [4]. ---- [1] https://wiki.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Disable_Commands [2] https://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Dispatch_Interception [3] http://openoffice.2283327.n4.nabble.com/Intercepting-commands-quot-uno-xxx-quot-td2772465.html - There is a sample document if you scroll a bit. [4] https://wiki.openoffice.org/wiki/Documentation/DevGuide/WritingUNO/Protocol_Handler
Created attachment 123765 [details] Greyed Items menu
Thanks for your reply. What I want to do is to grey or not the items of my custom menu like in the LO factory menu (see attached file) to have a complete visual information for the final user that this functionnality is not available in the state of my application. With your approach, the user has the visual information in the menu that the function is available and after he receives a message displayed that the function is not possible. Is it possible to grey or not the items of a custom menu ?
(In reply to ThierryT from comment #3) > With your approach, Which approach exactly? > the user has the visual information in the menu that the > function is available and after he receives a message displayed that the > function is not possible. Interception/Protocol Handlers involves passing XDispatch object, which has the ability to notify listeners about the state of the command - including disable ("grey out"). Office.Commands config also allows show/hide.
Your approach is based only on the interception of the command of the menu. That means only afterwards. Mine is based before the using of the item menu. To inform earlier the final user that this functionnality is not available at this stage of the application. I join (in the next message) an example of a prototype of the new menu inserted in the Menubar. Please, could you explain to me how can we grey some items in this menu ?
Created attachment 123772 [details] Example of new menu
(In reply to ThierryT from comment #5) > Your approach is based only on the interception of the command of the menu. > That means only afterwards. No it's not. Please read carefully the documentation about the dispatch framework.
After reading carefully and found some examples on different forums (in french, english and german) about the Dispatch framework functionnality, I understand that with this method, you can intercept the command before its execution (that means you "disabled" it). But it is still possible to select the item in the menu because it is still not greyed. It is why I said in my different comments that you make it afterwards. Information could be transmitted to the final user after the selection of the Item. My approach is : If the Item menu is GREYED (like in the other menus in LO), we avoid the possibility to select it => we disable the possibility to execute the command before its selection with the menu Item not after its selection.
(In reply to ThierryT from comment #8) > I > understand that with this method, you can intercept the command before its > execution (that means you "disabled" it). No. Interception means that the entity (i.e. the object implementing the XDispatch interface) that will be used for handling the specific command will be something yours, not the built-in one. Resolving the right object to handle some command is indeed useful before execution, but it's not the only use of it. XDispatch implementing object is also responsible for broadcasting the state of the command to its listeners, mostly UI elements like toolbar buttons or menu items. Such listeners, in turn, once get the updated state, usually represent it in some way. So e.g. if they get "disabled" state, they usually will grey out the associated UI element. > If the Item menu is GREYED (like in the other menus in LO) ... and guess how "other menus in LO" grey out their items? Right. They use the same dispatch framework mechanism I described above.