How to intercept the recurrence button click in the appointment window
-
Thursday, March 01, 2012 3:56 PM
Hi all
I'm running into an issue during the programming with existing ribbons within outlook.
I'd like to handle the "Recurrence" button click in the appointment inspector.
I did the following:
I've registred my IRibbonExtensibility object in the ThisAddin.cs class as follows
protected override IRibbonExtensibility CreateRibbonExtensibilityObject() { return new AppointmentItemRibbon(); }The class it self is very straight forward
public class AppointmentItemRibbon : IRibbonExtensibility { private static string GetResourceText(string resourceName) { Assembly asm = Assembly.GetExecutingAssembly(); string[] resourceNames = asm.GetManifestResourceNames(); for (int i = 0; i < resourceNames.Length; ++i) { if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0) { using (Stream resourceStream = asm.GetManifestResourceStream(resourceNames[i])) { if (resourceStream != null) { using (StreamReader resourceReader = new StreamReader(resourceStream)) { return resourceReader.ReadToEnd(); } } } } } return null; } private IRibbonUI _ribbonUi; public string GetCustomUI(string ribbonID) { if (ribbonID == "Microsoft.Outlook.Appointment") { return GetResourceText("OutlookAddIn1.AppointmentItemRibbon.xml"); } return null; } public void RecurrenceClick(IRibbonControl control, ref bool bolCancel) { MessageBox.Show("huhu" + control.Id); } public void Ribbon_Load(IRibbonUI ribbonUI) { _ribbonUi = ribbonUI; } }
as well the according xml
<?xml version="1.0" encoding="UTF-8"?> <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load"> <commands> <command idMso="Recurrence" onAction="RecurrenceClick"/> </commands> </customUI>
Unfortunately it still doesn't work. What did I wrong? Any ideas?
Regards Lukas
All Replies
-
Thursday, March 01, 2012 4:00 PMadd debugging info (log, show message box) to Ribbon_load and inside your 'if' in getcustomui - is the code executed?
-
Thursday, March 01, 2012 4:12 PMModeratorDoes it work better if you remove the "ref" argument for Cancel and write your signature like this:public void RecurrenceClick(IRibbonControl control, bool cancelDefault)
"quickstar" <=?utf-8?B?cXVpY2tzdGFy?=> wrote in message news:eb1248fb-240f-4f0f-910c-a2be7bc6c4ab...Hi all
I'm running into an issue during the programming with existing ribbons within outlook.
I'd like to handle the "Recurrence" button click in the appointment inspector.
I did the following:
I've registred my IRibbonExtensibility object in the ThisAddin.cs class as follows
protected override IRibbonExtensibility CreateRibbonExtensibilityObject() { return new AppointmentItemRibbon(); }The class it self is very straight forward
public class AppointmentItemRibbon : IRibbonExtensibility { private static string GetResourceText(string resourceName) { Assembly asm = Assembly.GetExecutingAssembly(); string[] resourceNames = asm.GetManifestResourceNames(); for (int i = 0; i < resourceNames.Length; ++i) { if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0) { using (Stream resourceStream = asm.GetManifestResourceStream(resourceNames[i])) { if (resourceStream != null) { using (StreamReader resourceReader = new StreamReader(resourceStream)) { return resourceReader.ReadToEnd(); } } } } } return null; } private IRibbonUI _ribbonUi; public string GetCustomUI(string ribbonID) { if (ribbonID == "Microsoft.Outlook.Appointment") { return GetResourceText("OutlookAddIn1.AppointmentItemRibbon.xml"); } return null; } public void RecurrenceClick(IRibbonControl control, ref bool bolCancel) { MessageBox.Show("huhu" + control.Id); } public void Ribbon_Load(IRibbonUI ribbonUI) { _ribbonUi = ribbonUI; } }
as well the according xml
<?xml version="1.0" encoding="UTF-8"?> <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load"> <commands> <command idMso="Recurrence" onAction="RecurrenceClick"/> </commands> </customUI>
Unfortunately it still doesn't work. What did I wrong? Any ideas?
Regards Lukas
Ken Slovak MVP - Outlook -
Monday, March 05, 2012 10:11 AM
add debugging info (log, show message box) to Ribbon_load and inside your 'if' in getcustomui - is the code executed?
The GetCustumUI is called correctly. I don't know where I should put additional degging infos. Where would you put more informations? -
Monday, March 05, 2012 10:14 AMDoes it work better if you remove the "ref" argument for Cancel and write your signature like this:public void RecurrenceClick(IRibbonControl control, bool cancelDefault)
Nope, the ref argument is used to route the default behavior.
If I remove the ref argument, it's used to determine if the toggleButton is clicked or not.
-
Monday, March 05, 2012 12:13 PM
declare your RecurrenceClick method like this:
public void RecurrenceClick(IRibbonControl control)
and let us know if it works now.
-
Tuesday, March 06, 2012 9:41 AMSadly, still no luck! Is this a bug?
-
Tuesday, March 06, 2012 3:44 PMModeratorThe signature for a toggleButton does not use "ref" or any by reference designation for the Cancel argument. Take a look at http://msdn.microsoft.com/en-us/library/bb421511(v=office.12).aspx for an example.
--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm"quickstar" <=?utf-8?B?cXVpY2tzdGFy?=> wrote in message news:a5b8d429-4a3c-4eac-92bb-3734ed37aca8...Does it work better if you remove the "ref" argument for Cancel and write your signature like this:public void RecurrenceClick(IRibbonControl control, bool cancelDefault)
Nope, the ref argument is used to route the default behavior.
If I remove the ref argument, it's used to determine if the toggleButton is clicked or not.
Ken Slovak MVP - Outlook- Marked As Answer by Tom_Xu_WXModerator Thursday, March 15, 2012 7:38 AM
- Unmarked As Answer by quickstar Wednesday, March 21, 2012 2:32 PM
-
Wednesday, March 21, 2012 2:36 PM
Though, it doesn't Work even if I remove the ref argument.The signature for a toggleButton does not use "ref" or any by reference designation for the Cancel argument. Take a look at http://msdn.microsoft.com/en-us/library/bb421511(v=office.12).aspx for an example.
- Edited by quickstar Wednesday, March 21, 2012 2:36 PM
-
Wednesday, March 21, 2012 2:41 PMModeratorIs that handler actually getting called? Add some logging or debug.writeline() information or something to verify that. When I use a toggle button setting Cancel = true does work."quickstar" <=?utf-8?B?cXVpY2tzdGFy?=> wrote in message news:1bb75bd1-6d89-4ef7-b995-a310da7b739f...
Though, it doesn't Work even if I remove the ref argument.The signature for a toggleButton does not use "ref" or any by reference designation for the Cancel argument. Take a look at http://msdn.microsoft.com/en-us/library/bb421511(v=office.12).aspx for an example.
Ken Slovak MVP - Outlook -
Thursday, March 22, 2012 1:41 PMIs that handler actually getting called? Add some logging or debug.writeline() information or something to verify that. When I use a toggle button setting Cancel = true does work.
Of course not. If the handler would be called my post would be obsolete.
You can Download my sample project for reference. It's very strange, may be it's a bug within outlook.
-
Thursday, March 22, 2012 1:52 PMModeratorOK, that's new information, that the callback isn't being called at all. I'll download your project and take a look at it."quickstar" <=?utf-8?B?cXVpY2tzdGFy?=> wrote in message news:79418b4d-b889-4fae-b44f-9089afdd821a...Is that handler actually getting called? Add some logging or debug.writeline() information or something to verify that. When I use a toggle button setting Cancel = true does work.
Of course not. If the handler would be called my post would be obsolete.
You can Download my sample project for reference. It's very strange, may be it's a bug within outlook.
Ken Slovak MVP - Outlook -
Thursday, March 22, 2012 3:44 PMModeratorMy own brain was dead in our earlier discussion of the toggleButton, the correct onAction signature for a toggle is:public void RecurrenceClick(IRibbonControl control, bool pressed)The cancel argument doesn't apply to toggle's, it's the pressed state that is the second argument.However, even with the correct argument setup for the callback I now get the RecurrenceClick() method called, but I get a "wrong signature" error message.When I altered your ribbon XML to also handle the click of a toggleButton I added as a custom button to the appointment ribbon the same RecurrenceClick() callback was successfully executed.So the new signature is correct for toggleButton's.I'll try to find out about this, but it appears that either that button is restricted or is actually not a toggleButton but something else."Ken Slovak" <=?utf-8?B?S2VuIFNsb3Zhaw==?=> wrote in message news:4d12ef2a-6d34-4648-b0f4-f84eeb3fb44f...OK, that's new information, that the callback isn't being called at all. I'll download your project and take a look at it."quickstar" <=?utf-8?B?cXVpY2tzdGFy?=> wrote in message news:79418b4d-b889-4fae-b44f-9089afdd821a...Is that handler actually getting called? Add some logging or debug.writeline() information or something to verify that. When I use a toggle button setting Cancel = true does work.
Of course not. If the handler would be called my post would be obsolete.
You can Download my sample project for reference. It's very strange, may be it's a bug within outlook.
Ken Slovak MVP - Outlook
Ken Slovak MVP - Outlook -
Thursday, March 22, 2012 4:13 PMModerator
OK, I figured it out, it seems to be something I've been unable to find any documentation on.It appears that when repurposing a toggleButton onAction you have to add a new bool cancelDefault argument to the usual bool pressed argument.The callback signature I used to get the callback called was this:public void RecurrenceClick(IRibbonControl control, bool pressed, ref bool cancelDefault)Setting cancelDefault to true prevented the recurrence dialog from opening, setting it false allowed it to open."Ken Slovak" <=?utf-8?B?S2VuIFNsb3Zhaw==?=> wrote in message news:d1d5d4e8-dda0-436d-846e-fc0dfc5c5c25...My own brain was dead in our earlier discussion of the toggleButton, the correct onAction signature for a toggle is:public void RecurrenceClick(IRibbonControl control, bool pressed)The cancel argument doesn't apply to toggle's, it's the pressed state that is the second argument.However, even with the correct argument setup for the callback I now get the RecurrenceClick() method called, but I get a "wrong signature" error message.When I altered your ribbon XML to also handle the click of a toggleButton I added as a custom button to the appointment ribbon the same RecurrenceClick() callback was successfully executed.So the new signature is correct for toggleButton's.I'll try to find out about this, but it appears that either that button is restricted or is actually not a toggleButton but something else."Ken Slovak" <=?utf-8?B?S2VuIFNsb3Zhaw==?=> wrote in message news:4d12ef2a-6d34-4648-b0f4-f84eeb3fb44f...OK, that's new information, that the callback isn't being called at all. I'll download your project and take a look at it."quickstar" <=?utf-8?B?cXVpY2tzdGFy?=> wrote in message news:79418b4d-b889-4fae-b44f-9089afdd821a...Is that handler actually getting called? Add some logging or debug.writeline() information or something to verify that. When I use a toggle button setting Cancel = true does work.Of course not. If the handler would be called my post would be obsolete.
You can Download my sample project for reference. It's very strange, may be it's a bug within outlook.
Ken Slovak MVP - Outlook
Ken Slovak MVP - Outlook
Ken Slovak MVP - Outlook- Marked As Answer by quickstar Saturday, March 24, 2012 1:09 PM
-
Saturday, March 24, 2012 1:10 PMOK, I figured it out, it seems to be something I've been unable to find any documentation on.It appears that when repurposing a toggleButton onAction you have to add a new bool cancelDefault argument to the usual bool pressed argument.The callback signature I used to get the callback called was this:publicvoidRecurrenceClick(IRibbonControlcontrol, boolpressed, ref boolcancelDefault)Setting cancelDefault to true prevented the recurrence dialog from opening, setting it false allowed it to open.
You got it! Thanks a lot!
It seems to be a documentation gap.

