Time for action – changing contexts

The context is the location in which this binding is valid. For commands that are visible everywhere—typically the kind of options in the default menu—they can be associated with the org.eclipse.ui.contexts.dialogAndWindow context. If the command should only be invoked from dialogs, then the org.eclipse.ui.contexts.dialog context would be used instead.

  1. Open the fragment.e4xmi of the com.packtpub.e4.clock.ui project.
  2. To enable the command only for dialogs, go to the Binding Context, and modify the Reference-ID to point to org.eclipse.ui.contexts.dialog.
  3. Run the Eclipse instance, and try the command with Cmd + 9 or Ctrl + 9 depending on platform. The command should not work unless a dialog is being shown. Open a dialog by navigating to the File | New | Other menu and then try Cmd + 9 or Ctrl + 9 again.

Note

If there is no change in the behavior, try cleaning the workspace of the target instance at launch, by going to the Run | Run… menu and choosing Clear on the workspace. This is sometimes necessary when making changes to the fragment.e4xmi file, as some extensions are cached and may lead to strange behavior.

What just happened?

Context scopes allow bindings to be valid for certain situations, such as when a dialog is open. This allows the same KeyBinding to be used for different situations, such as a Format operation—which may have a different effect in a Java editor than an XML editor for instance.

Since scopes are hierarchical, they can be specifically targeted for the contexts in which they may be used. The Java editor context is a sub-context of the general text editor, which in turn is a sub-context of the window context, which in turn is a sub-context of the windowAndDialog context.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.192.183