Packages - Display Based Upon User Role

Discussions related to SoftPro Select user interface development.

Moderator: Phil Barton

Post Reply
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Packages - Display Based Upon User Role

Post by roteague »

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,
Robert
Hadi Chemaly

Re: Packages - Display Based Upon User Role

Post by Hadi Chemaly »

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,

Code: Select all

<Menu id="RibbonTab1" priority="10" text="RibbonTab1" style="Dynamic">
2. in the OnInitialize() method of the package class, register a query status handler for the ribbon tab,

Code: Select all

base.RegisterHandler(MyPackage.RibbonTab1, null, this.RibbonTab1_QueryStatus);
3. implement your query status handler,

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);
}
Note that once the tab is made invisible, it cannot be dynamically restored at runtime.
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: Packages - Display Based Upon User Role

Post by roteague »

Thanks Hadi, that is what I'm looking for.
Robert
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: Packages - Display Based Upon User Role

Post by roteague »

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,

Code: Select all

<Menu id="RibbonTab1" priority="10" text="RibbonTab1" style="Dynamic">
2. in the OnInitialize() method of the package class, register a query status handler for the ribbon tab,

Code: Select all

base.RegisterHandler(MyPackage.RibbonTab1, null, this.RibbonTab1_QueryStatus);
3. implement your query status handler,

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);
}
Note that once the tab is made invisible, it cannot be dynamically restored at runtime.
Could you accomplish the same thing with:

Code: Select all

base.CommandManager.RemoveCommand((Command)sender);
Robert
Hadi Chemaly

Re: Packages - Display Based Upon User Role

Post by Hadi Chemaly »

roteague wrote:Could you accomplish the same thing with:

Code: Select all

base.CommandManager.RemoveCommand((Command)sender);
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.

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.
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: Packages - Display Based Upon User Role

Post by roteague »

Hadi Chemaly wrote:
roteague wrote:Could you accomplish the same thing with:

Code: Select all

base.CommandManager.RemoveCommand((Command)sender);
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.

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.
Thanks Hadi, I'll keep that in mind.
Robert
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: Packages - Display Based Upon User Role

Post by roteague »

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,
Robert
Hadi Chemaly

Re: Packages - Display Based Upon User Role

Post by Hadi Chemaly »

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.
roteague
Posts: 292
Joined: Thu Sep 25, 2008 4:49 pm
Location: Honolulu, Hawaii

Re: Packages - Display Based Upon User Role

Post by roteague »

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.
Robert
Post Reply