Unfortunately the submenus aren't accessible with the above code - and some of them are dynamic - so its going to be more of a semi-clone with some submenu omissions.
That's again for the help - that got me there.
In case anyone wants this, here's some code to create an example menu from a list of of CommandURLs (the Insert/Fields submenu)
Code: Select all
'in a writer module
sub tst()
msgbox CommandURLsToMenu( ".uno:InsertDateField|.uno:InsertTimeField|.uno:InsertPageNumberField|.uno:InsertPageCountField|.uno:InsertTopicField|.uno:InsertTitleField|.uno:InsertAuthorField|_|.uno:InsertField","|")
end sub
function CommandURLsToMenu(st as string,separator)
dim sts() as string,c as long,ims
redim ims(0)
oModuleCfgMgrSupplier =createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.text.TextDocument")
ImgMngr=oModuleCfgMgr.getimagemanager
oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
RkcW= GetRegistryKeyContentn("/org.openoffice.Office.UI.WriterCommands/UserInterface/Commands",FALSE)
RkcG= GetRegistryKeyContentn("/org.openoffice.Office.UI.GenericCommands/UserInterface/Commands",FALSE)
oPopup = CreateUnoService("stardiv.vcl.PopupMenu")
sts = split(st,separator)
for i = 0 to ubound(sts)
commandurl = sts(i)
with opopup
c =c+1
if sts(i) ="_" then
oPopup.insertSeparator(c)
else
if RKCW.hasbyname(commandurl) then
lbl= RKCW.getbyname(commandurl).getbyname("Label")
elseif RKCG.hasbyname(commandurl) then
lbl= RKCG.getbyname(commandurl).getbyname("Label")
else
lbl = commandurl
end if
oPopup.insertItem(c, lbl,0, c)
' oPopup.RADIOCHECK = true
' oPopup.checkitem(c,true)
.setCommand(c, commandurl)
if ImgMngr.hasimage(0,commandurl) then
ims(0)= commandurl
g= ImgMngr.getImages(0,ims)
.setitemimage(c,g(0),true)
end if
end if
end with
next
aRect = CreateUnoStruct("com.sun.star.awt.Rectangle")
n = oPopup.execute( thiscomponent.currentcontroller.frame.getContainerWindow(), aRect, com.sun.star.awt.PopupMenuDirection.EXECUTE_DEFAULT)
If n > 0 Then
CommandURLsToMenu = oPopup.getCommand(n)
end if
end function
'below function from the OO installation Tools Library. Just added an "n" to the name
Function GetRegistryKeyContentn(sKeyName as string, Optional bforUpdate as Boolean)
Dim oConfigProvider as Object
Dim aNodePath(0) as new com.sun.star.beans.PropertyValue
oConfigProvider = createUnoService("com.sun.star.configuration.ConfigurationProvider")
aNodePath(0).Name = "nodepath"
aNodePath(0).Value = sKeyName
If IsMissing(bForUpdate) Then
GetRegistryKeyContent() = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath())
Else
If bForUpdate Then
GetRegistryKeyContentn() = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationUpdateAccess", aNodePath())
Else
GetRegistryKeyContentn() = oConfigProvider.createInstanceWithArguments("com.sun.star.configuration.ConfigurationAccess", aNodePath())
End If
End If
End Function