Key binding to popup menu item in eclipse Helios? - eclipse

In our project at work, they have written one plug-in for eclipse helios. They have used the
objectContribution for adding the popups and written respective action classes for them.
I am trying to add the shortcut key for one of the popup menu item in project explorer.
But I read here http://www.eclipse.org/forums/index.php/mv/tree/172398/#page_top that there is no way to call key bindings from objectContribution and need to migrate it to handlers/commands.
Is there any other way to bind keys to popups instead of migrate them to handlers?
Thanks in advance!!

No, objectContributions cannot accept keybindings. From legacy action extension points, only actionSets accept keybindings correctly.
The other option available (as mentioned) is to provide a handler for the command you want. The handler won't interfere with the objectContribution behaviour (the objectContribution action delegate class will still be called directly from the menu item, the handler would be called when using a keybinding).
PW

Related

Using IAction::setAccelerator does not work as expected

I face an issue regarding keyboard shortcuts using JFace IAction and setAccelerator(). My sample code:
menuAction.setAccelerator(SWT.CTRL | 'A');
The keyboard shortcut CtrlL+A is not recognised within my application.
To my knowledge, the accelerator property of an IAction only carries the information which key shortcut should be used.
The actual implementation that captures key shortcuts and executes matching actions is not part of JFace or at least not active by default. Some bits and pieces that are part of Platform/UI make it work in the workbench.
To see what is actually needed to make accelerators work in a standalone JFace application, you should follow the call to ExternalActionManager.ICallback::isAcceleratorInUse() in ActionContributionItem ~ line 825.
If this doesn't lead to a solution, you can still add a display filter to invoke the respective actions for a key shortcut (see also SWT Actions with Keyboard Shortcuts... without having to add them to the menu).
Don't forget to add this action menuAction to your menu manager and after applying all you stuffs you must to update the menu manager. Call updateAll(true) method on your menu manager. This update is required because the menu manager didn't notice your accelerator assignment yet!

In Eclipse, how can I view which ui class is active?

I know that there is a feature in Eclipse that shows the class name of the active element of the eclipse interface (for example, the class of the element selected with mouse). It is used to debug client plugin extensions, but I don't remember how to call it..
How can I get this feature? Which key combination I can use?
Thanks,
Michele.
You are probably thinking of the Plug-in Spy plug-in. Press Alt+Shift+F1 to see to details about the current selection. Alt+Shift+F2 lets to find out information about menu items.

Inject OnClick Event into running EXE

Is it possible with some program to to send an OnClick Event eg: MenuNewClick (File New) or others.
I have an application that has no Keyboard shortcuts.
When I use a Resource Editor I can see the Delphi Forms for each OnClick Event I need.
I would just like to be able to send these OnClick Events with Keyboard Shortcuts into the running exe.
Have used apps like Darker's Enabler, EDA Preview that allow you to modify the layout of a running exe.
Possible ?
Even this forum has options "Keyboard shortcuts
Enable keyboard shortcuts (when enabled, press ? for help)"
Thanks.
If the application is indeed made with Delphi and if it uses default TMainMenu component you could modify the RCData in which the .dfm is stored (this data alows you to view the form and its properties with programs like PE Exporer and similar) in a way that you change the AutoHotkeys property of TMainMenu to maAutomatic and then change ShortCut property of each menu item to contain proper keyboard shortcut.
If you have access to Delphi I recomend you first make an example application which will have all available shourctuts implemented so you could comparison the RCData between these two applications and made necessary changes.
NOTE: What I'm suggesting will require editing the EXE resource data so make sure you are working on a copy of the exe and not on the real one so you don't break your application.

Eclipse Plugin: How to modify the extension "org.eclipse.ui.newWizards"?

