Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community Forums[HowTo] re-use key-binding in wizard?
https://www.eclipse.org/forums/index.php/mv/msg/143410/451588/#msg_451588
So, I have an RCP app, and a bunch of key-bindings, including (no surprise) CTRL-C, and related items.
I use them in my (non-textual) editor to copy model-objects -- works fine; I create the actions in
my ActionBarAdvisor, using org.eclipse.ui.actions.ActionFactory, and also there add them to my main
menu; and I have registered an EditorActionBarContributor to retarget them to the current editor.
I also use them in Text-areas of in-place editors to copy Text (also works fine; I copied and reused
the org.eclipse.ui.actions.TextActionHandler, oddly not part of RCP).
Now, I would like to use CTRL-C within a wizard, that is wholly independent of any editor or view,
and can come into existance when all editors and views are closed, so it has no posibility of having
a reference to the editor-site or the view-site, AFAIK. Alas, that seems to mean that I cannot use
CTRL-C, since it is "still" bound to my editor even though the modal wizard-dialog is open.
Is there a work-around for this?
thanks,
Paul]]>Paul E. Keyser2006-06-26T20:16:29-00:00Re: [HowTo] re-use key-binding in wizard?
https://www.eclipse.org/forums/index.php/mv/msg/143410/451643/#msg_451643
dialog context, or just use the dialog context. You can place your
keybinding for CTRL+C to your copy command in the dialog context (you
would use the child context to restrict your keybinding to your dialog
only).
Look at org.eclipse.ui.contexts and org.eclipse.ui.bindings (and
possibly org.eclipse.ui.commands).
So I added to my plugin.xml what I thought would be a "deletion" (per the description of
org.eclipse.ui.bindings: "If a binding does not define a command identifier, then it is a deletion
marker. This means that if all the conditions are met, it will cancel any bindings with the same
trigger in the same context.") -- like this:
Made no difference - the CTRL-C is still not even being received by my Key-Listener in the wizard.
I turned on tracing for key-bindings, and saw this, when I hit CTRL-L (opens my wizard) and then
CTRL-C:
BINDINGS >> Clearing cache
BINDINGS >> Cache miss
BINDINGS >> There are 1 deletion markers
BINDINGS >> Cache miss
BINDINGS >> There are 1 deletion markers
BINDINGS >> Cache miss
BINDINGS >> There are 1 deletion markers
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 620835924,
character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x6c, time = 620836145,
character = 0xc)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+L])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'com.mun.ist.my.commands.SelectCorpus',
parameters = {})
BINDINGS >> Cache miss
BINDINGS >> There are 1 deletion markers
BINDINGS >> Cache miss
BINDINGS >> There are 1 deletion markers
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x0, keyCode = 0x40000, time = 620839479,
character = 0x0)
KEYS >>> Listener.handleEvent(type = KeyDown, stateMask = 0x40000, keyCode = 0x63, time = 620840140,
character = 0x3)
KEYS >>> WorkbenchKeyboard.press(potentialKeyStrokes = [CTRL+C])
KEYS >>> WorkbenchKeyboard.executeCommand(commandId = 'org.eclipse.ui.edit.copy', parameters = {})
KEYS >>> not enabled
So, I'm confused -- there's no way (in wizard) for me to set the context, since there is no site
from which to get the IKeyBindingService, and the deletion does not "free up" the key-combo.
Paul]]>Paul E. Keyser2006-06-27T20:33:09-00:00Re: [HowTo] re-use key-binding in wizard?
https://www.eclipse.org/forums/index.php/mv/msg/143410/452010/#msg_452010
> Hmm -- OK, I went to org.eclipse.ui's plugin.xml, and found there:
> <key
> commandId="org.eclipse.ui.edit.copy"
> contextId="org.eclipse.ui.contexts.dialogAndWindow"
> sequence="M1+C"
> schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" />
>
But I thought the deal was that you wanted CTRL+C to work, with your
command, within the dialog? Since dialog beats dialogAndWindow, why not
define the keybinding and just point to your command:
While the dialog is open CTRL+C will point to your CopySomething command
instead of the org.eclipse.ui.edit.copy command.
Option 2 ... the copy command is still valid while your dialog is open.
Why not just supply a handler for it? When you create your dialog,
you should be able to get the global handler service from the workbench
.... workbench.getAdapter(IHandlerService.class) (in 3.2 it's called
getService(*)).
Then activate a handler for the org.eclipse.ui.edit.copy command.
org.eclipse.core.commands.AbstractHandler is a base implementation of
IHandler. Save the IHandlerActivation, and then when your dialog closes
deactivate that handler.
If the stars are aligned, this should give you a dialog copy command
that responds to CTRL+C while your dialog is up :-)
Later,
PW]]>Paul Webster2006-06-29T17:13:55-00:00Re: [HowTo] re-use key-binding in wizard?
https://www.eclipse.org/forums/index.php/mv/msg/143410/452037/#msg_452037
Since both options require that I write an IHandler, but the first opetion also required a bit of
plugin.xml, I decided to try Option 2 first (an option I hadn't been able to think of, since I had
never known about IHandlerService). I can get the IHandlerService, create what I think is a suitable
IHandler -- by extending the AbstractHandler you mention and implementing its execute() method by
simply running the action in question (have done this elsewhere, to handle F2 in the main app) --
save the IHandlerActivation returned by handlerService. activateHandler (id, handler), & call
handlerService. deactivateHandlers (Collection<IHandlerActivation>) in my perform{Cancel, Finish}
methods. But the handler.execute() is never called. I'm sure I've got the id right (I just copied it
from your email) and I also tried with F2, for which I have (as mentioned) a working handler in the
main app (so that id must be the right one), and it also fails, same way: handler.execute() is never
called.
I'll try the option 1, but am not sanguine ...
Any ideas?
thanks
Paul
Paul Webster wrote:
> But I thought the deal was that you wanted CTRL+C to work, with your
> command, within the dialog? Since dialog beats dialogAndWindow, why not
> define the keybinding and just point to your command:
>
> <key
> commandId="com.mun.ist.my.commands.CopySomething"
> contextId="org.eclipse.ui.contexts.dialog"
> schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
> sequence="M1+C"/>
>
> While the dialog is open CTRL+C will point to your CopySomething command
> instead of the org.eclipse.ui.edit.copy command.
>
> Option 2 ... the copy command is still valid while your dialog is open.
> Why not just supply a handler for it? When you create your dialog, you
> should be able to get the global handler service from the workbench ...
> workbench.getAdapter(IHandlerService.class) (in 3.2 it's called
> getService(*)).
>
> Then activate a handler for the org.eclipse.ui.edit.copy command.
> org.eclipse.core.commands.AbstractHandler is a base implementation of
> IHandler. Save the IHandlerActivation, and then when your dialog closes
> deactivate that handler.
>
>
> If the stars are aligned, this should give you a dialog copy command
> that responds to CTRL+C while your dialog is up :-)
>
> Later,
> PW]]>Paul E. Keyser2006-06-29T18:44:43-00:00Re: [HowTo] re-use key-binding in wizard?
https://www.eclipse.org/forums/index.php/mv/msg/143410/452437/#msg_452437
> id must be the right one), and it also fails, same way:
> handler.execute() is never called.
I looked into this. There is a default global handler for
org.eclipse.ui.edit.copy,
org.eclipse.ui.internal.handlers.WidgetMethodHandler:copy. When your
dialog contributes a global handler for copy, there are 2 global
handlers active at the same time, and the command framework disables
both of them.
The command framework looks at all handlers that say they are active,
and then picks one based on priority. The more specific the expression,
the higher the priority, and the one with the highest priority wins.
ex:
global handlers are 0
a handler tied to the active window is higher
a handler tied to the active part is higher
So an expression can get your handler for org.eclipse.ui.edit.copy
working in your dialog.
ex - I'm launching my dialog from an action (which has fWindow):
protected Control createDialogArea(Composite parent) {
handlerService = (IHandlerService) fWindow.getWorkbench()
.getService(IHandlerService.class);
AbstractHandler handler = new AbstractHandler() {
public Object execute(ExecutionEvent event)
throws ExecutionException {
System.out.println("Run my copy handler, or get fish-slapped");
return null;
}
};
activeHandler = handlerService.activateHandler(
"org.eclipse.ui.edit.copy", handler,
new ActiveShellExpression(getShell()));
return super.createDialogArea(parent);
}
public boolean close() {
handlerService.deactivateHandler(activeHandler);
activeHandler.getHandler().dispose();
return super.close();
}
Obviously, make sure your code is robust. But the ActiveShellExpression
(which is tied to my dialog shell) bumps my handler priority above 0.
Also, since the shell is disposed on a close, don't forget to deactivate
your handler.
Later,
PW]]>Paul Webster2006-07-05T16:17:38-00:00Re: [HowTo] re-use key-binding in wizard?
https://www.eclipse.org/forums/index.php/mv/msg/143410/452629/#msg_452629
>
> The command framework looks at all handlers that say they are active,
> and then picks one based on priority. The more specific the expression,
> the higher the priority, and the one with the highest priority wins.
>
> ex:
> global handlers are 0
> a handler tied to the active window is higher
> a handler tied to the active part is higher
>
> So an expression can get your handler for org.eclipse.ui.edit.copy
> working in your dialog.
>
Ah -- I did not think of that at all, thanks.
> ex - I'm launching my dialog from an action (which has fWindow):
>
> protected Control createDialogArea(Composite parent) {
> handlerService = (IHandlerService) fWindow.getWorkbench()
> .getService(IHandlerService.class);
> AbstractHandler handler = new AbstractHandler() {
> public Object execute(ExecutionEvent event)
> throws ExecutionException {
> System.out.println("Run my copy handler, or get fish-slapped");
> return null;
> }
> };
> activeHandler = handlerService.activateHandler(
> "org.eclipse.ui.edit.copy", handler,
> new ActiveShellExpression(getShell()));
> return super.createDialogArea(parent);
> }
>
Hmm -- are you in Eclipse 3.2? I ask, b/c in 3.1.2 (where I am), IHandlerService.activateHandler(,,
Expression) requires a fourth parameter, an int. (The javadocs to IHandlerService.activateHandler()
and IHandlerActivation.getSourcePriority() do not explain how values of that int will be
interpreted, but I guessed from your email that the more positive int is the higher priority.)
Logarithmic search through positive int's showed that 1000 (and smaller) fail, but that 10000 (and
larger) work, at least for "org.eclipse.ui.edit.copy" -- even Integer.MAX_VALUE fails for
"org.eclipse.ui.edit.delete", "org.eclipse.ui.edit.rename", and "org.eclipse.ui.newWizard". But in
the three cases for which the handler-mechanism fails, at least my key-listener works ('DEL', 'F2',
'CTRL-n').
thanks,
Paul]]>Paul E. Keyser2006-07-10T21:08:50-00:00