Single key to toggle show/hide changes

In LO Writer, I’d like to be able to switch between Hide Changes and Show Changes with a single keystroke. I had no trouble adding a button for this to the Edit toolbar, but I can’t find a way to customize the keyboard to assign this function to a single key. I’ve also tried recording a macro for this purpose, but it only works in one direction: it will hide or show, but not toggle back and forth.

Emboldened by a bit of VB.Net experience, I tried tinkering with the VBA code, for example replacing:

args1(0).Value = true

by

args1(0).Value = not args1(0).Value

which threw an error. Then I tried using a VB.Net-style If…Else…End If statement but that simply had no effect.

Can anyone tell me a way to toggle Show.Hide with a single custom key?

Vic

The args1 variable does not know any nothing about the document. It is freshly created. To be able to toggle the state with respect to any property, you need either access to the property itself or a method accessing it. As I do not know a path to the needed information, I have to create a global Boolean variable and to toggle its value every time the Sub made for toggling the state is called. Using my global variable to set Args1(1), the uno command called by the dispatcher will also toggle the addressed property.

(Editing. Addendum. Rectification)
(That the args variables used by uno commands neither do remember a previous setting nor do know anything about the document’s state remains true!)

My previously published solution and the example were based on the assumption that the uno command ‘ShowTrackedChanges’ was named “unmisguiding” and actually evaluates the args parameter. Playing with the solution the OQ posted in his self-answer I found that this is not the case.
The args parameter is treated by “.uno:ShowTrackedChanges” as a dummy without any evaluation. The mentioned uno command itself is toggling the state and thus should better be named ‘ToggleShowingTrackedChanges’.

Code to achieve the task is therefore very simple:

sub ShowHideChanges
dim document   as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
REM Needed only to fill a syntactically mandatory parameter place:
dim args1(0) as new com.sun.star.beans.PropertyValue 

dispatcher.executeDispatch(document, ".uno:ShowTrackedChanges", "", 0, args1())

end sub

I removed the code based on my misunderstanding.

Thank you for your answer Lupp. I assumed I would get notification of your reply so I hadn’t seen it yet. Anyway, I just managed to get my own macro working and, feeling a little proud of myself, returned to the forum to post my solution. I had tried toggling the Value field, which is what your code does but for some reason didn’t work for me (probably a bit of VB.Net syntax which threw a less than informative error). When I tried changing the Name field instead it worked fine. For what it’s worth, here’s my version:

sub ShowHideChanges
dim document   as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Value = True
if args1(0).Name = "HideTrackedChanges" then
   args1(0).Name = "ShowTrackedChanges"
else
   args1(0).Name = "HideTrackedChanges"
end if
dispatcher.executeDispatch(document, ".uno:ShowTrackedChanges", "", 0, args1())
end sub

I haven’t worried about the initializing args(0) as in your code so I’ll have to see how it behaves in a new LO session. Meanwhile I can get on with my mucky text editing which is about to crash into a deadline!

regards, Vic

(Code block edited for better readability. Lupp)

sorry Lupp, I should have responded to your reply instead of answering my own question. Not sure how to change that.

Don’t worry. Answering an own question is well approved for this forum. What you included in your answer would exceed the maximum siz of a comment anyway.
Concerning your solution you will find an addendum to my answer.