You are viewing limited content. For full access, please sign in.

Question

Question

CAT: Duplicate Toolbar Buttons

SDK
asked on March 8, 2016 Show version history

First off, CAT's `ToolbarManager` is sweet! Being able to automate the adding of custom buttons to a user's toolbar with the simple double-click of an .exe is a game-changer!

Quick question...

It seems not possible to fully prevent duplicate custom buttons from being added to the toolbar via CAT.

For example, check out Slide 26 of the Laserfiche Empower EDM213 presentation. From what I can tell, that code iterates over the number of custom toolbar buttons that have been added here, not the number of custom toolbar buttons that have actually been dragged/dropped onto to the toolbar. Is that accurate?

If so, running the CAT application twice in a row causes the custom toolbar button in question to appear twice on the toolbar. That's also the behavior that I'm seeing on my end.

This is definetley not a major issue, I just wanted to see if it was programatically avoidable. Thanks!

0 0

Answer

SELECTED ANSWER
replied on March 9, 2016

you can find the buttons that have been added to each toolbar by calling ToolbarManager.GetButtonInfo(toolbarName, index). Here is sample code that looks for the button named My_Button_Name and checks every MainWindow toolbar for it:

ClientWindowType windowType = ClientWindowType.Main;

using (ToolbarManager tbMgr = lfclient.GetToolbarManager(windowType))
{
    int customButtonId = -1;

    // Find the ID of the custom button
    for (int k = 0; k < tbMgr.GetCustomToolbarButtonCount(); k++)
    {
        CustomButtonInfo customButtonDefinition = tbMgr.GetCustomToolbarButton(k);
        if (customButtonDefinition.Description == "My_Button_Name")
            customButtonId = customButtonDefinition.Id;
    }

    if (customButtonId != -1)
    {
        // Custom button definition found, now check if it is on any toolbars

        bool buttonExistsOnToolbar = false;

        // Iterate over all toolbars on MainWindow and check for the button
        int nToolbarCount = tbMgr.GetToolbarCount();
        for (int n = 0; n < nToolbarCount; n++)
        {
            string strToolbar = tbMgr.GetToolbarName(n);
            for (int j = 0; j < tbMgr.GetButtonCount(strToolbar); j++)
            {
                ToolbarButtonInfo buttonInfo = tbMgr.GetButtonInfo(strToolbar, j);
                if (buttonInfo.Id == customButtonId)
                {
                    // found the button on the toolbar with name strToolbar
                    buttonExistsOnToolbar = true;
                }
            }
        }

        if (!buttonExistsOnToolbar)
        {
            // Now add the button since it does not exist on any toolbar
        }
    }
}

 

1 0
replied on March 9, 2016

This is perfect! Thanks!

0 0
replied on March 18, 2016 Show version history

Hey Robbie! Quick follow-up question...

I've implemented your code above, and it works great. It completely prevents duplicates.

Out of curiosity though, whenever I call `GetButtonCount()` and `MsgBox()` the result, the count that I get never matches what I get myself from manually counting buttons on the toolbar in question (I'm sure that I'm making this call on the correct window/toolbar). The count that `GetButtonCount()` returns is always lower than what I count with my own eyes. I've tried experimenting with this a bit by adding/removing buttons and seeing the effect, but I can't quite track down the discrepancy. Any ideas?

In case it helps, here's a screenshot:

 

 

The message box is being thrown using the following code:

Using lfclient As New ClientManager()

    Dim windowTypes As New List(Of ClientWindowType)()
    windowTypes.Add(ClientWindowType.Main)
    windowTypes.Add(ClientWindowType.DocumentViewer)

    For Each windowtype As ClientWindowType In windowTypes

        Using toolbarmgr As ToolbarManager = lfclient.GetToolbarManager(windowtype)

            Dim toolbarCount As Integer = toolbarmgr.GetToolbarCount()
            For i As Integer = 1 To toolbarCount

                Dim toolbarName As String = toolbarmgr.GetToolbarName(i - 1)
                Dim buttonCount As Integer = toolbarmgr.GetButtonCount(toolbarName)
                MsgBox(windowtype.ToString & " - " & toolbarName & " - " & buttonCount)

            Next

        End Using

    Next

End Using

As you can see in the screenshot, five toolbar buttons are on the toolbar, but `GetButtonCount()` returns only three.

Again, none of this seems to be affecting my CAT application's ability to do its job -- I'm just generally curious. Thanks!

0 0
replied on March 19, 2016

Some of the buttons are special (Go Back, Go Forward, Export, View Style) and aren't returned in the button list. This actually might be a bug, but like you say I don't think it is affecting anyone.

1 0
replied on March 21, 2016

Gotcha. Thanks!

0 0

Replies

You are not allowed to reply in this post.
You are not allowed to follow up in this post.

Sign in to reply to this post.