locked
Customize Right-Click Context Menu in PowerPoint 2010 RRS feed

  • Question

  • I have an requirement where need to trap and customize existing Right-Click context menu for a shape object in PowerPoint 2010.

    I know this feature is not available in PowerPoint 2007. But does anyone know whether its available in 2010 and if yes appreciate if you can provide appropriate guidance.

    Regards,

    Ramesh

    Thursday, November 3, 2011 9:54 PM

Answers

All replies

  • I have a similar requirement in that I want to add a context menu item to the default context menu and then let the user apply some metadata to the selected element.  Any info on how to accomplish either of these tasks would be appreciated.
    Thursday, November 3, 2011 11:33 PM
  • Hi,

    Thank you for posting.

    As far as I know, we can custom the existing right-click context menu for a shape object in PowerPoint 2010. You can reference this article:

    http://skp.mvps.org/2010/ppt007.htm

    I tested on my side via the following ribbon xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <contextMenus>
        <contextMenu idMso="ContextMenuShape">
          <button id="idCustomShow" label="Make Custom" onAction="OnCustomShowFromSection" />
        </contextMenu>
      </contextMenus>
    </customUI>

    You can refer to the ControlIDs from the list:

    http://www.microsoft.com/download/en/details.aspx?id=6627
    Hope this can help you and just feel free to follow up after you have tried.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Bruce Song Tuesday, November 8, 2011 6:40 AM
    • Marked as answer by Bruce Song Wednesday, November 16, 2011 5:41 AM
    Friday, November 4, 2011 7:10 AM
  • Hi Bruce,

    Thank you for the reply.  This by itself isn't all I need I think.  I am writing an Add-In as opposed to a document level macro.  Basically, I think I have the right xml saved in an xml file in my AddIn project and I have code to add it to the CustomXMLParts list, but I can't find the right event handler on the Presentation to hook into.  here is what I am doing now. 

            private bool _isLoaded = false; 
    
            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                this.Application.SlideSelectionChanged += new PowerPoint.EApplication_SlideSelectionChangedEventHandler(OnSlideSelectionChanged);
            }
    
            void OnSlideSelectionChanged(PowerPoint.SlideRange SldRange) {
                this.LoadCustomUI(SldRange.Application.ActivePresentation);
            }
    
            private void ThisAddIn_Shutdown(object sender, System.EventArgs e){
    
            }
    
    
            private void LoadCustomUI(PowerPoint.Presentation presentation) {
                if (_isLoaded)
                    return; 
    
                string xmlString = GetCustomUIXml();
                presentation.CustomXMLParts.Add(xmlString, missing);
                _isLoaded = true; 
            }
    
            private string GetCustomUIXml() {
                StreamReader reader = new StreamReader(Assembly.GetExecutingAssembly().GetManifestResourceStream("PresoAddIn.ContextMenu.xml"));
                string xml = string.Empty;
    
                try {
                    if (reader.Peek() != -1) {
                        xml = reader.ReadToEnd();
                    }
                }
                catch (Exception ex) {
                    System.Diagnostics.Debug.WriteLine(ex.Message); 
                }
    
                return xml; 
            }
    

     

    and here is my XMl.  This all fails to give me a context menu item as I thought it would. 

     

     

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnLoad">
      <contextMenus>
        <contextMenu idMso="ContextMenuShape">
          <toggleButton visible="true" id="idAddToTargetsToggle" label="Allow Customization" onAction="OnAddToTargetsToggle" />
        </contextMenu>
      </contextMenus>
    </customUI>
    


    I am probably doing something completely wrong so any help would be appreciated.   I am not really married to using this event at all, I just used it because it was convenient for firing my code.  I couldn't put the load code in the ThisAddIn_Startup method because Application.ActivePresentation is null at that time.  Any advice about the correct way to do this would be well appreciated

     

     


    Monday, November 7, 2011 6:27 PM
  • Wow I was doing this all wrong.   Here is the article I needed. Thx for your reply though.

     

     

    http://msdn.microsoft.com/en-us/library/aa942866(v=VS.100).aspx

    • Proposed as answer by Bruce Song Tuesday, November 8, 2011 6:40 AM
    • Marked as answer by Bruce Song Wednesday, November 16, 2011 5:41 AM
    Monday, November 7, 2011 7:46 PM
  • Yes, your steps about adding custom xml is wrong. We should follow the steps from the article which described. If you have any problems when following the article just feel free to let us know.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, November 8, 2011 6:40 AM