Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Updating undo/redo labels
Updating undo/redo labels [message #1041656] Mon, 15 April 2013 07:26 Go to next message
Cedric Moonen is currently offline Cedric Moonen
Messages: 269
Registered: August 2009
Senior Member
Hello,

In my application I have an undo and redo actions which are implemented. It works fine except that the label for the commands in the menu is not modified when an action is performed (e.g. displaying something like "Undo Typing").

This is how I declared them in the plugin.xml:

   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
            locationURI="menu:org.eclipse.ui.main.menu">
         <menu
               label="Edit">
            <command
                  commandId="org.eclipse.ui.edit.undo"
                  style="push">
            </command>
            <command
                  commandId="org.eclipse.ui.edit.redo"
                  label="Redo"
                  style="push">
            </command>
         </menu>
      </menuContribution>
   </extension>


In my ApplicationActionBarAdvisor I'm doing this:
	@Override
	protected void makeActions(IWorkbenchWindow window) {
		register(ActionFactory.UNDO.create(window));
		register(ActionFactory.REDO.create(window));
	}


In my editor class I have the following code:
	private UndoContext undoContext;
	private UndoRedoActionGroup undoRedoActionGroup;

        // Called in the init method of the editor
	protected void createGlobalActionHandlers() {
		undoContext = new ObjectUndoContext(this);
		undoRedoActionGroup = new UndoRedoActionGroup(this.getSite(),
				undoContext, true);
		IActionBars actionBars = getEditorSite().getActionBars();
		undoRedoActionGroup.fillActionBars(actionBars);
	}

	@Override
	public void setFocus() {
		undoRedoActionGroup.fillActionBars(getEditorSite().getActionBars());
	}

	public void executeOperation(IUndoableOperation operation) {
		try {
			IAdaptable info = getShellAdaptable();
			operation.addContext(undoContext);
			OperationHistoryFactory.getOperationHistory().execute(operation,
					null, info);
			undoRedoActionGroup.updateActionBars();
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


Each operation extends org.eclipse.core.commands.operations.AbstractOperation and specifies its label in the constructor (by calling the super type constructor).

What is missing in my code so that the labels of the operations are displayed in the menu ?

Thanks,
C├ędric
Re: Updating undo/redo labels [message #1043826 is a reply to message #1041656] Thu, 18 April 2013 03:02 Go to previous message
Cedric Moonen is currently offline Cedric Moonen
Messages: 269
Registered: August 2009
Senior Member
I've been trying to debug to see what was happening. The UndoActionHandler setText method is correctly called (with the correct text) and this delegates to a LabelRetargetAction which in the end (simplifying here) ends up calling the commandChanged method of the CommandContributionItem. The code is as follow:

	private ICommandListener getCommandListener() {
		if (commandListener == null) {
			commandListener = new ICommandListener() {
				public void commandChanged(CommandEvent commandEvent) {
					if (commandEvent.isHandledChanged()
							|| commandEvent.isEnabledChanged()
							|| commandEvent.isDefinedChanged()) {
						updateCommandProperties(commandEvent);
					}
				}
			};
		}
		return commandListener;
	}


So, in the nested commandChanged methdo you can see that the updateCommandProperties is called only if one of the 3 conditions is true. Unfortunately, the commandEvent which is passed in has its changedValues field set to 0, which means that none of the condition will be true and the command won't be updated (thus the text in the menu doesn't change).

Higher up in the call stack, the commandEvent is created like this:
					boolean enabledChanged = handlerEvent.isEnabledChanged();
					boolean handledChanged = handlerEvent.isHandledChanged();
					fireCommandChanged(new CommandEvent(Command.this, false,
							false, false, handledChanged, false, false, false,
							false, enabledChanged));


So the name changed value and description changed value are set to false.

Is this a bug ? Or am I doing something wrong here ? It is so deeply nested in the eclipse framework that it looks like a bug...

[Updated on: Thu, 18 April 2013 03:05]

Report message to a moderator

Previous Topic:Odd Behavior in Example RCP Projects
Next Topic:Custom visible-when in standalone RCP application
Goto Forum:
  


Current Time: Sun Jul 13 06:34:20 EDT 2014

Powered by FUDForum. Page generated in 0.02332 seconds