Page 1 of 1

[Solved] Packaging right-click context menus in an extension

PostPosted: Mon Feb 03, 2020 11:37 pm
by dbm
I am developing a programming tool extension on the Windows 10 version of Libre Office 6.3 and have run into a difficulty packaging the macros and related menu/toolbar/context menu components into an extension. While I have been able to add menu and tool bar changes using ADDON.XCU xml, specifications, I have been unable to find a method of packaging my context menu changes.

Below is an example of the type of context menu change I would like to package, highlighted and circled:

Image


Ideally, I would like to include these changes as something similar to the specification used for adding and merging menus and toolbars in the extension package.

Alternatively, I would be open to building these menus dynamically, using a basic macro, if someone can point me to appropriate documentation and/or examples.

Does anyone know of documentation, posts or examples explaining how to accomplish this using either of these techniques, or can suggest another method of modifying context menus from an extension.

Thanks in advance – david.

Re: Packaging right-click context menus in an extension

PostPosted: Tue Feb 04, 2020 12:16 am
by JeJe
Don't know about extensions but for information on intercepting context menus:

https://wiki.openoffice.org/wiki/User:A ... ementation

viewtopic.php?f=45&t=81436

An alternative to modifying the context menu might be to use a mouse handler and have a menu that pops up when you right click with a modifier key (eg shift + right click).

Edit: Or a keyboard shortcut of course.

Re: Packaging right-click context menus in an extension

PostPosted: Tue Feb 04, 2020 12:24 am
by Villeroy
I would think that LibreOffice can do that because LibreOffice lets you customize context menus just like main menues and toolbars.

Re: Packaging right-click context menus in an extension

PostPosted: Tue Feb 04, 2020 12:36 am
by JeJe
Another advance from LibreOffice! Someone asked a similar question about a year ago but got no answer

https://ask.libreoffice.org/en/question ... extension/

LibreOffice 6.2 API Documentation would be the place to look maybe:

https://api.libreoffice.org/

Edit:

Java ContextMenuInterceptor example:

https://api.libreoffice.org/examples/De ... mples.html

Re: Packaging right-click context menus in an extension

PostPosted: Tue Feb 04, 2020 2:10 am
by dbm
Thanks for the responses.

I will investigate the context menu strategy.

It does not appear that anyone answered the similar question posed last year, but given the ability to package tool bars and menus, one would think that the ability to package context menus would be offered as well. Does anyone have any information indicating that this can not be done with the current release of the software?

Re: Packaging right-click context menus in an extension

PostPosted: Tue Feb 04, 2020 12:20 pm
by Villeroy
https://libreoffice.org/ is the successor to OpenOffice. SInce many years OpenOffice is no longer under active development.

Re: Packaging right-click context menus in an extension

PostPosted: Fri Feb 07, 2020 9:43 pm
by dbm
I did find an acceptable solution for this issue and while it works in my case, it may not be universally applicable.

In LibreOffice 6.3.4.2, I was able to package all of the menu, toolbar and context menu customizations in a template which I then load when initializing the code for my extension. The only issue that I encountered was, what I think is a bug in the toolbar customization where icons are corrupted when scoping the toolbar customs at the document level. It is possible to replace the corrupted icon file with a sound file and repack the template though it adds a bunch of steps to the packaging process. Alternatively, tool changes and menu changes could be packaged using the traditional methods while just packaging the context menus in a template.

While this works in my case, I do not expect that this solution will work for everyone - it would be nice to have a documented way of packaging context menu changes and also notebook bar changes.

Re: [Solved] Packaging right-click context menus in an exten

PostPosted: Fri Feb 07, 2020 11:28 pm
by JeJe
LibreOffice has three different icon sizes for toolbars so to be compatible with all options your customization should provide icons for each... just mentioning that in case it might have something to do with your icon problems.

Re: [Solved] Packaging right-click context menus in an exten

PostPosted: Sun Feb 21, 2021 3:40 pm
by DavidBo
Great you have solved it, but I don't understand how you did it.
How could you design a context menu entry? shown in your picture.
Next what do mean by template? What kind of file are you working with?

Re: [Solved] Packaging right-click context menus in an exten

PostPosted: Sun Feb 21, 2021 3:46 pm
by Villeroy
If you don't know what a template is, you never used any office suite of the past 30 years.

Re: [Solved] Packaging right-click context menus in an exten

PostPosted: Sun Feb 21, 2021 3:54 pm
by DavidBo
I don't understand how menus are related to templates unless we are talking about special templates used for extensions.
Another possibility is that he has added the menu entries through the tool-> customize functionality.
I have not seen how you can add a right click context menu in an addons.xcu. So if he has done that I would like to know.

Re: [Solved] Packaging right-click context menus in an exten

PostPosted: Sun Feb 21, 2021 4:13 pm
by RoryOF

Re: [Solved] Packaging right-click context menus in an exten

PostPosted: Sun Feb 21, 2021 5:20 pm
by Villeroy
DavidBo wrote:I don't understand how menus are related to templates unless we are talking about special templates used for extensions.
Another possibility is that he has added the menu entries through the tool-> customize functionality.
I have not seen how you can add a right click context menu in an addons.xcu. So if he has done that I would like to know.

Like MS Office, OpenOffice allows you to customize toolbars and menu entries specific to a document class (template). Just declare that you want to save the customization in the current document instead of the global settings.
Keyboard shortcuts would be too confusing, therefore you can't define shortcuts for specific documents. LibreOffice added the ability to customize context menues. This way you create a template with or without macro code that serves a special purpose (reporting, data entry, form letters etc.) with menues and toolbars adjusted to the specific task. This is sooo 90ies but 1% of office users may be still able to utilize stuff like this.