I have a command to launch views configured in plugin.xml of an RCP application module as follows:
<extension
point="org.eclipse.ui.commands">
<command
defaultHandler="myapp.commandhandler.LaunchView"
id="myapp.command.launchview"
name="Map">
</command>
</extension>
I have configured this command to be shared across a couple of menu extensions like this:
<menuContribution
allPopups="false"
locationURI="menu:org.eclipse.ui.main.menu">
<menu
id="myapp.application.menu.showview"
label="Show View">
<command
commandId="myapp.command.launchview"
label="Map"
style="push">
</command>
<command
commandId="myapp.command.launchview"
label="Legend"
style="push">
</command>
</menu>
</menuContribution>
Now I want to pass a command parameter representing each view's ID, similar to what is being done here Eclipse RCP commands.
But when I add these parameter configurations, these menu items disappear from the main menu. Any ideas?
Menu item will disappear from menu if the commandId or commandParameter it is bound to does not exist.
Related
I have an eclipse RCP application (already built). I need to integrate it with eclipse UI itself. What I mean is -- I want to add a menu option in eclipse User Interface and a command in the menu which when clicked runs the application.
It is similar to find and replace option in the eclipse menu
Any idea how this can be done?
I also want the application to be bundled with eclipse
Write a plugin that you install in to Eclipse (rather than your RCP).
The plugin can use the org.eclipse.ui.menus extension point to add to the File menu. For example:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="menu:file?after=open.ext">
<command
commandId="my.command.id"
id="my.menu.id"
style="push">
</command>
</menuContribution>
Use the org.eclipse.ui.commands extension point to define the command
<extension
point="org.eclipse.ui.commands">
<command
id="my.commnd.id"
description="Description text"
name="Name">
</command>
Use the org.eclipse.ui.handlers extension point to define a handler for the command
<extension
point="org.eclipse.ui.handlers">
<handler
class="package.CommandHandler"
commandId="my.command.id">
</handler>
The handler contains the code to run your RCP:
public class CommandHandler extends AbstractHandler
{
public Object execute(ExecutionEvent event) throws ExecutionException
{
// TODO launch your RCP
return null;
}
}
I created a simple Eclipse plugin, to launch a wizard and create some files, everything is working, I also added an option lo launch the wizard from the New > Mi Wizard menu, but now I want to display this option only when I right click an specific folder in a project, this is what I have so far:
This is my wizard:
<extension point="org.eclipse.ui.newWizards">
<category
name="My Category"
id="com.test.myCategory">
</category>
<wizard
name="My Wizard"
icon="icons/wizard1.gif"
category="com.test.myCategory"
class="com.test.myWizard"
id="com.test.myWizard">
</wizard>
</extension>
And this is how I'm adding the wizard to the New menu:
<extension point="org.eclipse.ui.navigator.navigatorContent">
<commonWizard
type="new"
wizardId="com.test.myWizard"
menuGroupId="testGroup">
<enablement>
<adapt type="org.eclipse.core.resources.IFolder">
<test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="myFacet:1.3" forcePluginActivation="true"/>
</adapt>
</enablement>
</commonWizard>
</extension>
The option in the New menu is displayed correctly, but it is displayed when I right click all folders, is there a way to display the option only when I right click a certain folder, specifically the WebContent folder?
You can use the org.eclipse.core.resources.name property tester to test the resource name:
<adapt type="org.eclipse.core.resources.IFolder">
<and>
<test property="org.eclipse.core.resources.name" value="WebContent"/>
<test property="org.eclipse.wst.common.project.facet.core.projectFacet" value="myFacet:1.3" forcePluginActivation="true"/>
</and>
</adapt>
On developing an eclipse plugin i created a command in the Manifest extensions with id crtc_v4.session with a default handler crtc_v4.handlers.StartSession , I added a handler in the manifest for this command this handler enables the command according to the variable crtc_v4.sessionvar.
The problem which appears on the console is :
!MESSAGE Conflicting handlers for crtc_v4.session: {crtc_v4.handlers.StartSession#98bc5c} vs {crtc_v4.handlers.StartSession#1265d09}
But it doesn't block running the plugin. I'm asking about the solution for this problem, and whether it affects the performance of my plugin in general ?
Edit :
The snippet that define the command :
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="crtc_v5.crtctoolbar">
<command
commandId="crtc_v5.session"
icon="icons/neutral.png"
label="Start Session"
style="push">
</command>
</toolbar>
</menuContribution>
The snippet that define the handler :
</extension>
<command
defaultHandler="crtc_v5.handlers.StartSession"
id="crtc_v5.session"
name="session">
</command>
</extension>
And here is the enablement against sessionvar :
<extension
point="org.eclipse.ui.handlers">
<handler
class="crtc_v5.handlers.StartSession"
commandId="crtc_v5.session">
<enabledWhen>
<with
variable="crtc_v5.sessionvar">
<equals
value="LOGGEDIN">
</equals>
</with>
</enabledWhen>
</handler>
You've defined a default handler in the command and another one in the org.eclipse.ui.handlers extension. If you want to use enabledWhen, simply remove the defaultHandler attribute (since both instances provide the same handler, crtc_v5.handlers.StartSession).
When you want to have different handlers provide the behaviour for your command depending on the application state, you would use activeWhen in the org.eclipse.ui.handlers definition, but that doesn't seem to be the case here.
I have a PPT Add-In which may fail if a certain ViewType is not maintained.
I do not see any PPTEvent which I could trap the change and prevent it (although, if this is possible, please advise!). So I have been playing with the Ribbon/CommandBars attempting to disable or hide certain controls pertaining to the ViewType.
I have identified the controls by Id and I attempt to set their .Visible property to False, or alternatively, to .Enabled = False, but neither seems to have any affect. The controls are still visible, and clicking on them still executes.
This example I would try to disable the Slide Sorter control. This prevents VBE from Execute the Button, but it does not disable the button's action as far as the user might still click it, it still executes.
Sub DisableViewChange()
Dim cBar As CommandBar
Dim ctrl As CommandBarControl
Set cBar = CommandBars("View")
Set ctrl = cBar.FindControl(Id:=738)
ctrl.Visible = True
ctrl.Enabled = False
Set btn = ctrl
btn.Execute
Set cBar = Nothing
Set btn = Nothing
Set ctrl = Nothing
End Sub
Update to include pics of the elements I would like to disable/hide/remove:
You can definitely modify the XML of a specific document to remove certain ribbon elements from the ribbon - I have done a huge amount of this. You should investigate using the Custom UI Editor which will open up the document and allow you to modify the XML of your selected ribbon groups by using the Visible = False modifier. Then, you should be able to save the Add-In and when it's loaded into memory it will hide the parts you've specified, preventing your crash.
This was useful for me a while ago:
http://gregmaxey.mvps.org/word_tip_pages/customize_ribbon_main.html
There are Microsoft XML Schemas for each of the Office applications (which I can't find now - but definitely exists).
I hope that's some help.
Red's suggestion above was very helpful. With some (errr... a lot) of trial and error, I was able to make some tweaks to the Ribbon. I present this answer in hopes that my trial and error will be useful to someone else who is equally unfamiliar with XML:
I disable several commands that I was looking to disable, that was relatively easy:
<commands>
<command idMso="ViewSlideSorterView" enabled="false"/>
<command idMso="ViewNotesPageView" enabled="false"/>
<command idMso="ViewSlideShowReadingView" enabled="false"/>
<command idMso="ViewSlideMasterView" enabled="false"/>
<command idMso="ViewHandoutMasterView" enabled="false"/>
<command idMso="ViewNotesMasterView" enabled="false"/>
<command idMso="WindowNew" enabled="false"/>
</commands>
Since I am fussing with the XML, I decide also to migrate my add-in's commands from a legacy CommandBar (under the Add-Ins Tab group) to a custom ribbon tab, so this XML also contains a working example of a new Tab, which consists of a Group, a menu, and a few buttons in that menu.
Here is the validated XML including the disabled commands and the custom tab menu:
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui">
<commands>
<command idMso="ViewSlideSorterView" enabled="false"/>
<command idMso="ViewNotesPageView" enabled="false"/>
<command idMso="ViewSlideShowReadingView" enabled="false"/>
<command idMso="ViewSlideMasterView" enabled="false"/>
<command idMso="ViewHandoutMasterView" enabled="false"/>
<command idMso="ViewNotesMasterView" enabled="false"/>
<command idMso="WindowNew" enabled="false"/>
</commands>
<ribbon startFromScratch="false">
<tabs>
<tab idMso="TabView">
<group idMso="GroupPresentationViews" visible="true"/>
<group idMso="GroupMasterViews" visible="true"/>
</tab>
<tab id="MyNewTab" label="My Tab Label">
<group id="MyGroupMain" label="My Group Label">
<menu id="MyMenu" imageMso="HappyFace" size="large">
<button id="MyLaunchButton" label="Launch Tiger" onAction="macro1" />
<button id="MyInfoButton" label="Info" onAction="macro2" />
<button id="MyVersionButton" label="Version" onAction="macro3" />
<button id="MyHelpButton" label="Help" onAction="macro4" />
</menu>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
I have not hooked my subroutines/macros in to these buttons yet, but that should not be terribly difficult.
I would not have been able to get through this without stumbling upon this link, which contains a batch of Excel files (for each Application) listing all of the menu items by type, id, relationship to other items, etc.
http://www.microsoft.com/en-us/download/details.aspx?id=6627
I have written a custom launcher in Eclipse which I can access via the "Run As" and "Debug As" menu options on the toolbar. I also want to be able to launch via the package explorer and via right clicking on the editor of a file to be launched. I followed the tutorial here to add the shortcut but nothing happens, it does not enter my handling code, nor does it complain regarding the configuration of the extension point.
Here is a snippet from my plugin.xml
<extension point="org.eclipse.debug.ui.launchShortcuts">
<shortcut
id = "org.mylauncher.launchCalcShortcut"
class = "org.mylauncher.LaunchCalcShortcut"
description="Execute calculations"
icon="icons/launch_16_16.png"
label="Calculate"
modes="run, debug" >
<configurationType id="org.mylauncher.launchCalc"/>
</shortcut>
I have also played with removing the (optional) icon attribute, and have separately validated the path of the icon.
I've been modifying this configuration for hours now with no good result and it is impossible to debug as it is not running in my own code at all.
Thanks.
It seems that the correct answer to this problem is to specify a contextual launch shortcut. Here is my working configuration:
<extension
point="org.eclipse.debug.ui.launchShortcuts">
<shortcut
class="com.xxxx.CalcLaunchShortcut"
icon="calc.png"
id="com.xxxx.CalcLaunchShortcut"
label="Calc"
modes="run, debug">
<contextualLaunch>
<contextLabel mode="run" label="Run Calculator" />
<contextLabel mode="debug" label="Debug Calculator" />
<enablement >
<with variable="selection">
<count value="1"/>
<iterate>
<adapt type="org.eclipse.core.resources.IResource">
<and>
<test property="org.eclipse.core.resources.name" value="*.calc"/>
</and>
</adapt>
</iterate>
</with>
</enablement>
</contextualLaunch>
</shortcut>