Dynamic ribbon only updates the active inspector

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

Dynamic ribbon only updates the active inspector
 
Lee Davis




Posts: 11
Joined: 2009-03-30
Hi,

I have found that I am unable to update the ribbon for an inspector that is not the active inspector.

I have also noticed that when I change elements (captions/visibility & enabled of buttons etc...) I see a "flicker" when switching between inspectors.

I will send an email containing an example project that illustrates this problem.

You will notice that if you open two emails, both with my Ribbon Tab visible, switching between the emails will momentarily show the previously active email's details in my ribbon before displaying the correct details.

Further, if you click the button on my ribbon, then switch to a different inspector you will see (after 5 seconds) that the active inspector is updated, not the one where the timer is fired.

Before updating any of the ribbon's components I call


_module.CommandBarsObj = _inspector.CommandBars;


where _module is a reference to the AddInModule and _inspector is a reference to the inspector for the specific mailitem (not necessarily the ActiveInspector)

Similar code DOES work for toolbars, but not for ribbons.

Forcing an InspectorActivate event (by switch to another window and back again) will correct the ribbon's details.

Looking forward to your solution.

Thanks,
Lee.
Posted 09 Apr, 2009 23:09:30 Top
Andrei Smolin


Add-in Express team


Posts: 18842
Joined: 2006-05-11
Hello Lee,

Thank you for sending us the project. As soon as I have any info for you, I'll let you know.


Andrei Smolin
Add-in Express Team Leader
Posted 10 Apr, 2009 04:44:46 Top
Andrei Smolin


Add-in Express team


Posts: 18842
Joined: 2006-05-11
Hello Lee,

You pointed out two problems and demonstrated them by your code. They are (please correct me if I'm wrong):
- When updating the caption of a Ribbon button in the InspectorActivate event, "switching between the emails will momentarily show the previously active email's details in my ribbon before displaying the correct details"
- When updating the caption of a Ribbon button in the Timer event, "you will see that the active inspector is updated, not the one where the timer is fired".

The Ribbon doesn't provide a way to access properties of a given Ribbon control instance. Instead, it calls callback functions to set the control properties. That is, when the Office 2007 Ribbon decides that some property (say, the button caption) should be changed, it invokes an appropriate callback function, which supplies a [new] value for the property. Note that it is Ribbon that decides whether to change the property or not (but see below)

Add-in Express currently supports assigning the same property value for all instances of a Ribbon control. For a toolbar button caption, this means that whenever the Ribbon invokes a corresponding callback function, Add-in Express uses the ID of the Ribbon button to get the value you specified for the Caption property of the corresponding Add-in Express component and to return the value to the Ribbon.

When you specify a value in a Ribbon component property, Add-in Express saves the property value and calls InvalidateControl, a special method provided by the Ribbon. The method accepts the ID of a Ribbon control; this makes the Ribbon believe that all instances of the control require updating. But the Ribbon sets its own rules and the control instances will be updated when the Ribbon decides to do this.

When you open the first Inspector window in the current Outlook 2007 session, the Ribbon uses the XML markup created by Add-in Express and based on Ribbon components that you use (and their settings) to create Ribbon controls for you. Then it invokes callback functions to get the controls' properties as you designed them. Then it shows the controls. Finally, InspectorActivate occurs (let's assume for a moment that you don't change the button caption in this event). When you open a second inspector window, the Ribbon doesn't use callbacks because it already knows all property values.

Back to your scenario. In the first InspectorActivate, you change the button caption. This causes Add-in Express to save a new value and to call IncalidateControl. Usually, the Ribbon reacts immediately: it invokes the callback, Add-in Express returns the saved value, the Ribbon shows it. This is the time when the button caption blinks (the update speed depends on processor usage). When you open another inspector, the Ribbon knows that the button caption is invalid, so it invokes a callback function, gets the value you supplied in the first InspectorActivate and shows it. Then InspectorActivate occurs for the second inspector, you change the button caption again, InvalidateControl is called, the button caption blinks again. When you switch to the first inspector, the same sequence occurs: the Ribbon invokes a callback function to get the value that you set in the previous InspectorActivate, then InspectorActivate occurs for the current inspector and you set a new value.

Now, you click another Ribbon button that starts a timer, and then you switch to another inspector. Switching to another inspector saves a new property value, invalidates the first Ribbon button and shows a new caption for the button. When in the timer event, you change the caption of the first Ribbon button, this invalidates the button anew and shows yet another caption.

As you can see, there is no way to change the caption of a given Ribbon button instance in the scheme above. Instead, you can change the captions of all Ribbon button instances, but the Ribbon will not reflect all the changes at once. To provide developers with the ability to change the ribbon control properties dynamically, we are now probing an event that will occur when the Ribbon invokes callback functions. If our tests show that this approach is the right one, we will add this event to version 2009.

FYI, the public release of http://www.add-in-express.com/creating-addins-blog/cat/addin-express-2009/ is scheduled for early May.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Apr, 2009 12:55:45 Top
Lee Davis




Posts: 11
Joined: 2009-03-30
Hi Andrei,

thank you for the detailed reply and explanation of where the problem lies. Hopefully your testing will identify a solution as the current behaviour anything but ideal.

Thanks,
Lee.
Posted 22 Apr, 2009 02:20:30 Top
Andrei Smolin


Add-in Express team


Posts: 18842
Joined: 2006-05-11
Hi Lee,

We add the PropertyChanging property to all Ribbon components. Combined with AddinExpress.MSO.IRibbonUI.InvalidateControl(), the property will allow you to update Ribbons in the way you like. For Ribbon controls that have items, we also add the ItemPropertyChanging event.

The properties will be available in the upcoming public release of Add-in Express 2009 scheduled for early May.


Andrei Smolin
Add-in Express Team Leader
Posted 29 Apr, 2009 14:24:00 Top