Page 1 of 1
OfficeResourceLoader?
Posted: Wed Mar 06, 2019 12:00 am
by JeJe
I want to create a popup menu clone of the writer menubar as the menubar isn't available in full screen mode.
When retrieving the menu items with getUIConfigurationManager, the menu label property is given as an empty string for all items though.
I'm guessing the short description for the given menu commands (eg "Cut" for ".uno:cut") can be retrieved using the OfficeResourceLoader from the files in my OpenOffice's Resources folder.
Anyone know how to do this? I can't find any previous threads or information beyond:
https://www.openoffice.org/api/docs/com ... oader.html
I've got as far as
Code: Select all
res =createUnoService("com.sun.star.resource.OfficeResourceLoader")
'com.sun.star.resource.OfficeResourceLoader
'com.sun.star.resource.StringResource
'com.sun.star.resource.StringResourceWithLocation
'com.sun.star.resource.StringResourceWithStorage
'com.sun.star.resource.VclStringResourceLoader
bundle= res.loadBundle_Default("swen") 'swen-GB.res is one of the files.
msgbox bundle.haselements
.loadBundle_Default("swen") doesn't give an error. Nor does "s" or "sw". But other combinations of letters do.
And haselements gives 0.
Re: OfficeResourceLoader?
Posted: Wed Mar 06, 2019 11:28 am
by JeJe
Here's the unfinished code for cloning the menu. (I need to rewrite it to add submenus and so that clicking on menus other than the file one will return the correct command etc. etc.)
The label is the problem. I've used the commandURL instead as the property value returned is "".
Code: Select all
'In a writer module
dim menuset
sub getmenu
dim sts()
redim sts(0)
mbar=ThisComponent.CurrentController
'
aRect = CreateUnoStruct("com.sun.star.awt.Rectangle")
oPopup = CreateUnoService("stardiv.vcl.PopupMenu")
oPopup2 = CreateUnoService("stardiv.vcl.PopupMenu")
oModuleCfgMgrSupplier =createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager("com.sun.star.text.TextDocument")
menuset= oModuleCfgMgr.getSettings( "private:resource/menubar/menubar",true)
ImgMngr=oModuleCfgMgr.getimagemanager
BaseMenu = CreateUnoService("stardiv.vcl.PopupMenu")
redim popups(menuset.count -1)
for j = 0 to menuset.count -1
popups(j) = CreateUnoService("stardiv.vcl.PopupMenu")
propso= menuset.getbyindex(j)
for i = 0 to ubound(propso)
select case propso(i).name
case "CommandURL"
BaseMenu.insertItem(j, propso(i).value,0, j)'msgbox props(i).value
case "ItemDescriptorContainer"
id = propso(i).value
for c= 0 to id.getcount -1
props= id.getbyindex(c)
for p = 0 to ubound(props)
select case props(p).name
case "CommandURL"
commandurl= props(p).value
case "HelpURL"
case "Label"
label =props(p).value
case "Style"
style = props(p).value
case "Type"
ntype =props(p).value
case "ItemDescriptorContainer"
'id = props(i).value
issubmenu = true
end select
next
if ntype = 1 then
PopupS(j).insertSeparator(c)
else
PopupS(j).insertItem(cc, commandurl,0, c)
PopupS(j).setCommand(cc, commandurl)
if label <>"" then PopupS(j).setitemtext cc,label
if ImgMngr.hasimage(0,commandurl) then
sts(0)= commandurl
g= ImgMngr.getImages(0,sts)
Popups(j).setitemimage(cc,g(0),true)
end if
cc=cc+1
end if
commandurl =""
next
'popups(j).insertItem(c, commandurl,0, cc) ' =menuset.getbyindex(1)
end select
next
BaseMenu.setpopupmenu(j,popups(j))
next
n = BaseMenu.execute( thiscomponent.currentcontroller.frame.getContainerWindow(), aRect, com.sun.star.awt.PopupMenuDirection.EXECUTE_DEFAULT)
msgbox n
msgbox popups(0).getCommand(n)
if n= 0 then exit sub
dim 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
'dispatcher.executeDispatch(document, oPopup.getCommand(n), "", 0, args1())
end sub
Re: OfficeResourceLoader?
Posted: Wed Mar 06, 2019 8:35 pm
by hubert lambert
Hi,
You can get the menu item labels at the "/org.openoffice.Office.UI.WriterCommands/UserInterface/Commands" node of the registry:
Code: Select all
key = "/org.openoffice.Office.UI.CalcCommands/UserInterface/Commands"
reader = getConfigurationAccess(key)
commands = [(reader[x].Name, reader[x].Label.replace('~', '')) for x in reader.ElementNames]
Regards.
Re: OfficeResourceLoader?
Posted: Wed Mar 06, 2019 9:58 pm
by JeJe
Brilliant thanks! Looking into that I ended up with...
Code: Select all
'GetRegistryKeyContent function in the Oo Tools library
RKC= GetRegistryKeyContent("/org.openoffice.Office.UI.WriterCommands/UserInterface/Commands",FALSE)
lbl = RKC.getbyname(".uno:AcceptChange").getbyname("Label")
msgbox lbl '"Accept change"
Re: OfficeResourceLoader?
Posted: Thu Mar 07, 2019 2:00 pm
by JeJe
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