I want to remove a command from a toolbar / set the command to inactive. I can open the dialog, but I can't go any furter.
sub SetStatusOfCommand
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ResourceURL"
args1(0).Value = "private:resource/toolbar/custom_toolbar_6925"
dispatcher.executeDispatch(document, ".uno:ConfigureDialog", "", 0, args1())
rem and now ...?
end sub
Thank you for any help!
I want to remove a command from a toolbar / set the command to inactive. I can open the dialog, but I can't go any furter.
sub SetStatusOfCommand
dim document as object
dim dispatcher as object
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ResourceURL"
args1(0).Value = "private:resource/toolbar/custom_toolbar_6925"
dispatcher.executeDispatch(document, ".uno:ConfigureDialog", "", 0, args1())
rem and now ...?
end sub
Thank you for any help!
Share Improve this question asked Feb 17 at 16:10 need2knowneed2know 112 bronze badges 5 |1 Answer
Reset to default 0Following Code is running: I have access to the element I want to modify. The properties 'Label' and 'CommandURL' are set and are visible and available in the toolbar-dialog. 'Visible' and 'Enabled' are also set (in the toolbar-object), but they have no effect in the dialog. See the last 2 lines.
Sub DisableCommandInToolbar REM here 'myCommand' in the toolbr 'myToolbar'
Dim uiSettings As Object
Dim moduleCfgMgr As Object
Dim i As Integer
Dim id As Integer
REM Access to the user interface settings
uiSettings = CreateUnoService("com.sun.star.ui.ModuleUIConfigurationManagerSupplier")
moduleCfgMgr = uiSettings.getUIConfigurationManager("com.sun.star.text.TextDocument")
REM Retrieve the list of all toolbars
oUIToolbarInfos = moduleCfgMgr.getUIElementsInfo(3) REM Load element information [3: toolbars. (1 = menu bars, 2 = context menus, 4 = status bars, 5 = floating windows)]
REM Find the index of the desired toolbar
REM there's no method like 'GetByName' so you have to find the index in a loop
For i = LBound(oUIToolbarInfos) to UBound(oUIToolbarInfos) REM Iterate through all element info (id will later hold the element ID)
OneToolbarInfo = oUIToolbarInfos(i) REM Current element info (also an array)
sToolbarURL = OneToolbarInfo(0).Value REM thomething like: 'private:resource/toolbar/custom_toolbar_fa3a5975'
sName = OneToolbarInfo(1).Value
if sName = "myToolbar" then
id = i REM Index of the 'myToolbar' toolbar
REM MsgBox "toolbar = " & " " & sToolbarURL & Chr(10) & "Item Index = " & " " & id
Exit For REM Stop searching once found
End if
Next i
Dim oLayoutMgr, TBar, oContext As Object
Dim ChildCount As Integer
Dim ChildName As String
Dim j As Integer
Dim CmdIdx As Integer
Dim sToolbarURLSettings as object
CmdIdx = -1
REM Find the index of the desired command
REM there's no method like 'GetByName' so you have to find the index in a loop
oLayoutMgr = ThisComponent.CurrentController.Frame.LayoutManager REM Get LayoutManager of the current document
TBar = oLayoutMgr.getElement(sToolbarURL) REM Retrieve the toolbar with the given URL (stored in sToolbarURL above)
If isNull(TBar) Then Exit Sub REM If the toolbar does not exist, exit the subroutine
oContext = TBar.getRealInterface().getAccessibleContext() REM Get the accessibility interface of the toolbar to access its elements
ChildCount = oContext.getAccessibleChildCount() REM Get the number of child elements (buttons, separators, etc.) in the toolbar
For j = 0 To ChildCount - 1 REM Loop through all elements in the toolbar
ChildName = oContext.getAccessibleChild(j).getAccessibleName() REM Get the name of the current toolbar element
If ChildName = "myCommand" Then REM if the element name matches the target command ...
CmdIdx = j REM ... Store the index of the found command ...
Exit For REM ... and exit the loop
End If
Next j
sToolbarURLSettings = moduleCfgMgr.getSettings(sToolbarURL, True) REM Retrieve the settings of the specified toolbar, allowing modifications (True = writable)
If CmdIdx <> -1 Then REM if Command exists
Dim newEntry(4) As New com.sun.star.beans.PropertyValue REM Create a new entry to set parameters
newEntry(0).Name = "CommandURL"
newEntry(0).Value = "vnd.sun.star.script:myLibrary.myModule.myCommand?language=Basic&location=application" REM The command itself
REM Set the label
newEntry(1).Name = "Label"
newEntry(1).Value = "myNewLabel" REM The visible name in the toolbar
REM Other supported types include SEPARATOR_LINE, SEPARATOR_SPACE, and SEPARATOR_LINEBREAK.
newEntry(2).Name = "Type"
newEntry(2).Value = com.sun.star.ui.ItemType.DEFAULT
REM Optional additional properties like 'Enabled', 'Visible'
newEntry(3).Name = "Enabled" REM ist set in the toolbar but has no effect
newEntry(3).Value = False REM True has no effect also. Same as string: "False", "True"
REM Make the command invisible
newEntry(4).Name = "Visible" REM ist set in the toolbar but has no effect
newEntry(4).Value = False REM True has no effect also. Same as string: "False", "True"
REM next 2 line are working also, "CommandURL" and "Label" are shown in the Toolbar. But "Enabled" and "Visible" has no effect.
sToolbarURLSettings.replaceByIndex(CmdIdx, newEntry) REM Replace ...
moduleCfgMgr.replaceSettings(sToolbarURL, sToolbarURLSettings) REM .... the element ...
End If
End Sub
5.44 Toolbars
. – Jim K Commented Feb 17 at 17:51