How to make a contributed Eclipse command key binding configurable? - eclipse

I'm assigning a key binding to my command in the plugin.xml:
<extension point="org.eclipse.ui.bindings">
<key commandId="MyCommand"
contextId="org.eclipse.ui.contexts.window"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+R"/>
</extension>
It works, but it doesn't show up in Preferences > Keys and therefore the user can't change it. How can I make it configurable?

By default, a command is filtered out from the key configuration preference page, unless it is categorized.
You can either disable this filtering using the "well-hidden" filter button on the bottom half of the Key configuration dialog, or you can define a category for your command.

Related

How to add condition checks in eclipse plugin.xml file?

I need to hide a menu item (File -> Exit) that is not relevant to me. I could do this using org.eclipse.ui.activities extension. The following code works great:
<activity
description="Capability to filter all menus not relevant to the product"
id="com.xxx.productspecific.filter.menus"
name="Common UI Filter for menus">
</activity>
<activityPatternBinding
activityId="com.xxx.productspecific.filter.menus"
isEqualityPattern="true"
pattern="org.eclipse.ui.file.exit">
</activityPatternBinding>`
Now I need to make this work based on some condition. I have a program argument (or command-line argument) "targetEnv=FDK". The menu should be hidden only when this argument is available. I tried the below snippet, but the menu items continue to be hidden no matter what I provide in the argument.
<activity
description="Capability to filter all menus not relevant to the product"
id="com.xxx.productspecific.filter.menus"
name="Common UI Filter for menus">
<enabledWhen>
<with
variable="%targetEnv">
<equals
value="FDK">
</equals>
</with>
</enabledWhen>
Is this the right way to use a program argument in plugin.xml?

Custom CEditor Eclipse CDT not recognized

How can I choose to use my implementation of CEditor instead of built in one?
<extension
id="highlighter.CustomEditor1"
point="org.eclipse.ui.editors">
<editor
default="true"
name="CustomCHighlightEditor"
extensions="c,cusc"
icon="icons/c_file_obj.gif"
class="highlighter.CustomEditor"
contributorClass="org.eclipse.cdt.internal.ui.editor.CEditorActionContributor"
symbolicFontName="org.eclipse.cdt.ui.editors.textfont"
id="highlighter.CustomEditorC">
</editor>
Is not working (no error, no changes). If I open a C file it's still opened with the old editor.
Edit:
When trying to change default editor like in this image:
It is only recognized for my created cusc extension like you see here:
So there have to be something that prevents to override the file association?
Also ceditor functionallity like folding or such things are missing in both filetypes :-/
EDIT: Works now, had some preference errors
Specializing Content type
If you want to have your editor opened by default for some specific C files, you need to define your own content types and then associate your editor with that specialized content type.
For example Ant extends the base xml content type to define an ant specific content type.
<extension
point="org.eclipse.core.contenttype.contentTypes">
<content-type
id="antBuildFile"
name="%antBuildFileContentType.name"
base-type="org.eclipse.core.runtime.xml"
file-names="build.xml"
file-extensions="macrodef,ent,xml,ant"
priority="normal">
<describer
class="org.eclipse.ant.internal.core.contentDescriber.AntBuildfileContentDescriber">
</describer>
</content-type>
</extension>
The key thing is that ant files can be .xml files, but something about its content makes it different. Look at AntBuildfileContentDescriber to see how Ant distinguishes a build file from a plain xml file.
If you then look at the plug-in XML for the ant UI, you will find the editor associated with the specialized content type.
Changing Default Editors
If you simply want to change which editor is used by default for a C file and there are multiple editors available, go to Preferences -> General -> Editors -> File Associations and select the file you want (*.c) and change the default editor.

Order of toolbar buttons in Eclipse Kepler

I'm trying to contribute to the same custom toolbar from two different plugin.xml files. Unfortunately I can't find a way to specify the order in which the buttons appear. The one that is supposed to be the last appears as the first button.
I already tried to specify the insertion position by using
...
MenuManager manager = new MenuManager(null, "my.toolbar.id");
IMenuService menuService = (IMenuService) getEditorSite().getService( IMenuService.class);
manager.add(new GroupMarker("testing"));
menuService.populateContributionManager(manager, "toolbar:my.toolbar.id?after=testing");
...
and in the plugin.xml
<extension point="org.eclipse.ui.menus">
<menuContribution locationURI="toolbar:my.toolbar.id?after=testing">
<toolbar id="my.toolbar.id">
<command ...
Does anybody have an idea what could be wrong?
I finally figured it out.
In the main plugin.xml file a separator has to be defined on the toolbar where the additional buttons are supposed to be inserted.
In the second plugin.xml file the toolbar contribution should look similar to this:
<extension
point="org.eclipse.ui.menus">
<menuContribution
locationURI="toolbar:my.toolbar.id?after=mainAdditions">
<!-- no toolbar element with id here-->
<command ...
</menuContribution>
where mainAdditions is the name of the separator.

How to unset marcro of netbean

I have clicked keyboad during I use netbean IDE, but I don't know which key and then it appar marcro set. Mean that create shortcut key in netbean. At those I create one shortcut key is I clicked key space + key inter
now my computer can't click the key space. When I click it not action.
As I think if we unset marcro it will work.
Please help me
Thank
Tools/Options/Editor/Macros
There you can define and edit macros and also set the shortcut (to none in your case)
If you want to delete an assigned shortcut in Netbeans got to: menu "Tools" --> option "Options" --> click icon "Keymap". Then search in the column "Shortcut" (can be ordered by clicking on the column header) for the shortcut you want to change.

How can I add a key binding for a quickMenu similar to the "Refactor" context menu in JDT?

I want to add a shortcut to my eclipse plugin to show a quick menu with existing bindings. It should work like the "Refactor" quick menu in JDT.
Shortcut for quick menu in JDT:
JDT quick menu:
I already added a binding and a command but it seems there is something missing. The Delete Something entry is also working for the context menu, just the shortcut to the quick menu is missing.
Does anybody how to do this?
<extension point="org.eclipse.ui.bindings">
<key
commandId="myplugin.refactoring.actions.DeleteSomething"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+5">
</key>
<key
commandId="myplugin.refactoring.quickMenu"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+9">
</key>
<extension point="org.eclipse.ui.commands">
<command
categoryId="myplugin.category.refactor"
description="Delete Something"
id="myplugin.refactoring.actions.DeleteSomething"
name="Extract Method">
</command>
<command
categoryId="myplugin.category.refactor"
id="myplugin.refactoring.quickMenu"
name="Show Refactor Quick Menu">
</command>
<category
id="myplugin.category.refactor"
name="Refactor">
</category>
You can also do it like this:
Add a command for the quick menu and set a default handler.
<command
defaultHandler="myplugin.refactoring.QuickmenuHandler"
id="myplugin.refactoring.quickMenu"
name="Show Refactor Quick Menu">
</command>
The handler should be able to create the menu. Something like this:
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
...
Menu menu = new Menu(some parent);
new MenuItem(menu, SWT.PUSH).setText("...");
menu.setVisible(true);
return null;
}
Add a shortcut to the command (as you did):
<key
commandId="myplugin.refactoring.quickMenu"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="M1+9">
</key>
Finally bind all of this together in the menu extension point:
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="popup:ch.arenae.dnp.frame.popup?after=additions">
<menu
commandId="myplugin.refactoring.quickMenu"
label="Refactor">
<command
commandId="<first refactoring command>"
style="push">
</command>
</menu>
...
</menuContribution>
The important point is the commandId attribute in the menu element. It is used to display the keyboard shortcut in the menu.
You can have a look at how JDT implements the same. For instance, when looking at the Eclipse 3.8.2 source code, you'll see interesting method:
org.eclipse.jdt.ui.actions.RefactorActionGroup.installQuickAccessAction()
which is called when Java editor is opened. This is were programmatic handler association with current editor takes place.
To summarize how it's done in JDT:
First, they have a command declaration in plugin.xml:
<command
name="%ActionDefinition.refactorQuickMenu.name"
description="%ActionDefinition.refactorQuickMenu.description"
categoryId="org.eclipse.jdt.ui.category.refactoring"
id="org.eclipse.jdt.ui.edit.text.java.refactor.quickMenu">
They declare a key binding:
<key
sequence="M2+M3+T"
commandId="org.eclipse.jdt.ui.edit.text.java.refactor.quickMenu"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"/>
They associate this command with a handler once editor is created. The handler itself (org.eclipse.jdt.internal.ui.actions.JDTQuickMenuCreator) takes care of filling the quick menu with items.
You don't have to associate a command with a handler programmatically - another option is using org.eclipse.ui.handlers extension point.