te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>Remove command from a toolbar with LibreOffice Basic - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Remove command from a toolbar with LibreOffice Basic - Stack Overflow

programmeradmin4浏览0评论

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
  • Does this answer your question: ask.libreoffice./t/…. Also, look through Andrew Pitonyak's macro document section 5.44 Toolbars. – Jim K Commented Feb 17 at 17:51
  • Thank you, Jim K. Not fully answered, but it pointed me in the right direction. I now have access to the element in the toolbar, but I can't find the right properties for 'Enabled' and 'Visible'. I can change the 'Label' (which means the 'Replace' works), but I can't set the element to 'disabled' and 'hidden'. – need2know Commented Feb 18 at 10:57
  • It sounds like you might be close. Edit the question to post example code that shows how to change the label. Have you tried an introspection tool such as MRI to see what properties are available? – Jim K Commented 2 days ago
  • I haven't tried the inspection tool yet. I would have to install it first. I tried using the Basic- IDE and ChatGPT, but without success so far. MRI is a good idea. Very helpful is Andrew Pitonyak's macro document. Thank you for the tips. – need2know Commented 2 days ago
  • Now the object 'oContext.getAccessibleChild' inspected with Xray. Very confused, even the property 'Label' is not present. – need2know Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 0

Following 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
发布评论

评论列表(0)

  1. 暂无评论