Highlight Color added to Context Menu does not "highlight"

5.3.7.2. (x64) Win7.1 Pro:

I used “Add Command” to select the function “Format\Highlight Color” (such as resides on one of the main Toolbars) to my “Customize\Context Menu\Text” menu. There are actually “two” of those “Highlight Color” Command items optionally available from the list under “Commands.” The first has “Description” box content, describing exactly how the “Highlight Color” command in the Toolbar works.

The second identical “Highlight Color” Command (graphically and textually) has no “Description” box content.

Then there is a “Highlight Fill” command without an icon or description.

I can add any of these easily to my Text Context Menu, but when any of these added “Highlight…” commands are clicked from within my “customized” Text Context Menu, none of them will apply my “highlight” (or any highlight).

What do I need to learn or what is not working that should?

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

lib, thanks for your interest. I’m not “there” yet: I pasted the code at the bottom of the Macros > “My Macros\Standard\Module 1” file.

I understand very little of this, although I do program in other languages.

I can see that you have added a function getRecentColors() that gets called within highLight_Selected(), but I haven’t been able to get any “highlighting” by just adding the above code and the Command to my Context menu. This will take some time/study. Thanks.

Yw @Orpheus,

First establish if the function highLight_Selected() is executed at all, e.g. by adding a line: Msgbox "highLight_Selected function is executed".

If the msgbox shows, then try the next debugging measure:
instead of getRecentColors()(0) as value for rProps(0), you could temporarily pass a fixed RGB color ( for example RGB(100,255,100) ).

If that succeeds, then the problem is apparently in getRecentColors() [ No problem here tho…]

i found that getRecentColors()(0) is indeed unreliable; it seems that it only works after a color has already been selected via the toolbar button…

i have commented out that part for now, and put a fixed rgb value instead…

I’ll look into it later to see if there is a better way to retrieve the current color.

Hello @Orpheus,
i updated the function highLight_Selected() too … please see if it works now