Hello @Orpheus99,
It is because the Highlight Color command ( .uno:CharBackgroundExt
) requires an argument ( property“BackColor” of type Long ) in order to set the Highlight Color.
If the .uno:CharBackgroundExt
command is invoked without an argument, then it will Unset the Highlight Color.
You can test this for yourself, by selecting a piece of text that already has a highlight color set, and then click on your own added context menu command. The highlight color will then be cleared.
If you put the same command in a Toolbar button then it works, because the button has an extra feature of setting the desired color ( using the small arrow ).
For your context menu, you could use a macro to specify the BackColor property for the .uno:CharBackgroundExt
command.
Just copy-paste the code below into your Basic Macro Library, then Add a new Command to your Context menu, and in the Category
listbox scroll down to LibreOffice Macros
and click to locate the macro called highlight_Selected
.
EDITED 2017-01-17
fixed rgb value instead of getRecentColors()
EDIT 2 : got rid of the dispatch, that was unreliable too! omg…
Sub highLight_Selected()
REM Highlight the currently selected Text using the most recently selected Color.
Dim oSel As Object : oSel = ThisComponent.CurrentSelection.getByIndex(0)
oSel.CharBackColor = RGB( 100, 255, 100) ‘getRecentColors()(0)
End Sub
Function getRecentColors()
REM Index 0 is the most recent color.
Dim aProps(1) As New com.sun.star.beans.PropertyValue
aProps(0).Name = "nodepath" : aProps(0).Value = "/org.openoffice.Office.Common/UserColors/"
aProps(1).Name = "enableasync" : aProps(1).Value = False
Dim oConfig As Object : oConfig = createUnoService( "com.sun.star.configuration.ConfigurationProvider" )
Dim oUserColors As Object
oUserColors = oConfig.createInstanceWithArguments( "com.sun.star.configuration.ConfigurationAccess", aProps() )
getRecentColors = oUserColors.getByName( "RecentColor" )
End Function
HTH, lib