Le 27 oct. 06, à 08:12, Carsten Driesner a écrit :
I wasn't able to run your example as I need a dedicated machine for
testing. Currently I only have remote access (with and therefore
cannot use a normal Office installation. That's why the script cannot
create the Office service manager. I hope that I can check your script
today, using a dedicated machine.
Hi Carsten,
I was a bit afraid that sending you a JScript sample would not
facilitate your job.
So I have tried my best translating it into OOBasic (using frequent
copy/paste from the samples you've sent to me !), and checked it. Here
is the result below.
Just try to execute the 'Main' sub first with 'false' as the 2nd
parameter of InsertMenu.
Then with 'true'.
In the 1st case, a menu line is appended to the writer "file" menu,
with a Ctrl+F11 key shortcut.
It is displayed, and works when one strokes Ctrl+F11 (a msgbox is then
showed).
In the 2nd case, the same line is put into a submenu, itself appended
to the "file" menu.
The key shortcut is still assigned, works, but is not displayed.
I hope you will see the same phenomenon.
Regards,
Julien Galand
_______________________________________________________________________
Sub Main
sMyCommand = "macro:///Standard.Module1.Test()"
' Set the 2nd parameter to 'true' to create a submenu in the "file"
menu.
' Set it to 'false' to create only a menu line in the "file" menu.
'
' In both cases, the final menu line is assigned a key shortcut (here
Ctrl+F11).
'
InsertMenu(sMyCommand, false)
InsertShortcut(sMyCommand)
End Sub
Sub InsertMenu(sCommand as String, bWithSubmenu as boolean)
sMenuBar = "private:resource/menubar/menubar"
sMyPopupMenuCmdId = ".uno:PickList"
REM *** Retrieve the current frame of my model
oModel = ThisComponent
if not isNull( oModel ) then
oFrame = oModel.getCurrentController().getFrame()
oLayoutManager = oFrame.LayoutManager()
oMenuBar = oLayoutManager.getElement( sMenuBar )
oMenuBarSettings = oMenuBar.getSettings( true )
oMenuBar.Persistent = false
fileMenuIndex = FindCommand( sMyPopupMenuCmdId, oMenuBarSettings )
if fileMenuIndex >= 0 then
oPopupMenuItem() = oMenuBarSettings.getByIndex(fileMenuIndex)
oPopupMenu = GetProperty( "ItemDescriptorContainer",
oPopupMenuItem() )
if not isNull( oPopupMenu ) then
'if FindCommand( sCommand, oPopupMenu ) = -1 then
oMenuItem = CreateMenuItem( sCommand,
"Standard.Module1.Test", null )
if bWithSubmenu then
oSubmenu =
oMenuBarSettings.createInstanceWithContext(GetDefaultContext())
oSubmenu.insertByIndex(0, oMenuItem)
oMenuItem = CreateMenuItem( "", "Standard.Module1.Test
submenu", oSubmenu)
endif
nCount = oPopupMenu.getCount()
oPopupMenu.insertByIndex( nCount, oMenuItem )
'endif
endif
else
msgbox "No file menu found!"
endif
oMenuBar.setSettings( oMenuBarSettings )
endif
End Sub
Function FindCommand( Command as String, oPopupMenu as Object ) as
Integer
nCount = oPopupMenu.getCount()-1
for i = 0 to nCount
oMenuItem() = oPopupMenu.getByIndex(i)
nPropertyCount = ubound(oMenuItem())
for j = 0 to nPropertyCount
if oMenuItem(j).Name = "CommandURL" then
if oMenuItem(j).Value = Command then
FindCommand = j
exit function
endif
endif
next j
next i
FindCommand = -1
End Function
Function GetProperty( PropertyName as String, properties() as Variant )
as Variant
for j = lbound( properties() ) to ubound( properties() )
oPropertyValue = properties(j)
if oPropertyValue.Name = PropertyName then
GetProperty = oPropertyValue.Value
exit function
endif
next j
GetProperty = null
end function
Function CreateMenuItem( Command as String, Label as String, oSubmenu
as Variant ) as Variant
Dim aMenuItem(2) as new com.sun.star.beans.PropertyValue
aMenuItem(0).Name = "CommandURL"
aMenuItem(0).Value = Command
aMenuItem(1).Name = "Label"
aMenuItem(1).Value = Label
aMenuItem(2).Name = "Type"
aMenuItem(2).Value = 0
if not isNull( oSubmenu ) then
redim preserve aMenuItem(3)
aMenuItem(3).Name = "ItemDescriptorContainer"
aMenuItem(3).Value = oSubmenu
endif
CreateMenuItem = aMenuItem()
End Function
Sub InsertShortcut(sCommand as String)
oModuleCfgMgrSupplier =
createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager(
"com.sun.star.text.TextDocument" )
oWriterAccelCfgmgr = oModuleCfgMgr.getShortCutManager()
Dim aKeyEvent as new com.sun.star.awt.KeyEvent
aKeyEvent.Modifiers = com.sun.star.awt.KeyModifier.MOD1
aKeyEvent.KeyCode = com.sun.star.awt.Key.F11
oWriterAccelCfgMgr.setKeyEvent( aKeyEvent, sCommand )
oWriterAccelCfgMgr.store()
End Sub
Sub Test
MsgBox "Test"
End Sub
_______________________________________________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]