none
Capture Event of Existing Ribbon Button and Add a Customized Ribbon RRS feed

  • Question

  • Hi All,
         First, thank you for checking my post.
         Now I'm working on a project which need capture the "Reply", "Reply to All", "Forward" Ribbon button event on the inspector of outlook 2007.
         I have read this post Answer How to hook existing ribbon buttons in Office 2007 and I can capture the event of ribbon buttons.  It works. but I find another issue.
         I have another customized Office Ribbon in the project. After I add the code according to that post, my customized office ribbon is disappeared from the inspector window. I checked code and these code causes the problem.
        protected override object RequestService(Guid serviceGuid)
        {
             if (serviceGuid == typeof(Office.IRibbonExtensibility).GUID)
             {
                  if (ribbon == null)
                      ribbon = new Ribbon1();
                  return ribbon;
             }

             return base.RequestService(serviceGuid);
        }

        This method should return a RibbonManager when IRibbonExtensibility is requested but now it returned a class like this:
        [ComVisible(true)]
        public class Ribbon1 : Office.IRibbonExtensibility
        {
            public Ribbon1()
            {
            }

            public string GetCustomUI(string ribbonID)
            {
                string ribbonXML = "<customUI xmlns=\"http://schemas.microsoft.com/office/2006/01/customui\">\n"
                    + "    <commands>\n"
                    + "        <command idMso=\"Reply\" onAction=\"myCopy\" />\n"
                    + "    </commands>\n"
                    + "    <ribbon>\n"
                    + "    </ribbon>\n"
                    + "</customUI>";
                return ribbonXML;
            }

            public void myCopy(Office.IRibbonControl control, ref bool CancelDefault)
            {
                MessageBox.Show("haha");
                CancelDefault = false;
            }
        }

        So how can I let the my customized Office appear on the inspector? Any suggestion is welcome. Thank you in advance.


    Whatever happens , we shall keep going on.
    Friday, November 28, 2008 6:28 AM

Answers

  • Hi Justin,

    Are you using Visual Studio 2005 and VSTO 2005 SE?Are you defined your Customized Office Ribbon in XML formt?

    If my guess is correct, the reason your own Ribbon control didn't load is that in the GetCustomUI method you just returned the XML which only built the existing Ribbon button.

    I assume you were add the Ribbon support by right click your solution explorer->add item->Ribbon Support, so there will be a Ribbon1.XML new available in your solution explorer.

    Next,integrate the ribbonXML string which you listed above into the Ribbon1.XML.Then, restore the context in GetCustomUI to the default value like:

     public string GetCustomUI(string ribbonID)
            {
                return GetResourceText("WordAddIn2007.Ribbon1.xml");
            }

    Then, put your own customized Ribbon XML code into the same file.

    And, there's a simple way if you just have a few of own customized Ribbon XML code you cuold directly append them to the ribbonXML variable, this will also work.

    Thanks
    • Marked as answer by Justin.CHG Thursday, December 4, 2008 5:53 AM
    Monday, December 1, 2008 3:47 AM

