Standard main menu not reacting to own handler #714

CLOSED learning portal
Submitted 5 months ago

I have a question on how to add an undo/redo handler to the main menu of Eclipse IDE.

I use Eclipse SDK as base system and that environment has already undo and redo menu entries in the main menu under Edit. I have an editor which uses the Eclipse 3 API i.e. extends the class EditPart. Before reading this tutorial I extended the undo/redo functionality by adding handlers to the plugin.xml of my plug-in.

I added a handler in the file fragment.e4xmi which I registered in the plugin.xml of my plugin. I added a "Model Fragment for Application - handler" with a handler entry for undo and redo.

Questions:

  1. Where do I get the command ids from, i.e. org.eclipse.ui.edit.undo and org.eclipse.ui.edit.redo? I tried importing them in the imports section of the e4 model fragment. But the Find button for the Reference-ID does not find any command id except the ids I defined myself in the import section. Should it find the ids from the org.eclipse.ui plug-in, too and why is it not shown?

  2. The handler entry uses an e4 handler with the 2 annotated methods (@Execute and @CanExecute). For the command id of the handler I use the imported command id e.g. org.eclipse.ui.edit.undo. For the id of the handler I use my own id.

When I add an own menu (main menu or main toolbar) with the command id org.eclipse.ui.edit.undo then the buttons in the menu are enabled/disabled correctly as the state of my editor changes. But the main menu/main toolbar entries which are already added by the Eclipse SDK (see main menu Edit) are always disabled and do not reflect the editing state of my editor.

  1. What am I missing? For Copy/Cut/Paste it works and the main menu shows the editor state and for these commands I just added a handler with the corresponding Eclipse command id e.g. org.eclipse.ui.edit.copy.

I use Eclipse DSL Tools (includes Incubating components), Version: 2021-06 (4.20.0), Build id: 20210612-2011 while developing my plug-in and Eclipse e4 Tools verion 4.20.0.v20210427-1802.

Comments

  5 months ago

Hi Udo,

sorry for the missing reply, we were in "home summer vacation".

From your description it sounds like you did everything correctly. I have not personally tried this and unfortunately it is not part of the training so this goes beyond the support we offer for the training, as this channel is only for issues with the training content.

From a quick look into the undo / redo framework I looks like it is still using actions and therefore I guess it currently ignores the e4 commands. But verifying this or fixing it in the framework would require more time which we could, if desired, via consulting.

For now I would suggest to use e3 plug-in extensions unless this issue is very important for you.

Sorry for the answer, but looking into customer specific issue outside the training content is unfortunately not possible due to time constraints.

Best regards, Lars

Please login to write a comment.