Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Outlook Add-In and Disabling/Hiding Custom Menu Items

I've created an Outlook Add-In, and I'm using an XML ribbon configuration file to specify a new tab, and button. The button loads into a new tab within outlook. Now sometimes, based on user we want to be able to hide or disable these buttons. What's the simplest way to disable a menu button on a custom tab through the Outlook Interop api?

My first guess is that I need to iterate through some command bar collections after my ribbon is created, and then search for my menu buttons, but I'm not sure where these collections are.

protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
{
    this.ribbon = new MyRibbon();

    // loop through tabs and ribbon items, look for my custom control, and enabled/disable specific buttons.

    return this.ribbon;
}
like image 387
mservidio Avatar asked Sep 16 '11 20:09

mservidio


People also ask

How do I stop Outlook from disabling add-ins?

Force Outlook to always enable the add-in: You can check this setting and reset it if necessary. On the File tab, click 'Manage COM Add-ins' under 'Slow and Disabled COM Add-ins'. You should then see a screen like the one below, select the 'Do not monitor this add-in for the next 30 days' and 'Close'.

How do I fix slow and disabled add-ins in Outlook?

Go to your Outlook and then click info, there you will see the option “Slow and Disabled COM Add-ins”. click it and then search for “DragDrop for Outlook” and then click “always enable this add-in” (Marked in red). After that restart Outlook and you are good to go.


1 Answers

Sorry to answer my own question. Finally figured it out. Within the xml configuration there is a getVisible callback for buttons/groups/tabs.

So all you need to do is add the callback in the xml, in my case I did it for a group:

<ribbon>
    <tabs>
      <tab idQ="myNs:myTab" label="My Label" >
          <group id="settingsGroup" label="Settings" getVisible="Control_Visible" >
              <button id="preferences" label="Preferences" image="configuration.png"
      screentip="Preferences" size="large" onAction="Settings_Click" supertip="Preferences" />
          </group>
      </tab>
    </tabs>
</ribbon>

and create a callback method

public bool Control_Visible(Office.IRibbonControl control)
{
    // In order to maintain a reference to the groups, I store the controls into a List<Office.IRibbonControl>.
    if(!this.groupControls.Contains(control))
    {
        this.groupControls.Add(control);
    }         

    // logic here to determine if it should return true or false to be visible...
    return true;
}

Then if during the use of outlook, you change the visibility setting of a button/tab/group, you need to call Invalidate() method on the ribbon so the ribbon redraws. IE:

this.ribbon.Invalidate();
like image 109
mservidio Avatar answered Sep 27 '22 15:09

mservidio