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

Question

Question

Removing custom toolbar button with SDK leaves an "empty space" in the toolbar

SDK
asked on January 5, 2016 Show version history

I am working on a project that installs a small utility program and creates a custom toolbar button in Laserfiche to launch it. During uninstall, it also attempts to remove the toolbar button. It appears to succeed in removing the button, but leaves behind an empty space on the toolbar as in the picture below:

You can just drag it off of the toolbar, but I'd prefer if it removed the button cleanly. Here is the code I am using... am I forgetting a step?

using (ClientManager lfclient = new ClientManager())
{
  using (ToolbarManager tbMgr = lfclient.GetToolbarManager(ClientWindowType.Main))
  {
    int i = 0;
    while (i < tbMgr.GetCustomToolbarButtonCount())
    {
      btnInfo = tbMgr.GetCustomToolbarButton(i);
      if (btnInfo.Description == "My_Button_Name")
      {
        tbMgr.RemoveCustomToolbarButton(i);
      }
      else
      {
        i++;
      }
    }
  }
}

 

0 0

Answer

SELECTED ANSWER
replied on January 5, 2016 Show version history

RemoveCustomToolbarButton removes the button definition (not the button itself on the toolbar), leaving a "dangling" button on the toolbar. First remove the button from the toolbar(s), then delete the definition:

using (ToolbarManager tbMgr = lfclient.GetToolbarManager(ClientWindowType.Main))
{
    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;
    }

    // Remove the button from all toolbars
    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)
                tbMgr.RemoveButton(strToolbar, buttonInfo.Id);
        }
    }

    // Remove the custom button definition
    int i = 0;
    while (i < tbMgr.GetCustomToolbarButtonCount())
    {
        CustomButtonInfo btnInfo = tbMgr.GetCustomToolbarButton(i);
        if (btnInfo.Description == "My_Button_Name")
        {
            tbMgr.RemoveCustomToolbarButton(i);
        }
        else
        {
            i++;
        }
    }
}

 

1 0
replied on January 5, 2016 Show version history

Thanks for the clarification, that did the trick. (Also... I assumed that your if statement on line 21 was supposed to be "buttonInfo.Id == customButtonId")

0 0
replied on January 5, 2016

Oops, thanks. i updated the snippet.

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.