I have a wizard that should be launched in different ways: from the menu (org.eclipse.ui.menus + org.eclipse.ui.actionSets) and from the New context menu. For the later I used the extension org.eclipse.ui.newWizards to add the wizard into the context menu. So far, so good...
For some reasons I had to subclass the wizard dialog (changed the finish button text in the dialog). If the wizard is launched from the menu, the action (defined in org.eclipse.ui.actionSets) creates and opens this special wizard dialog and everything is fine.
If the wizard is launched from the context menu (org.eclipse.ui.newWizards), the internal class NewWizardShortcutAction is taken that creates the "normal" wizard dialog (and not my subclass) to open the wizard.
Is there any way to modify the implementation of the extension point that only my subclassed wizard dialog is used?
By default the command uses org.eclipse.ui.internal.handlers.WizardHandler.New to launch the new wizard dialog, and that's the default handler provided to the command.
It would be possible to register a different handler at the Workbench Window level, and that would override the default handler while a Workbench Window was active. It could be done in the plugin.xml or in your application ActionBarAdvisor:
IHandlerService hs = (IHandlerService) window.getService(IHandlerService.class);
hs.activateHandler(IWorkbenchCommandConstants.FILE_NEW, new MyNewHandler());
But you would have to implement whatever support was needed in the handler to launch the wizard with the correct selection.
I'm also trying to do the same. The way I will be doing this is to register my own custom action, by removing the old action, will post back the solution if it works !
Update: I ended up using a different approach. If you see the run method in NewWizardShortcutAction, it is just calling init, creating the WizardDialog and opening it. So in my override of the init in MyWizard class, I just used my own MyWizardDialog extending from WizardDialog and opened it. Subsequently, I need to make that the run function will not re-open the WizardDialog, so I track that using a boolean in MyWizard that will disallow getting any pages so that the WizardDialog in the run method will not be displayed.
This is a hacky solution but works !

Activate the activator class

I am using eclipse 3.6. I created one sample plugin application. It is neither a eclipse rcp nor workbench. Now when I run the eclipse I want that plugin also to be loaded. But I dont want to use IStartUp. Because what I have found out is
IStartup will be called after the workbench is loaded. I want to refresh some menu. So Is there any way to activate my plugin while the eclipse loaded?
I tried to use Bundle Activation policy. But that is also not activating my Activator class. I just put one System.out. println("Inside start()"). So that is not called. Now can I make it activate my activator?
EDIT:
what my exact requirement is, I have created one workbench application.It is not eclipse rcp application. Now I want to remove the following menu and menu items from the eclipse before the eclipe is loaded.
1. File Menu
2.) Search Menu
3.)Run Menu
4.)Help->search,Dynamic Help,Key assist,Tips and trick,Report Bug,Cheat Sheet.
These menus are inbuilt menu of eclipse. So that is the reason I have to do in this way.
So I already implemented by using startup extension point. But the early startup is called after the eclipse is started.So I need to do some refreshment on the workbench.Then only the menu item will get removed.So I thought I need startup extension point will not satisfy my requirement as it doesnot refresh the workbench.I need to activate the my plugin and refresh the workbench before it is loaded.
Thanks
Bhanu
You can set the needed start level for your plugin using touch point instruction.
You are just a plugin that expects to run in the Eclipse IDE?
Then the answer is, you cannot do what you want.
If you start before the workbench has finished initializing, most of the services that could be used won't work: The workbench itself, menu service, command service, etc.
For most plugins in eclipse, the plugin.xml should be used to add menus, views, editors, etc to eclipse. When necessary, the framework will instantiate them.
org.eclipse.ui.IStartup is available and as you mentioned it will be called after the workbench has been initialized, but before any windows have been shown. It's not to be used lightly, and not by plugins contributing to the UI as it allows all extension from that plugin to be loaded.
EDIT:
If you are an RCP app, you control the main menu. As an RCP app, you have access to the ActionBarAdvisor, WorkbenchAdvisor, WorkbenchWindowAdvisor, which all have lifecycle methods.
If you are an an eclipse plugin, you can add to the main menu ... you cannot easily remove from the main menu. This is by design. Start levels and org.eclipse.ui.startup are 2 mechanisms that won't do what you want.
You still need to answer these questions:
There might still be a way. The crux of your problem is: "I want to refresh some menu"
What kind of menu (popup, main menu,
compound list of menu items in a
menu, etc)?
Where is the menu contribution coming from?
Which specific menu item is it?
Please edit your question (do not comment) and include the information from the above 3 questions, please.