Packages - Display Based Upon User Role
Moderator: Phil Barton
Packages - Display Based Upon User Role
Is there any way to turn off a top level tab (in a user developed package) based upon a user's profile? I have a tab that should only be visible for administrative users. I considered just setting the contents of the screen to be invisible, but I would rather not display the tab at all.
Thanks,
Thanks,
Robert
Re: Packages - Display Based Upon User Role
Yes, you can switch off a ribbon tab much like you would disable a ribbon button.
Referring to the default package that gets created when choosing the SoftPro Template in Visual Studio, here is how you achieve that:
1. in the package .ctd (command table) file, add the dynamic style attribute to the ribbon tab menu entry,
2. in the OnInitialize() method of the package class, register a query status handler for the ribbon tab,
3. implement your query status handler,
Note that once the tab is made invisible, it cannot be dynamically restored at runtime.
Referring to the default package that gets created when choosing the SoftPro Template in Visual Studio, here is how you achieve that:
1. in the package .ctd (command table) file, add the dynamic style attribute to the ribbon tab menu entry,
Code: Select all
<Menu id="RibbonTab1" priority="10" text="RibbonTab1" style="Dynamic">
Code: Select all
base.RegisterHandler(MyPackage.RibbonTab1, null, this.RibbonTab1_QueryStatus);
Code: Select all
private void RibbonTab1_QueryStatus(object sender, EventArgs e)
{
Command cmd = (Command)sender;
cmd.Visible = false; // Here, write up the logic that determines the tab visibility.
base.UnregisterHandler(MyPackage.RibbonTab1, null, this.RibbonTab1_QueryStatus);
}
Re: Packages - Display Based Upon User Role
Could you accomplish the same thing with:Hadi Chemaly wrote:Yes, you can switch off a ribbon tab much like you would disable a ribbon button.
Referring to the default package that gets created when choosing the SoftPro Template in Visual Studio, here is how you achieve that:
1. in the package .ctd (command table) file, add the dynamic style attribute to the ribbon tab menu entry,2. in the OnInitialize() method of the package class, register a query status handler for the ribbon tab,Code: Select all
<Menu id="RibbonTab1" priority="10" text="RibbonTab1" style="Dynamic">
3. implement your query status handler,Code: Select all
base.RegisterHandler(MyPackage.RibbonTab1, null, this.RibbonTab1_QueryStatus);
Note that once the tab is made invisible, it cannot be dynamically restored at runtime.Code: Select all
private void RibbonTab1_QueryStatus(object sender, EventArgs e) { Command cmd = (Command)sender; cmd.Visible = false; // Here, write up the logic that determines the tab visibility. base.UnregisterHandler(MyPackage.RibbonTab1, null, this.RibbonTab1_QueryStatus); }
Code: Select all
base.CommandManager.RemoveCommand((Command)sender);
Robert
Re: Packages - Display Based Upon User Role
I don't advise to use the RemoveCommand() as it can leave the system in a vulnerable state if that same command is invoked somewhere else. UnregisterHandler() is really what you need.roteague wrote:Could you accomplish the same thing with:
Code: Select all
base.CommandManager.RemoveCommand((Command)sender);
In fact RemoveCommand() is going to be deprecated from the ICommandManager interface in a future release, as it was not meant to be publicly exposed.
Re: Packages - Display Based Upon User Role
Thanks Hadi, I'll keep that in mind.Hadi Chemaly wrote:I don't advise to use the RemoveCommand() as it can leave the system in a vulnerable state if that same command is invoked somewhere else. UnregisterHandler() is really what you need.roteague wrote:Could you accomplish the same thing with:
Code: Select all
base.CommandManager.RemoveCommand((Command)sender);
In fact RemoveCommand() is going to be deprecated from the ICommandManager interface in a future release, as it was not meant to be publicly exposed.
Robert
Re: Packages - Display Based Upon User Role
I'm trying to do something similar to this, but instead of a Tab, I'm trying to use a Group. Since group doesn't allow style="Dynamic" is it possible to turn off a group the same way that a Tab (Menu) would be turned off? If not, it there another way around this?
Thanks,
Thanks,
Robert
Re: Packages - Display Based Upon User Role
A <Group> is more of an abstract concept used to define how the underlying concrete element(s) is/are grouped, such as vertically, horizontally, order of appearance, etc. As you have determined, visibility does not apply to groups.
Currently, the only concrete elements where visibility can be played with are ribbon tabs (which are the top-most <Menu> entry following a shell:RibbonMenu reference (i.e. <MenuRef>)) and leaf commands (e.g. <Button>). Ribbon tabs can only be turned on/off whereas leaf commands can only be enabled/disabled.
Typically you would want to be toggling the visibility of concrete <Menu> elements that fall between ribbon tab definitions and leaf command definitions, but unfortunately these are not supported at this time. You can choose to set the visibility of all buttons in your group by enabling/disabling them.
Currently, the only concrete elements where visibility can be played with are ribbon tabs (which are the top-most <Menu> entry following a shell:RibbonMenu reference (i.e. <MenuRef>)) and leaf commands (e.g. <Button>). Ribbon tabs can only be turned on/off whereas leaf commands can only be enabled/disabled.
Typically you would want to be toggling the visibility of concrete <Menu> elements that fall between ribbon tab definitions and leaf command definitions, but unfortunately these are not supported at this time. You can choose to set the visibility of all buttons in your group by enabling/disabling them.
Re: Packages - Display Based Upon User Role
Any idea if this functionality will be included in future builds? Our preferred solution is to keep with the SoftPro/Office UI convention where possible.
BTW, I should have said "Menu" not "Group". This is what I want to turn on/off. I already have the program set to turn off a tab.
BTW, I should have said "Menu" not "Group". This is what I want to turn on/off. I already have the program set to turn off a tab.
Robert