Eclipse: how do you add a key binding to an action on an editor context menu - eclipse-plugin

My custom Eclipse editor overrides createAction, where it registers an IAction with the editor. Then, in editorContextMenuAboutToShow I add this action to the menu.
Everything works fine, in that the action appears on the context menu within the editor; and I'm able to invoke the action from the menu itself.
Now, I'd like to add a key binding for this action. So far, I've added three extensions to my plugin.xml: a command, a binding, and a context. I can actually see the command/binding/context show up in the keys preference.
As for binding the command to my action, I've passed the command id declared in plugin.xml as the parameter to setActionDefinitionId after creating the action itself in createActions.
Needless to say, the key binding doesn't invoke the action - hence this question. What steps am I missing?

In a TextEditor-based editor, I had to touch these places in order to provide an action with a key binding:
define a command, key binding and scope (as you did)
set the actionDefinitionId to match the command id (as you did)
after creating the action in createActions(), I had to call setAction( myAction.getActionDefinitionId(), myAction );
set the scope in initializeKeyBindingScopes() with setKeyBindingScopes( new String[]{ "org.example.myScope" } );
Does that help?

Related

Does OutletService support dynamically adding component in button handler

i used this.outletService.add('BottomHeaderSlot', factory, OutletPosition.BEFORE); during the search button click handler to add a custom component in the BottomHeaderSlot. I intended to add searchOverlay under the header to add customized search behavior.
But my custom component is not shown under the header after calling outletService.add. I refered to this https://sap.github.io/cloud-commerce-spartacus-storefront-docs/outlets/ . Does outletService support dynamic adding component during runtime?
Following is my button handler
open(): void {
const factory = this.componentFactoryResolver.resolveComponentFactory<SearchOverlayComponent>(SearchOverlayComponent);
this.outletService.add('BottomHeaderSlot', <any>factory, OutletPosition.BEFORE);
this.cd.markForCheck();
That's a good question. At the moment it is a not a feature supported from our outlets.
A solution you could do is inject the component in a more static manner (either CMS or outlet when the app initializes like seen here https://github.com/SAP/cloud-commerce-spartacus-storefront/blob/develop/projects/storefrontlib/src/cms-components/asm/services/asm-enabler.service.ts)?
Your component could then be wrapped with an <ng-container *ngIf="open$ | async></ng-container> where open$ is an observable for the state of the search box. That way the component only appears in the dom when the searchbox is open.
The idea of dynamically adding a components through outlets is a good one we will keep in mind. I will open an issue on Github as an improvement.

How to hide the "Set Encoding..." menu in eclipse

Do you have any idea how to hide the Set Encoding menu in the Edit Menu? I had spend some hard time looking for a way to hide this menu.
I try to dig the plugin.xml in many plugins with no luck to look for this Set Encoding action command.
I can't get the action definition id from plug-in spy that I can use to hide this menu in my developed plugin. I only get the info below:
The active contribution item class:
org.eclipse.ui.texteditor.RetargetTextEditorAction
The contributing plug-in:
org.eclipse.ui.workbench.texteditor (3.5.1.r352_v20100105)
The org.eclipse.ui.edit.text.changeEncoding action is usually added to the Edit menu dynamically by the IEditorActionBarContributor specified for the contriubutorClass attribute of the declared org.eclipse.ui.editors extension point.
E.g. the org.eclipse.ui.DefaultTextEditor gets declared by the org.eclipse.ui.editors plugin itself, and specifies the class TextEditorActionContributor as the contriubutorClass. TextEditorActionContributor does add the ChangeEncoding action like so:
public void init(IActionBars bars) {
super.init(bars);
IMenuManager menuManager= bars.getMenuManager();
IMenuManager editMenu= menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
if (editMenu != null)
editMenu.add(fChangeEncodingAction);
}}
So to completely remove this action from the Edit menu, you would need to define your own editors by extending org.eclipse.ui.editors and providing you own implementation of IEditorActionBarContributor.
You must edit the perspective, right click on the toolbar in Eclipse and you should get a context menu with the alternative Customize perspective.... Then go to the tab Menu visibility and disable the menu item you want to hide.

JavaFX 2 define onChange listener in FXML

I am busy teaching myself FXML.
I'm doing this by following this example.
It's a simple text editor.
However, in the tutorial everything is Java code.
I myself am using FXML to seperate the view of the logic.
I currently face the following challenge:
I have defined an TextArea in my FXML like so:
<TextArea id="taTextArea" fx:id="taContent" wrapText="true" />
Usually you add action listeners using onAction="#actionName"
What I want to know is, how can I do something similar for text changes. So I can detect wether a save is needed, modify the status bar label etc.
I want to avoid having to attach the TextArea to a change listener in the init method of the controller(implementing Initializable).
Also.. when I complete this application, I will write a blog about it.
With the lacking FXML documentation, I think itll be helpfull to other newbies.
So I want my code to be as clean as possible.
EDIT 1
No progress yet. I need to know if theres a thing such as code completion in FXML
So I can check what kind of properties I can use in FXMl. There should be a textLength property. In the provided link the author uses lengthProperty.addListener. I need an FXML equivilant
You could use the onKeyPressed property:
onKeyPressed="#textChanged"
which calls the textChanged method in the specified controller.
For the second question: The best reference for FXML currently is the javadoc of JavaFX, since all properties are listed there.

Using a WiX custom action to set a property's value

I am modifying an existing WiX installer to handle updating an existing installation of one of our products. There are several values whose defaults are specified in properties. These properties are displayed to the user for editing and are then written to a custom configuration file by the existing installer.
My code needs to be smart enough to detect if it is doing a brand new install versus installing an older version. If it is doing a brand new install, it needs to set the properties to default values. But if it is doing an upgrade, the code needs to retrieve the valus of those properties from the existing configuration file and display those to the user.
From the reading I've done, it seems to me I need to use a type 51 custom action to set the properties. But how do I implement this custom action?
I'm thinking that I have to first define the custom action to put it in the custom action table, and then I need to stick a tag somewhere to call it. And then I need to define it.
How can I do this? What would some example code be?
After doing some more research into custom actions, I believe I've got all of this figured out. I added a <Binary> tag to the .wxs file to identify where the custom action resides. I then referenced the Binary tag's ID in the CustomAction. Finally, I added a Custom tag to the InstallExecuteSequence section that referenced the CustomAction tag by ID.
The final Custom tag mentioned above needs to go into the InstallUISequence section, not the InstallExecuteSequence section, as the custom action needs to be called before the dialog is displayed.
As for the implementation of the Custom Action itself, I added a new C# Custom Action library project to the solution. In there, I implemented a method, decorated with the [CustomAction] attribute. This method uses the values of properties stored in the Session object passed as a parameter to the method and determines the path of the current version's executable file. It then does the work needed to locate the values in the program's Configuration file that need to be preserved across versions and writes them to other properties for the upgrade script.
Example:
[CustomAction]
public static ActionResult SetProperty(Session session)
{
try
{
session.Log("Begin SetProperty action");
session["PROPERTY_NAME"] = "value"
}
catch (Exception exception)
{
session.Log("ERROR in custom action SetProperty {0}", exception.ToString());
return ActionResult.Failure;
}
return ActionResult.Success;
}
Read the following sections of WiX tutorial:
Extra Actions: gives an overview of how to add a Custom Action to MSI;
What's Not in the Book: provides an example how to implement a Custom Action in DLL.

How to find components within IWorkbenchPart?

I'm writing a plugin for a poorly-documented Eclipse RCP application and I need to add a listener to what I believe is a TreeViewer within a view. I have access to the IWorkbenchPart representing the view, but how can I get the TreeViewer it contains? I'd guess I need a method to return the child components (i.e. something equivalent to AWT's getComponents() method), but I see no such method.
If the part contains a TreeViewer then it is likely that this viewer been set as the ISelectionProvider for the IWorkbenchSite containing the view.
Therefore you could try the following using the IViewPart reference that you have:
IViewPart; // Your reference to the IViewPart instance
ISelectionProvider provider = part.getSite().getSelectionProvider(); //Hopefully the TreeViewer
provider.addSelectionChangedListener(yourListener);