Although using commands and handlers provides a generic way for reusing content, it is possible to provide a shorter route to implementing menus with a Direct Menu Item. The difference between this and a Handled Menu Item is that Direct Menu Item contains a direct reference to the @Executable
class, instead of indirect through a handler.
Application.e4xmi
file and navigate to the Application | Windows and Dialogs | Trimmed Window | Main Menu | Menu (File). Right-click on the menu and choose Add child | Direct Menu Item. In the dialog shown, fill in the following details, including the class URI link to the HelloHandler
, defined previously:com.packtpub.e4.application.directmenuitem.hello
Direct Hello
bundleclass://com.packtpub.e4.application/com.packtpub.e4.application.handlers.HelloHandler
Application.e4xmi
and navigate to the Application | BindingTables | BindingTable – In Dialog and Windows node. Right-click on the binding table and choose Add child | KeyBinding. Fill in the fields as follows:com.packtpub.e4.application.keybinding.m1l
M1+L
helloCommand - com.packtpub.e4.application.command.hello
Hello
command will be run.A Direct Menu Item is a way of hooking up a Menu Item directly to an executable method in a very simple way, without needing to have a separate command and handler defined. For application-wide operations, such as quitting the application, using a Direct Menu Item may be appropriate.
However, if the command needs to be handled in different contexts, then it is more appropriate to define a handler which can be replaced in different scopes.
Unlike a Handled Menu Item, the Direct Menu Item cannot have command parameters associated with it. Nor can a Direct Menu Item have a keybinding assigned.
To associate a keybinding with a command, an associated context must be selected. This is typically the In Dialogs and Windows context, although other contexts can be selected as well (such as In Dialogs and In Windows). These are stored in the Binding Table node in the Application.e4xmi
file.
The sequence can be a single character, or it can be a sequence of characters. Combinations of characters are represented with a +
joining them. The meta characters (M1
, M2
, M3
, M4
, and so on) are defined in the org.eclipse.ui.bindings
extension point:
M1
is the Cmd key on macOS and the Ctrl key on WindowsM2
is the Shift key on all platformsM3
is the Alt key on all platformsM4
is the Cmd key on macOSWhen the binding is invoked, it will execute the command specified in the list. As a command, it can have associated parameters like the Handled Menu Items.
3.133.109.30