How to intercept the recurrence button click in the appointment window

Jawab How to intercept the recurrence button click in the appointment window

  • 01 Maret 2012 15:56
     
      Memiliki Kode

    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

Semua Balasan

  • 01 Maret 2012 16:00
     
     
    add debugging info (log, show message box) to Ribbon_load and inside your 'if' in getcustomui - is the code executed?
  • 01 Maret 2012 16:12
    Moderator
     
     
    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)

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "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
  • 05 Maret 2012 10:11
     
     
    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?
  • 05 Maret 2012 10:14
     
     
    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.

  • 05 Maret 2012 12:13
     
     

    declare your RecurrenceClick method like this:

    public void RecurrenceClick(IRibbonControl control)

    and let us know if it works now.

  • 06 Maret 2012 9:41
     
     
    Sadly, still no luck! Is this a bug?
  • 06 Maret 2012 15:44
    Moderator
     
     
    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]
    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
    • Ditandai sebagai Jawaban oleh Tom_Xu_WXModerator 15 Maret 2012 7:38
    • Tanda sebagai Jawaban dihapus oleh quickstar 21 Maret 2012 14:32
    •  
  • 21 Maret 2012 14:36
     
     
    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.
    Though, it doesn't Work even if I remove the ref argument.

    • Diedit oleh quickstar 21 Maret 2012 14:36
    •  
  • 21 Maret 2012 14:41
    Moderator
     
     
    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.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "quickstar" <=?utf-8?B?cXVpY2tzdGFy?=> wrote in message news:1bb75bd1-6d89-4ef7-b995-a310da7b739f...
    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.
    Though, it doesn't Work even if I remove the ref argument.


    Ken Slovak MVP - Outlook
  • 22 Maret 2012 13:41
     
     
    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.

  • 22 Maret 2012 13:52
    Moderator
     
     
    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.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "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
  • 22 Maret 2012 15:44
    Moderator
     
     
    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
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "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.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "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
  • 22 Maret 2012 16:13
    Moderator
     
     Jawab
    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
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "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
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "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.

    --
    Ken Slovak
    MVP - Outlook
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
     
     
    "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
    • Ditandai sebagai Jawaban oleh quickstar 24 Maret 2012 13:09
    •  
  • 24 Maret 2012 13:10
     
     
    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:
     
    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.