Writer macro to toggle sidebars

I’m looking for macro code to toggle sidebars open and closed.

I generally work with the navigator open on the left, and the style sidebar on the right. However, sometimes I want to close both to see the document larger, and then later open both up. I find the control/grab area on the sidebars too small to easily use, so closing and opening sidebars is a bit of a hassle. Not really difficult, but it takes a little while.

I’d like to use a macro to toggle the sidebars open and closed (both at once). However, recording the action in a macro doesn’t actually record anything. Does anyone know the macro commands I could use for this? Either to toggle the sidebars or to check their status and then open/close them as needed?

F5 toggles the Navigator, but I want to toggle both sidebars at once. I found this code for the navigator, but nothing yet for the other sidebar.

sub Navigator_on
    dim document   as object
    dim dispatcher as object
    dim args1(0) as new com.sun.star.beans.PropertyValue
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    args1(0).Name = "Navigator"
    args1(0).Value = true
    dispatcher.executeDispatch(document, ".uno:Navigator", "", 0, args1())
end sub

sub Navigator_off
    dim document   as object
    dim dispatcher as object
    dim args1(0) as new com.sun.star.beans.PropertyValue
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    args1(0).Name = "Navigator"
    args1(0).Value = false
    dispatcher.executeDispatch(document, ".uno:Navigator", "", 0, args1())
end sub

[From Apache OpenOffice Community Forum - [Solved] Macro to turn on the document navigator - (View topic)]

Ctrl+F5 toggles the sidebar and, as you know, F5 toggles Navigator. Ctrl+Shift+J toggles Full Screen (View > Full Screen). For me those are enough as I don’t do macros.

You can check the command for each in Tools > Customise > Keyboard by hovering over the function.

Thanks. I hadn’t known about either F5 or Ctrl+F5, or that I could see the commands by hovering in Customize>Keyboard. Lots of new info for me.

For Ctrl+F5 (no F11) the Macro recorder records the similar macro like for Navigator F5.
So then only some test if the Navigator window is visible.

Sub toggleNavigatorAndSidebar
	dim navigatorName$, tk as object, i%, topwindow as object, document as object, dispatcher as object
	document=ThisComponent.CurrentController.Frame

	dispatcher=createUnoService("com.sun.star.frame.DispatchHelper")
	dim args1(0) as new com.sun.star.beans.PropertyValue, args2(0) as new com.sun.star.beans.PropertyValue
		args1(0).Name="Navigator" : args1(0).Value=true
		args2(0).Name="Sidebar" : args2(0).Value=true

	rem source: https://forum.openoffice.org//en/forum/viewtopic.php?f=20&t=98738
	Globalscope.BasicLibraries.loadLibrary("Tools")
	navigatorName=GetRegistryKeyContent("org.openoffice.Office.UI.Sidebar/Content/PanelList/SwNavigatorPanel").Title
	tk=Stardesktop.CurrentFrame.ComponentWindow.Toolkit
	for i=0 to tk.TopWindowCount -1 'iterate all windows
		topwindow=tk.getTopWindow(i)
		if topwindow.AccessibleContext.AccessibleName=navigatorName then 'window is Navigator so Navigator is Visible
			args1(0).Value=false : args2(0).Value=false
			exit for
		end if
	next i
	dispatcher.executeDispatch(document,  ".uno:Navigator",  "",  0,  args1()) 'toggle Navigator
	dispatcher.executeDispatch(document, ".uno:Sidebar", "", 0, args2()) 'toggle Sidebar
End Sub

Thanks. I wasn’t aware of F11 either (lots of keyboard shortcuts still to learn for LO, apparently).

This macro works great to open Navigator and sidebar (sometimes*). It doesn’t close them when they’re open, but I presume I can include some sort of check on their condition to toggle the action. Research still to do.

  • it only works sometimes. Haven’t yet figured out why, but at least it’s a good base for me to learn and work from.