How to dynamically update the label of a menu contributed to the org.eclipse.ui.menus extension - eclipse-plugin

My eclipse plugin contributes a menu to the main menu. In it, is a sub-menu (selection) which in turn has some child elements (items). I would like to programmatically update the label of selection based on the selected item underneath. (see below)
File MyMenu Edit
─────┬─────────────────────┬──────────────────
│ Selection: Item B >│┌───────────┐
└─────────────────────┘│ Item A │
│ v Item B │
│ Item C │
└───────────┘
Using the command framework I was able to implement most of it (see below), but I can't figure out how to programmatically append the selection sub-menu with the text of its selected child.
Below are the relevant parts of the extensions to the plugin xml:
<extension point="org.eclipse.ui.commands">
<command
defaultHandler="menu_selector.DoSelectHandler"
id="command.do_select"
name="Select Option">
<commandParameter
id="command.do_select.option_value"
name="Option Value"
optional="false">
</commandParameter>
<commandParameter
id="command.do_select.persisted_value"
name="Persisted Value"
optional="false">
</commandParameter>
</command>
</extension>
<extension point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
<menu
label="MyMenu">
<menu
id="menu.selection"
label="Selection: ">
<dynamic
class="menu_selector.ItemsProvider"
id="items">
</dynamic>
</menu>
</menu>
</menuContribution>
</extension>
In the class ItemsProvider, I implemented getContributionItems() to populate the items dynamic sub-menu with do_select commands.
The class DoSelectHandler implements IElementUpdater. The commands framework calls its updateElement(UIElement element, Map parameters) method for all commands in the items dynamic menu right before it displays it. I use it to call setChecked(true) on the relevant element parameter to set the v character in front of the selected item in the items dynamic menu.
This would also be a logical route to update the selection menu, but I can't see how I can accomplish that. Setting the commandId on the selection menu doesn't make the commands framework call updateElement() with the selection menu as its element parameter.
Does anybody have an idea how to go around this?

You can get more control with specifing your own class for menu contribution
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
class="org.examples.menu.VeryDynamicMenuFactory"
locationURI="menu:org.eclipse.ui.main.menu?after=additions">
</menuContribution>
</extension>
The class should extend org.eclipse.ui.menus.ExtensionContributionFactory

Related

VSTO Ribbon Context Menu Dynamic Hierarchy

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

Aurelia binding for child elements

I have a couple custom elements laid out like this
<panel label="Label">
<row-panel title="Row1">
<button field="Row1" command="Label"></button>
</row-panel>
</panel>
Is there a way to use the title attribute "label" value of row-panel in the button attribute value for "field"?
Is there a way to use the panel attribute "label" value as the button "command" attribute value?
Ideally, I'd like the markup to look like this if possible.
<panel label="Label">
<row-panel title="Row1">
<button></button>
</row-panel>
</panel>
and the button element would inherit its field and command attributes from the two elements above it.
Any suggestions would be greatly appreciated!
You could create a property and bind it to all elements. Like this:
<panel label.bind="myProperty">
<row-panel title.bind="myProperty">
<button field.bind="myProperty"></button>
</row-panel>
</panel>

Disabling <action> in plugin develoipement

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>

Add standard command button "New Slide" to custom ribbon in office add-in

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 >

Open XML SDK - Adding a macro programatically to a Word 2007 document

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?