 | OO-Snippets: Create a toolbarCommons| Keywords | create, toolbar, runtime |
|---|
| Language | ooRexx |
|---|
| Application | Office |
|---|
| Authors | Josef Frysak (initial)
|
|---|
| Supported Versions | 2.4.1 |
|---|
| Supported OS | All |
|---|
| Question | How to create a toolbar at runtime?
|
|---|
| Answer | Use the "ModuleUIConfigurationManagerSupplier" service to get a document type specific user interface manager (for Writer, for Calc, ...). Next call the "createSettings" function to create a new toolbar. Now configurate the newly created toolbar, by using the properties of the newly created toolbar. For further details see http://wi.wu-wien.ac.at/rgf/diplomarbeiten/BakkStuff/2008/200809_Frysak/200809_Frysak_Automating_OOo_ooRexx_Nutshells.pdf. |
|---|
x_ScriptContext = uno.getScriptContext()
if (x_ScriptContext <> .nil) then
do
x_ComponentContext = x_ScriptContext~getComponentContext
x_Desktop = x_ScriptContext~getDesktop
x_Document = x_ScriptContext~getDocument
end
else
do
x_ComponentContext = UNO.connect()
service = "com.sun.star.frame.Desktop"
s_Desktop = x_ComponentContext~getServiceManager~XMultiServiceFactory~createInstance(service)
x_Desktop = s_Desktop~XDesktop
x_Document = x_Desktop~getCurrentComponent()
end
ToolbarURL = "private:resource/toolbar/custom_exampletoolbar"
x_MultiServiceFactory = x_ComponentContext~getServiceManager()~XMultiServiceFactory
configsupplier = "com.sun.star.ui.ModuleUIConfigurationManagerSupplier"
s_Supplier = x_MultiServiceFactory~createInstance(configsupplier)
x_Supplier = s_Supplier~XModuleUIConfigurationManagerSupplier
DocumentType = "com.sun.star.text.TextDocument"
x_UIConfigurationManager = x_Supplier~getUIConfigurationManager(DocumentType)
x_IndexContainer = x_UIConfigurationManager~createSettings()
x_Propertyset = x_IndexContainer~XPropertySet
x_Propertyset~setPropertyValue("UIName", "Bakk Statusbar")
DefaultButton = bsf.getConstant("com.sun.star.ui.ItemType", "DEFAULT")
toolbarbutton = uno.CreateArray(.UNO~PROPERTYVALUE, 4)
MacroURL = "vnd.sun.star.script:BakkMacros.w_CreateStyleCode.rex?language=ooRexx&location=user"
toolbarbutton[1] = uno.createProperty("CommandURL", MacroURL)
toolbarbutton[2] = uno.createProperty("Label", "Create Style: code")
toolbarbutton[3] = uno.createProperty("Type", DefaultButton)
toolbarbutton[4] = uno.createProperty("Visible", .true)
x_IndexContainer~insertByIndex(0, toolbarbutton)
MacroURL = "vnd.sun.star.script:BakkMacros.w_ImportCode.rex?language=ooRexx&location=user"
toolbarbutton[1] = uno.createProperty("CommandURL", MacroURL)
toolbarbutton[2] = uno.createProperty("Label", "Import Code from GVim")
toolbarbutton[3] = uno.createProperty("Type", DefaultButton)
toolbarbutton[4] = uno.createProperty("Visible", .true)
x_IndexContainer~insertByIndex(1, toolbarbutton)
If x_UIConfigurationManager~hasSettings(ToolbarURL) then
do
x_UIConfigurationManager~replaceSettings( ToolbarURL, x_IndexContainer )
end
else
do
x_UIConfigurationManager~insertSettings( ToolbarURL, x_IndexContainer )
end
::requires UNO.CLS
|
Changelog| Date | User | Modification |
|---|
| 2008-10-13 | 1 | Initial version |
|