The contextmenu service handles the context
menus stored in a document. So far, it
provided only the AddItem() method to add
new items at the bottom of the menu.
The new method allows to forget the preconfigured
menu and to replace it completely.
Example: associate next Sub with the
on-right-click event of sheet 'Sheet1'
=> The custom menu appears when
right-clicking in column C, otherwise
normal behaviour
Sub OnRightClick1(Optional XRange)
' Xrange is a com.sun.star.table.XCellRange
Dim calc, menu, bColumn
Set calc = CreateScriptService("Calc", ThisComponent)
Set menu = calc.ContextMenus("cell")
menu.RemoveAllItems()
bColumn = ( Len(calc.Intersect("Sheet1.$C:$C", _
XRange.AbsoluteName)) > 0 )
If bColumn Then
menu.AddItem("A", Script := "vnd.sun.star.script:...&location=document")
...
End If
menu.Activate(bColumn)
End Sub
The function is available both for Basic and Python user scripts.
The user documentation will have to be reviewed.
Change-Id: I84ee8724bf99c37397a19d729133cc4686a63980
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/180520
Reviewed-by: Jean-Pierre Ledure <jp@ledure.be>
Tested-by: Jenkins