Starting in December, we will archive content from the community that is 10 years and older. This FAQ provides more information.
Hi, I'm in the development process of a modular plugin solution where all the buttons are under the same
Ribbon tab but the construction of the Ribbon Panels under this common tab is being done for each module.
Meaning a user may choose to have different combinations of function which I can't predict so naturally
the code assumes it has to create this common tab because the modules aren't "aware" of each other.
The problem is, I can't find a way to check if the tab name is already exists, I can check for panels using:
GetRibbonPanels(string tabName)
I was hoping that calling for panels in a tab which doesn't exists, will return nothing but it throws an exception...
I tried using same name to check if the .CreateRebbonTab() will just ignore it, but is also throws an exception...
I could use try-catch statement but this is typically last resort and overall wrong approach in my opinion
try
{
application.CreateRibbonTab("AdvTools");
}
catch(Exception)
{
//do nothing
}
Are there any decent work-arounds for this situation ?
Solved! Go to Solution.
Solved by jeremy_tammik. Go to Solution.
This article shares code to read all ribbon panel titles safely:
https://thebuildingcoder.typepad.com/blog/2011/03/ribbon-panel-title-conflict.html
I hope this helps.
Best regards,
Jeremy
I see, so currently the only way to do this is using a private method which will iterate over all the tab names
and return an indicator if it is safe or not to call .CareateRibbonTab()
Well, maybe not the only way, just one possibility. There may be others, and some may be better. Who knows?
To create the RibbonTab that's the way to do it, using a try, to guarantee that the RibbonTab gonna be created.
To create the RibbonPanel you gonna need to search and maybe return the existent panel so you could add other buttons in the existent panel.
Using some extensions like:
public static RibbonPanel CreateOrSelectRibbonPanel(this UIControlledApplication application, string tabName, string panelName)
{
if (application.GetRibbonPanels(tabName).FirstOrDefault(p => p.Name == panelName) is RibbonPanel ribbonPanel)
return ribbonPanel;
return application.CreateRibbonPanel(tabName, panelName);
}
Can't find what you're looking for? Ask the community or share your knowledge.