none
Togglebutton GetVisible supporting different states in multiple documents RRS feed

  • Question

  • I'm using ribbon xml to handle my togglebutton.  I'm using the getVisible attribute on the group to hide/show the togglebutton in different states. But if I have multiple documents open the state is changing in all documents. Is it supported to have different states in multiple documents (powerpoint/word)?
    Monday, March 12, 2012 2:40 PM

Answers

  • Hi MartinMyth,

    Thank you for posting.

    I guess you can set the visible attribute for the group according to the document's name. Below is the code snippet for you to reference:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab id="MyTabTest" label="Hide Toggle Button">
            <group id="group1" label="Demo grounp1" getVisible="GetVisible">
    
            </group>
            <group id="group2" label="Demo grounp2">
              <toggleButton id="togglebutton1"
              label="Toggle Window Group" onAction="SetGroup1Visible"
                            />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
            private bool groupWindowVisible = false;
            public bool GetVisible(Office.IRibbonControl control)
            {
                return groupWindowVisible;
            }
    
            public void SetGroup1Visible(Office.IRibbonControl control,bool flag)
            {
                string docName = Globals.ThisAddIn.Application.ActiveDocument.Name;
                switch (docName)
                {
                    case "Document1":
                        groupWindowVisible = !groupWindowVisible;
                        break;
                    default:
                        break;
                }
    
                ribbon.Invalidate();
            }

    The SetGroup1Visible call back judge whether the document name is Document1 and then decide whether to change the visible state.If I have misunderstood you, just feel free to let me know your details.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Bruce Song Tuesday, March 13, 2012 5:29 AM
    • Marked as answer by Bruce Song Wednesday, April 4, 2012 6:20 AM
    Tuesday, March 13, 2012 5:28 AM
  • I just realized I have to keep the different states (getVisible, getPressed) in a dictionary where the key is currentDocument in order to handle multiple documents.
    • Marked as answer by Bruce Song Wednesday, April 4, 2012 6:20 AM
    Tuesday, March 13, 2012 11:15 AM

All replies

  • Hi MartinMyth,

    Thank you for posting.

    I guess you can set the visible attribute for the group according to the document's name. Below is the code snippet for you to reference:

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab id="MyTabTest" label="Hide Toggle Button">
            <group id="group1" label="Demo grounp1" getVisible="GetVisible">
    
            </group>
            <group id="group2" label="Demo grounp2">
              <toggleButton id="togglebutton1"
              label="Toggle Window Group" onAction="SetGroup1Visible"
                            />
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>
            private bool groupWindowVisible = false;
            public bool GetVisible(Office.IRibbonControl control)
            {
                return groupWindowVisible;
            }
    
            public void SetGroup1Visible(Office.IRibbonControl control,bool flag)
            {
                string docName = Globals.ThisAddIn.Application.ActiveDocument.Name;
                switch (docName)
                {
                    case "Document1":
                        groupWindowVisible = !groupWindowVisible;
                        break;
                    default:
                        break;
                }
    
                ribbon.Invalidate();
            }

    The SetGroup1Visible call back judge whether the document name is Document1 and then decide whether to change the visible state.If I have misunderstood you, just feel free to let me know your details.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Bruce Song Tuesday, March 13, 2012 5:29 AM
    • Marked as answer by Bruce Song Wednesday, April 4, 2012 6:20 AM
    Tuesday, March 13, 2012 5:28 AM
  • I just realized I have to keep the different states (getVisible, getPressed) in a dictionary where the key is currentDocument in order to handle multiple documents.
    • Marked as answer by Bruce Song Wednesday, April 4, 2012 6:20 AM
    Tuesday, March 13, 2012 11:15 AM
  • MartinMyth,yes, I also think that use dictionary is good idea.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, March 15, 2012 2:24 AM