All replies

  • Hi Justin,

    Are you using Visual Studio 2005 and VSTO 2005 SE?Are you defined your Customized Office Ribbon in XML formt?

    If my guess is correct, the reason your own Ribbon control didn't load is that in the GetCustomUI method you just returned the XML which only built the existing Ribbon button.

    I assume you were add the Ribbon support by right click your solution explorer->add item->Ribbon Support, so there will be a Ribbon1.XML new available in your solution explorer.

    Next,integrate the ribbonXML string which you listed above into the Ribbon1.XML.Then, restore the context in GetCustomUI to the default value like:

     public string GetCustomUI(string ribbonID)
            {
                return GetResourceText("WordAddIn2007.Ribbon1.xml");
            }

    Then, put your own customized Ribbon XML code into the same file.

    And, there's a simple way if you just have a few of own customized Ribbon XML code you cuold directly append them to the ribbonXML variable, this will also work.

    Thanks
    • Marked as answer by Justin.CHG Thursday, December 4, 2008 5:53 AM
    Monday, December 1, 2008 3:47 AM
  • Hi Tim,
        Thank you for your reply :)
        I'm using VS2008 SP1 (I'm sorry I should mention this in the topic) and I create ribbon by using Ribbon (Visual Designer).
        I have tried your advice in this way. But it still does work:(
     
    public string GetCustomUI(string ribbonID) 
        string ribbonXML = "<customUI xmlns=\"http://schemas.microsoft.com/office/2006/01/customui\" onLoad=\"Load\" loadImage=\"LoadImage\">\n" 
            + "    <commands>\n" 
            + "        <command idMso=\"Reply\" onAction=\"RibbonClick\" />\n" 
            + "        <command idMso=\"Forward\" onAction=\"RibbonClick\" />\n" 
            + "        <command idMso=\"ReplyAll\" onAction=\"RibbonClick\" />\n" 
            + "    </commands>\n" 
            + " <ribbon>\n" 
            + "     <tabs>\n" 
            + "         <tab idMso=\"TabAddIns\" visible=\"true\" tag=\"RibbonId=Microsoft.Outlook.Mail.Compose\">\n" 
            + "             <group id=\"group1\" getKeytip=\"GetKeyTip\" getLabel=\"GetLabel\" getVisible=\"GetVisible\" tag=\"RibbonId=Microsoft.Outlook.Mail.Compose\">\n" 
            + "                 <button getEnabled=\"GetEnabled\" id=\"buttonCfg\" getImage=\"GetImage\" getLabel=\"GetLabel\" getKeytip=\"GetKeyTip\" getScreentip=\"GetScreenTip\" getShowImage=\"GetShowImage\" getShowLabel=\"GetShowLabel\" getSupertip=\"GetSuperTip\" getVisible=\"GetVisible\" tag=\"RibbonId=Microsoft.Outlook.Mail.Compose\" onAction=\"ButtonClick\" getDescription=\"GetDescription\" getSize=\"GetSize\"/>\n" 
            + "             </group>\n" 
            + "             <group id=\"OutlookExt\" getKeytip=\"GetKeyTip\" getLabel=\"GetLabel\" getVisible=\"GetVisible\" tag=\"RibbonId=Microsoft.Outlook.Mail.Compose\">\n" 
            + "                 <button getEnabled=\"GetEnabled\" id=\"btnShow\" getImage=\"GetImage\" getLabel=\"GetLabel\" getKeytip=\"GetKeyTip\" getScreentip=\"GetScreenTip\" getShowImage=\"GetShowImage\" getShowLabel=\"GetShowLabel\" getSupertip=\"GetSuperTip\" getVisible=\"GetVisible\" tag=\"RibbonId=Microsoft.Outlook.Mail.Compose\" onAction=\"ButtonClick\" getDescription=\"GetDescription\" getSize=\"GetSize\"/>\n" 
            + "             </group>\n" 
            + "         </tab>\n" 
            + "     </tabs>\n" 
            + " </ribbon>\n" 
            + "</customUI>"
     
        return ribbonXML; 

       

    Whatever happens , we shall keep going on.
    Tuesday, December 2, 2008 8:07 AM
  • Hi  Justin

    Does the information near the end of this MSDN article help you at all?
    Cindy Meister, VSTO/Word MVP
    Tuesday, December 2, 2008 9:30 AM
    Moderator
  • Hi ,

    I've reviewd your XML code, I removed all the call back in your code,they work fine in my side :


     <button  id=\"buttonCfg\" label=\"BTN\"  tag=\"RibbonId=Microsoft.Outlook.Mail.Compose\"    />\n"

    have you got any error message? may be something wrong in your callback method, for debug I suggest you remove all the call back first.

    Please  double check it, and please also try Cindy's suggestion.

    Thanks
    Wednesday, December 3, 2008 7:36 AM
  • Hi Tim and Cindy,
        Thank you for your reply. 
        I have found a solution to my problem according to Tim's reply.
        I have converted my Ribbon into XML Format and wrote the callback in this ribbon XML (xxx.Ribbon1.xml). then it works! :) That's great
        All your advice are very helpful. Thank you again.


    Whatever happens , we shall keep going on.
    Thursday, December 4, 2008 5:51 AM