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 MenuItem. The difference between this and a Handled MenuItem is that Direct just contains a reference to the @Executable
class.
To add a new direct menu item, open the
Application.e4xmi
file and navigate to the Application | Windows | Trimmed Window | Main Menu | Menu (File). Right-click on the menu and choose Add child | Direct MenuItem. In the dialog shown, fill in the details, including the class URI link to theHelloHandler
, defined previously:ID:
com.packtpub.e4.application.directmenuitem.hello
Label:
Direct Hello
Class URI:
bundleclass://com.packtpub.e4.application/ com.packtpub.e4.application.handlers.HelloHandler
Run the application, choose File | Direct Hello to show the same message as before.
Keys can be bound to commands in an application, and can be enabled in one...