Context dependent ribbon buttons

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

Context dependent ribbon buttons
 
RikardG




Posts: 95
Joined: 2009-10-19
Hi,

I am developing an addin which is saving emails to a database. When a user creates a new email there should be a toggle button for the user to click. If the button is pressed the email should be saved to the database, otherwise it should not. At the moment I have two problems:

1) When the user has several new emails (not sent) open there are several inspectors but only one ribbon button. If I press the toggle button for one inspector the button's status in all the other inspectors is changed as well. I have read that "OnPropertyChanging" event could be used to catch the event for a single instance of the ribbon button. But this doesn't seem to work very well (at least not in Outlook 2010) because the event is not raised immediately, it seems to be raised when activating the inspector. This results in pressing the button nothing seems to happen until you switch focus to another inspector and back again...

2) When the email is sent I'd like to get information whether the user has pressed the "Save" button for the current inspector or not. If the button for the current inspector is pressed, the email should be saved, otherwise not. How could this be done?

Regards
Posted 02 Dec, 2010 03:37:26 Top
Eugene Astafiev


Add-in Express team


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

1. I have reproduced that issue in Outlook 2007 SP2 on my PC. It looks like this is the way how the Ribbon UI works. As a workaround you can iterate through all inspectors in Outlook programatically and activate each instance using the Activate method of the Inspector class.

2. Please have a look at the Intercepting built-in Ribbon controls section in the documentation.
.NET, Extended MAPI, Windows Phone & RT
Posted 02 Dec, 2010 06:36:02 Top
RikardG




Posts: 95
Joined: 2009-10-19
Hi,

I think you may have misunderstood my needs for the second question (or I may not understand your answer...). I'll try to explain my question more:

In the AddinExpress.MSO.ADXOutlookAppEvents.ItemSend event I want to know if the user has pressed my toggle button indicating the email should be saved to the database. I don't understand how I could get hold of the state of the button for current inspector of the current mail item?

Regards
Posted 02 Dec, 2010 07:03:30 Top
Eugene Astafiev


Add-in Express team


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

Did you try to use the Pressed property of the AddinExpress.MSO.ADXRibbonButton class in the ItemSend event handler?
.NET, Extended MAPI, Windows Phone & RT
Posted 02 Dec, 2010 07:38:02 Top
RikardG




Posts: 95
Joined: 2009-10-19
Hi,

I don't understand what you mean...

How can I know if the user pressed the toggle button in the inspector for current mail?

Friend WithEvents rbInspectorSaveMail As AddinExpress.MSO.ADXRibbonButton

Private Sub adxOutlookEvents_ItemSend(ByVal sender As System.Object, ByVal e As AddinExpress.MSO.ADXOlItemSendEventArgs) Handles adxOutlookEvents.ItemSend
Dim mailItem As Outlook.MailItem = TryCast(e.Item, Outlook.MailItem)
Dim inspector As Outlook.Inspector = mailItem.GetInspector()

I can't check the status for the rbInspectorSaveMail button as it's status is for all the inspectors...
What to do here?

End Sub
Posted 03 Dec, 2010 03:40:50 Top
Eugene Astafiev


Add-in Express team


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

How can I know if the user pressed the toggle button in the inspector for current mail?


You can use the Click event of the AddinExpress.MSO.ADXRibbonButton class for a such task. Moreover, the following code works like a charm on my PC with Outlook 2007 SP2:

private void adxOutlookEvents_ItemSend(object sender, AddinExpress.MSO.ADXOlItemSendEventArgs e)
{
    System.Windows.Forms.MessageBox.Show(adxRibbonButton1.Pressed.ToString());
}
.NET, Extended MAPI, Windows Phone & RT
Posted 03 Dec, 2010 06:00:14 Top
RikardG




Posts: 95
Joined: 2009-10-19
I'll try to explain again:

1) The user creates two new emails (without sending any of them = there are two inspector windows open at the same time)
2) In the first inspector, the user toggles my button for saving the email to the database
3) In the other inspector, the user do NOT toggle my button for saving the email to the database.
4) The user clicks the send button for one of the inspector windows.
5) I end up in the following event...


private void adxOutlookEvents_ItemSend(object sender, AddinExpress.MSO.ADXOlItemSendEventArgs e)
{
' How do I know which inspector button was toggled, ie how do I know the status of the toggle button for the inspector for the current mail?
}

If I do as you suggest, the button will be "pressed" if the user toggled the button in ANY of the two inspector windows...

Regards
Posted 03 Dec, 2010 06:40:06 Top
Eugene Astafiev


Add-in Express team


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

Thank you for providing me with a step-by-step guide. Unfortunately I couldn't reproduce the issue on my PC with Outlook 2007 SP2. Could you please send a sample add-in project to me for testing?

BTW What version and build number of Add-in Express do you use?
.NET, Extended MAPI, Windows Phone & RT
Posted 06 Dec, 2010 13:21:24 Top
RikardG




Posts: 95
Joined: 2009-10-19
Where can I send the sample?
Posted 07 Dec, 2010 06:01:41 Top
Eugene Astafiev


Add-in Express team


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

Please find the support e-mail address in the readme.txt file.
.NET, Extended MAPI, Windows Phone & RT
Posted 07 Dec, 2010 06:03:46 Top