Is there a built in function in ADX for disabling ribbon controls?

Add-in Express™ Support Service
That's what is more important than anything else

Is there a built in function in ADX for disabling ribbon controls?
 
Niels Ziegler


Guest


When I close the last document in Word 2010, my custom ADX Ribbon can still be clicked which leads to errors. The default ribbon controls that are document based get disabled in this case. Is there a built in way to achive the same result?

I tried to disable the controls through the group box, but the group does not offer any "enabled" property. Now I have to handle the document open and closing events and check if it's the last document that is being closed, then cycle through all controls in the group and cast them to buttons. Is there another way?

 foreach (ADXRibbonCustomControl c in controls)
            {
                switch (c.GetType().ToString())
                {
                    case "AddinExpress.MSO.ADXRibbonButton":
                        ((ADXRibbonButton)c).Enabled = false;
                        break;
                    case "AddinExpress.MSO.ADXRibbonGallery":
                        ((ADXRibbonGallery)c).Enabled = false;
                        break;
                    default:
                        break;
                }


            }
Posted 23 Feb, 2017 11:53:26 Top
nwein




Posts: 577
Joined: 2011-03-28
That's a great question Niels, I just swallowed this limitation and built various overloaded methods to show/hide and enable/disable all variances of ADX controls.
It would have helped if all controls were derived from a based class or interface so that we it wouldn't require overloading each control separately.
E.g.
private static void HideAndDisable(ADXRibbonGroup control, bool hide)
{
	control.Visible = !hide;
}

private static void HideAndDisable(ADXRibbonSeparator control, bool hide)
{
	control.Visible = !hide;
}

private static void HideAndDisable(ADXRibbonButton control, bool hide)
{
	control.Visible = !hide;
	control.Enabled = !hide;
}

private static void HideAndDisable(ADXRibbonSplitButton control, bool hide)
{
	control.Visible = !hide;
	control.Enabled = !hide;
}

private static void HideAndDisable(ADXRibbonMenu control, bool hide)
{
	control.Visible = !hide;
	control.Enabled = !hide;
}

private static void HideAndDisable(ADXRibbonCheckBox control, bool hide)
{
	control.Visible = !hide;
	control.Enabled = !hide;
}
Posted 23 Feb, 2017 12:05:09 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Niels and Nir,

Would this method do?

DisableControl(this.adxRibbonTab1.AsRibbon);

private void DisableControl(IADXRibbonComponent adxRibbonComponent) {
    System.Diagnostics.Debug.WriteLine("!!! " + adxRibbonComponent.Caption + " (" + adxRibbonComponent.XmlType + ")");
    if (adxRibbonComponent.Controls != null) {
        foreach (IADXRibbonComponent ctrl in adxRibbonComponent.Controls) {
            DisableControl(ctrl);
        }
    }
    adxRibbonComponent.Enabled = false;
}



Andrei Smolin
Add-in Express Team Leader
Posted 24 Feb, 2017 07:48:57 Top
nwein




Posts: 577
Joined: 2011-03-28
Thanks Andrei, it sure helped me.
Posted 24 Feb, 2017 10:07:16 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
You are always welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 24 Feb, 2017 10:33:59 Top
Niels Ziegler


Guest


Yes, it works great and reduced the method calls to just one line because previously I started at the RibbonBox level and now I use the RibbonTab.
Posted 27 Feb, 2017 05:40:59 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Great!


Andrei Smolin
Add-in Express Team Leader
Posted 27 Feb, 2017 06:10:49 Top