Alexander O. Anisimov wrote:
Hi,
I need to save UI in *.odt file (like OOo do it) from external
application.
In OOo there is customize dialog (View -> Toolbars -> Customize...).
In it I
configure toolbars and menu item, and then save it in my document.
Then I could load this document and I would have only that toolbars and
menu items which I customize in dialog.
How could I do such thing from external application?
Can someone provide any pointers. Any help will be highly appreciated.
I've implemented the application in Java and I am using OO 3.1
Hi Alexander,
I am not sure what you want to do. Do you want to use OOo from your
external application to write the data or do you want to write the XML
data with your external application? For the first scenario you need to
use the UI configuration manger UNO API. I am not aware of any code that
is available which suits the second scenario. You have to write your own
code to create the necessary structures/files within the dcoument
archive. You can find the UI configuration XML data in the sub folder
"Configurations2".
For the first scenario you can adapt the following sample in Basic:
REM ***** BASIC *****
REM *** Modifies the standard toolbar of the Writer and stores it to a
text document
Sub Main
REM *** Define the name of the standard toolbar
sStandardToolbar = "private:resource/toolbar/standardbar"
REM *** Define macro URL for this small test
sMyToolbarCmdId = "macro:///Standard.Module1.Test()"
REM *** Retrieve the desktop service ***
oDesktop = createUnoService( "com.sun.star.frame.Desktop" )
REM *** Retrieve the module configuration manager from central
module configuration manager supplier
oModuleCfgMgrSupplier =
createUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
REM *** Retrieve the module configuration manager with module identifier
REM *** See com.sun.star.frame.ModuleManager for more information
oModuleCfgMgr = oModuleCfgMgrSupplier.getUIConfigurationManager(
"com.sun.star.text.TextDocument" )
REM *** Retrieve the standard toolbar settings from the Writer module
oStandardBarSettings = oModuleCfgMgr.getSettings( sStandardToolbar,
true )
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 ***
sDocumentUrl = "file:///d:/document.odt"
oDoc = oDesktop.loadComponentFromUrl(sDocumentUrl, "_default", 0,
OpenProperties())
bHasSettings = false
oUICfgMgr = oDoc.getUIConfigurationManager()
if oUICfgMgr.hasSettings( sStandardToolbar ) then
bHasSettings = true
end if
REM *** Look for our button. Can be identified by the CommandURL
property.
bHasAlreadyButton = false
nCount = oStandardBarSettings.getCount()
for i = 0 to nCount-1
oToolbarButton() = oStandardBarSettings.getByIndex( i )
nToolbarButtonCount = ubound(oToolbarButton())
for j = 0 to nToolbarButtonCount
if oToolbarButton(j).Name = "CommandURL" then
if oToolbarButton(j).Value = sMyToolbarCmdId then
bHasAlreadyButton = true
end if
endif
next j
next i
MsgBox bHasAlreadyButton
if not bHasAlreadyButton then
oToolbarItem = CreateToolbarItem( sMyToolbarCmdId,
"Standard.Module1.Test" )
oStandardBarSettings.insertByIndex( nCount, oToolbarItem )
if bHasSettings then
oUICfgMgr.replaceSettings( sStandardToolbar,
oStandardBarSettings )
else
oUICfgMgr.insertSettings( sStandardToolbar,
oStandardBarSettings )
end if
end if
REM *** Store the changes to the document
oUICfgMgr.store()
oDoc.store()
oDoc.close( true )
End Sub
Function CreateToolbarItem( Command as String, Label as String ) as Variant
Dim aToolbarItem(3) as new com.sun.star.beans.PropertyValue
aToolbarItem(0).Name = "CommandURL"
aToolbarItem(0).Value = Command
aToolbarItem(1).Name = "Label"
aToolbarItem(1).Value = Label
aToolbarItem(2).Name = "Type"
aToolbarItem(2).Value = 0
aToolbarItem(3).Name = "Visible"
aToolbarItem(3).Value = true
CreateToolbarItem = aToolbarItem()
End Function
Sub Test
MsgBox "Test"
End Sub
Regards,
Carsten
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@api.openoffice.org
For additional commands, e-mail: dev-h...@api.openoffice.org