Window specific Ribbon controls

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

Window specific Ribbon controls
 
Mike Medved




Posts: 41
Joined: 2010-10-19
Doing development in C#, VS 2010. Add-in Express 2010. Currently testing on Outlook 2010

I show a custom form instead of the default email list for some mail folders.
I also show custom RIBBON bar (Outlook 2010). The items on the ribbon are shown/hidden/enabled/disabled depending on what is selected on the current window

If I open two explorer windows and select a different custom folder in each, it seems that the ribbon settings end up being shared across the two. So if a button should be enabled for the first one and disabled for the 2nd one based on the selection on each of the forms, it ends up being either enabled or disabled for both

The closest I came to getting it to work correctly is to re-specify the ribbon button status on adxOutlookEvents_ExplorerActivate event, but that is a really bad kludge. Doesn't work 100% of the time and the user still sees things change when they shouldn't be.

I know Outlook's ribbon is controled independently. How can that be setup for custom ribbon settings?

Thanks
Posted 12 Mar, 2011 17:14:55 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Mike,

It looks like you need to use the PropertyChanging event of the ribbon controls. Please have a look at the following forum threads for more information:

Ribbon checkbox affecting all opened explorers?
How to set the visiblity of a ribbon button for just the current inspector
Context dependent ribbon buttons
.NET, Extended MAPI, Windows Phone & RT
Posted 13 Mar, 2011 06:29:03 Top
Mike Medved




Posts: 41
Joined: 2010-10-19
Eugene,

Thanks for the guidence. Exactly what I needed. I do see how that works, though I am seeing some very odd inconsistencies. I want to replace the HOME tab with my own. I tried two different options, encountering two different problems:

1) SHOW/HIDE TABS - We should be able to show/hide tabs dynamically now that the bug with that is fixed (http://www.add-in-express.com/forum/read.php?FID=5&TID=8422)
And the tabs do have a PropertyChanging event.

I created a dummy tab ribbonHOMETab, set IdMso=TabMail and defined PropertyChanging event for Visible to be false when my custom form is shown. true otherwise
I created a dummy tab ribbonMYHOMETab, did NOT set IdMso and defined PropertyChanging event for Visible to be true when my custom form is shown. false otherwise

The PropertyChanging for ribbonHOMETab is not triggered at all.
The PropertyChanging for ribbonMYHOMETab is triggered and triggered and e.Value set to true but the Tab does not show.


2) Show/Hide Groups - When Option #1 failed, I tried hiding all groups on the built in tab when my custom folder is shown, and inserting my own groups within the built-in tab.

I set the PropertyChanging on all built in and custom groups and set them based on the currently displayed folder.

This is where it gets weird. The PropertyChanging gets triggered OK for all the groups the FIRST time I start Outlook. However, when I switch folders, it doesn't trigger. And the only way I can get it to trigger is to do this:

private void adxOlFormsManager_ADXBeforeFolderSwitch(....)
{
	// ribbonHOMEGroup1 refers to one of the groups on the default HOME tab
	ribbonHOMEGroup1.Visible = ribbonHOMEGroup1.Visible;
}


NOTE that the line doesn't actually change anything. It just sets the visible flag to itself. Having just that one line makes it so PropertyChanging events get fired correctly on ALL groups - both built-in ones and my own.

And that workaround only works if you touch the Visible property on one of the built-in groups, not one of the custom ones.
Posted 13 Mar, 2011 10:20:17 Top
Mike Medved




Posts: 41
Joined: 2010-10-19
In issue #1 disregard the Property changing not triggering at all.

As for issue #2, it actually impacts both #1 and #2. Seems that touching the Visible property on any item on the default HOME group causes all the PropertyChanging events to get triggered - buttons, groups and tabs.

Is that intended? When should the Visible and Enabled PropertyChanging events get triggered?
Posted 14 Mar, 2011 11:55:54 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Mike,

Could you please specify the build number of Add-in Express you use?

For more information about the Ribbon callbacks please take a look at the Customizing the 2007 Office Fluent Ribbon for Developers article.
.NET, Extended MAPI, Windows Phone & RT
Posted 14 Mar, 2011 12:22:24 Top
Mike Medved




Posts: 41
Joined: 2010-10-19
version 6.3.3052.2005

Will look at the link you gave. thanks
Posted 14 Mar, 2011 12:29:43 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Mike,

The following code works like a charm for built-in and custom ribbon tabs on my PC with Office 2010:

private void adxRibbonTab1_PropertyChanging(object sender, AddinExpress.MSO.ADXRibbonPropertyChangingEventArgs e)
{
   if (e.PropertyType == AddinExpress.MSO.ADXRibbonControlPropertyType.Visible)
   {
       e.Value = false;
   }
}
.NET, Extended MAPI, Windows Phone & RT
Posted 14 Mar, 2011 13:18:46 Top
Mike Medved




Posts: 41
Joined: 2010-10-19
What do you consider as "working" though? that would get triggered on startup. Would that code get called again when you switch folders? I would expect the code to trigger when you switch folders, but it doesn't. Not unless I add the line to set the visible property to itself. I can give you a sample app if it will help explain the situation
Posted 14 Mar, 2011 14:00:59 Top
Mike Medved




Posts: 41
Joined: 2010-10-19
[EDIT] ok, disregard. Seems that setting the Visible property triggered an Invalidate of the ribbon, which I would have been doing in the first place in order to have it update. I don't think I needed to do that for enabling/disabling buttons, so didn't think of that.

NOTE: In the sample I sent you I did also report an obscure situation where the HOME tab disappeared entirely. That does still happen
Posted 14 Mar, 2011 14:40:16 Top
Eugene Astafiev


Add-in Express team


Posts: 8540
Joined: 2007-07-25
Hi Mike,

Thank you for providing me with a sample add-in project. I have reproduced both issues on my PC with Office 2010.

1. Please note that Ribbon UI is a static thing from its birth. You need to use the Invalidate method of the ADXRibbonTab component to update the ribbon controls instead. You can read more about this in the Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3) article in MSDN.
2. The built-in tab may disappear sometimes. This is a bug in the Ribbon UI extensibility. I even can reproduce it with a regular VSTO add-in project. You don't need to use getVisible callback (see the Ribbon XML markup) if you set the IdMso property - just set the visible to true in that case. Also you can find the "Visible property of the ADXRibbonTab component was handled incorrectly for built-in Office ribbon tabs." entry in the Latest News section of our web site.
.NET, Extended MAPI, Windows Phone & RT
Posted 17 Mar, 2011 08:07:33 Top