How does one create a dynamic menu hierarchy using VSTO Ribbons (for Outlook 2016)?
The xml placeholder could look like this, but I need to add/remove a menu tree under the menu root (instead of dummySingle). It seems like there would need to be something like a "getDependents" callback for menu items.
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<contextMenus>
<contextMenu idMso="ContextMenuMailItem">
<menu id="Menu Root" label="Menu Root" >
<button id="dummySingle"
label="dummy"
onAction="DummyAction"/>
</menu >
</contextMenus>
</customUI>
You would need to look at Dynamic Menus for Office Ribbon. This would be great source for you to start with: Adding Custom Dynamic Menus to the Office Fluent User Interface. Your ribbon XML will looks like ...
<dynamicMenu id="dynamicMenu1"
label="Dynamic Menu"
getContent="GetContent" />
And on GetContent handler you will build dynamic menu contexts, may looks like ...
public string GetContent(IRibbonControl control)
{
StringBuilder MyStringBuilder = new StringBuilder(#"<menu xmlns=""http://schemas.microsoft.com/office/2006/01/customui"" >");
MyStringBuilder.Append(#"<button id=""button1"" label=""Insert Text"" onAction=""OnAction"" imageMso=""SignatureLineInsert"" />");
MyStringBuilder.Append(#"<menuSeparator id=""menusep1"" getTitle=""GetTitle"" />");
MyStringBuilder.Append(#"<button id=""button2"" label=""Insert More Text"" onAction=""OnAction"" imageMso=""FileDocumentInspect"" />");
MyStringBuilder.Append(#"</menu>");
return MyStringBuilder.ToString();
}
More on Dynamic Menus: documentation for dynamicMenu
Related
I'm trying to repurpose the built in font selector for my own objects in PowerPoint (vsto add-in). I repurpose regular commands (bold, italic etc.) successfully using the ribbon xml.
I have a test that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab idMso="TabAddIns" label="Test">
<group id="MyGroup"
label="My Group">
<comboBox idMso="Font" label="ComboBox1" onChange="ChangeCallback"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
If I have a regular is instead of the idMso this callback works fine:
ChangeCallback(Office.IRibbonControl control, string text)
{
Debug.WriteLine("Changed");
}
The callback stops working when I use idMso="Font", but the comboBox works and I can use it to select font like normal.
I have tried the following callback with no luck.
ChangeCallback(Office.IRibbonControl control, string text, ref bool cancelDefault)
{
Debug.WriteLine("Changed");
}
When I repurpose commands I put it in the commands section of the xml instead of the ribbon, but having a comboBox element there is not allowed.
Any ideas on how to get this to work?
In my application have a menu named Search, it is having sub menu named "Text" and the text sub menu also has a sub menu in that there is an action named 'Package' i.e., is created as action. this search menu is common for all perspectives.
i want to disable that action 'Packages' for particular particular perspective how to do that?
please help me.following is the code for menu creation and action
<menu
id="textSearchSubMenu"
label="Text"
path="org.eclipse.search.menu/fileSearchContextMenuActionsGroup">
<groupMarker
name="group2">
</groupMarker>
</menu>
<action
class="com.chinna.search.SPXTextSearchAction"
id="com.chinna.builder.SearchAction"
label="Packages"
menubarPath="org.eclipse.search.menu/textSearchSubMenu/group2"
pulldown="false"
retarget="false"
style="push">
<enablement>
<objectClass
name="org.eclipse.core.resources.IResource">
</objectClass>
</enablement>
</action>
I have created my customized ribbon in an addIn. Now I would like to add the New Slide command that exist in home screen (see screenshot below).
You can add built-in controls to your custom tab by soecifying their IdMso values. See Office 2013 Help Files: Office Fluent User Interface Control Identifiers .
You can read more about the Ribbon UI in the following series of articles in MSDN:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
I think after a lot of searching I finally figured it out!
This is all the code you need, delete everything else
This will create a new slide button just like the one that comes default in PowerPoint
<group id="add_slide" label="Add Slide">
<control idMso="SlideNewGallery" size="large" />
</group>
credit
i currently have new slide button in my addin like the image below which gives me a new slide
however I want the option like the already existing new slide in home ribbon where I can choose templates.Is there any way to invoke this button in my customized ribbon so below is my newslide that is what i want to get in my addin
private void New_slide_Click(object sender, RibbonControlEventArgs e)
{
PowerPoint.Application ppApp = Globals.ThisAddIn.Application;
ppApp.CommandBars.ExecuteMso("SlideNewGallery");
}
I created a new ribbon based on xml Template in VS. Afterwards I added a group and a control based on an idMso-Value. When using this xml file
<?xml version="1.0" encoding="UTF-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
<ribbon>
<tabs>
<tab id="tab0" label="AddIn">
<group id="grpCustom">
<button idMso="SlideNew" size="large" label="YOUR CUSTOM TEXT"></button>
</group>
<group idMso="GroupSlides"></group>
</tab>
</tabs>
</ribbon>
</customUI>
This results in that custom ribbon. Eugene Astafiev pointed it out, you can find idMso-Values in MSDN.
As explained by Franz the solution is to use the idMso.
For the New Slide command you are looking for, if you look at MSN in the idMso Table for "New Slide" you will find two entries.
The one you are looking for is a Gallery with idMso=SlideNewGallery.
(not a button).
You can add it in the XML. I like to use the Ribbon Editor.
With the Ribbon Editor it looks like this:
And in the Add-In it looks then like this:
The CustomUI XML relevant part looks like this
<group id="TD_GrpMisc" label="Misc">
<gallery
idMso="SlideNewGallery"
size="large"/>
<button
idMso="SlideNew"
size="large"/>
</group >
I am developing a custom ribbon extension for Excel, in which a control requires different custom images. I managed to use some images located in my filesystem, but I would like to embed these images inside the .xlsm file.
Is it possible to do it and to reference them from the VBA code that updates the image of the control?
For test purposes, this is the XML that defines my custom ribbon:
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="ribbonLoaded">
<ribbon>
<tabs>
<tab idMso="TabHome" >
<group id="customGroup1" label="My Group" insertAfterMso="GroupFont">
<button id="customButton1" label="Click Me" size="large" onAction="Macro1" getImage="getButtonImage"/>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
And this is the macro that change the image of the customButton1 control:
Dim imgIndex As Long
Public Sub getButtonImage(ByVal control As IRibbonControl, ByRef Image)
Select Case control.ID
Case "customButton1"
Set Image = LoadPicture("img" + Trim(Str(imgIndex)) + ".bmp")
imgIndex = (imgIndex + 1) Mod 2
End Select
End Sub
I tried to add the bmp files inside the .xlsm and reference them updating the relationships file (.rels), but I don't know how to reference them from VBA and most important, when I open the file with Excel and save it, they are automatically deleted...
Any help is appreciated!
If the image is embedded in the customUI, you do not need VBA to add them to a control. Just use the same ID for the image in an image tag:
<button id="button1" label="Test" size="large" image="TestID" onAction="ButtonOnAction" />
My sample is adressing the image with ID "TestID", which must be found in the customUI XML - expand the customUI node in the Custom UI Editor to find or change the image ID (or use the editor to add a new image).
robcooper's answer from UtterAccess.com might help:
Public Sub getButtonImage(ByVal control As IRibbonControl, ByRef image)
'for use in Access 2007 Ribbon control
'requires a reference to the Micrsoft Office 12.0 Object Library
Select Case control.ID
Case "cmdMainMenu"
Set image = LoadPicture(CurrentProject.Path & "\home.bmp")
End Select
End Sub
I am trying to dynamically add a new custom ribbon in a Word 2007 document following teh manual method described in this article :- http://msdn.microsoft.com/en-us/library/aa338202(v=office.12).aspx.
The article specifies the following :-
a) Create a XML file named customUI.xml which will contain the elements you want to display
in the tab and put the same in a folder named customUI.
b) Rename your Word 2007 document to .zip. Add the above "customUI" folder to the zip file.
c) Add the following relationship to the "_rels/rels" file in the .zip file :-
<Relationship Type="http://schemas.microsoft.com/office/2006/
relationships/ui/extensibility" Target="/customUI/customUI.xml"
Id="customUIRelID" />
Do we have some code sample to achieve the same using OpenXML SDK? For example, how to add the "RibbonExtensibilityPart" (which contains the ribbon XML) to the document?
EDIT :-
This is how I did the above mentioned steps:-
string documentFileName = <path of the docx file>;
string ribbonXml = <path of the ribbon XML file>;
using (WordprocessingDocument myDoc = WordprocessingDocument.Open(documentFileName, true))
{
MainDocumentPart mainPart = myDoc.MainDocumentPart;
if (myDoc.GetPartsCountOfType<RibbonExtensibilityPart>() > 0)
myDoc.DeletePart(myDoc.GetPartsOfType<RibbonExtensibilityPart>().First());
RibbonExtensibilityPart ribbonExtensibilityPart = myDoc.AddNewPart<RibbonExtensibilityPart>();
ribbonExtensibilityPart.CustomUI = new DocumentFormat.OpenXml.Office.CustomUI.CustomUI(File.ReadAllText(ribbonXML));
myDoc.CreateRelationshipToPart(ribbonExtensibilityPart);
}
and I am able to see the new ribbon with the elements in it.
However, I have buttons in the ribbon and I want to add handle actions on those buttons. Following is what my Ribbon XML looks like :-
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui">
<ribbon>
<tabs>
<tab id="CustomTab" label="My Tab">
<group id="MyGroup" label="My Group" >
<button id="Button1" label="My Large Button"
size="large"/>
<button id="Button2" label="My Normal Button"
size="normal" *onAction="ThisDocument.MyOtherButtonMacro"* />
</group >
</tab>
</tabs>
</ribbon>
</customUI>
have a look at the "onAction="ThisDocument.MyOtherButtonMacro". I know I can write Macro function in the document. However, as the custom ribbon will be added dynamically on the server-side, I am not sure how I can add the macro dynamically. Could anyone help?