Fernand Vanrie wrote:
This same question landed in a wrong thread so i repeat:
Can a Document based custom_toolbar be copied or moved by the API, using
a basic macro ?
Hi Fernand,
Yes it's possible to do it using the ui configuration manager API.
Please have a look the following Basic macro which copies custom
toolbars from one document to another one.
Regards,
Carsten
Basic macro:
------------
REM ***** BASIC *****
Sub Main
REM *** Copies all custom toolbars located in one document to
another one
REM *** A custom toolbar name MUST start with "custom_"
sCustomToolbar = "private:resource/toolbar/custom_"
REM *** Retrieve the desktop service ***
oDesktop = createUnoService( "com.sun.star.frame.Desktop" )
REM *** Propterties for loadComponentFromUrl ***
Dim OpenProperties(3) as new com.sun.star.beans.PropertyValue
OpenProperties(0).Name = "Hidden"
OpenProperties(0).Value = True
OpenProperties(1).Name = "AsTemplate"
OpenProperties(1).Value = False
OpenProperties(2).Name = "MacroExecutionMode"
OpenProperties(2).Value =
com.sun.star.document.MacroExecMode.NEVER_EXECUTE
REM *** Load two documents ***
sSourceUrl = "file:///c:/document1.odt"
sTargetUrl = "file:///c:/document2.odt"
oDoc1 = oDesktop.loadComponentFromUrl(sSourceUrl, "_default", 0,
OpenProperties())
oDoc2 = oDesktop.loadComponentFromUrl(sTargetUrl, "_default", 0,
OpenProperties())
oSourceUICfgMgr = oDoc1.getUIConfigurationManager()
oTargetUICfgMgr = oDoc2.getUIConfigurationManager()
REM *** Type number for the toolbar, retrieved from
com.sun.star.ui.UIElementType
TOOLBAR_TYPE = 3
oToolbars() = oSourceUICfgMgr.getUIElementsInfo( TOOLBAR_TYPE )
msgbox oSourceUICfgMgr.dbg_supportedInterfaces
REM *** Retrieve all toolbars stored in the document ***
bCopied = false
nMaxTbxIndex = ubound( oToolbars() )
for i = 0 to nMaxTbxIndex
oToolbarPropsSeq = oToolbars(i)
nMaxToolbarPropIndex = ubound( oToolbarPropsSeq )
for j = 0 to nMaxToolbarPropIndex
oToolbarProps = oToolbarPropsSeq(j)
if oToolbarProps.Name = "ResourceURL" then
if InStr( oToolbarProps.Value, sCustomToolbar ) = 1 then
msgbox oToolbarProps.Value
REM *** Retrieve the toolbar settings from the
REM *** source document ui configuration manager
oToolbar = oSourceUICfgMgr.getSettings(
oToolbarProps.Value, False )
REM *** Insert/replace the toolbar settings to the
target document
REM *** ui configuration manager.
if oTargetUICfgMgr.hasSettings( oToolbarProps.Value )
then
oTargetUICfgMgr.replaceSettings(
oToolbarProps.Value, oToolbar )
else
oTargetUICfgMgr.insertSettings( oToolbarProps.Value,
oToolbar )
endif
end if
bCopied = true
end if
next j
next i
REM *** Store the changes to the document
if bCopied = true then
oTargetUICfgMgr.store()
oDoc2.store()
end if
oDoc1.close( true )
oDoc2.close( true )
End Sub
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]