Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Undo/Redo not working properly with multiple documents
Undo/Redo not working properly with multiple documents [message #760364] Fri, 02 December 2011 02:53 Go to next message
Eclipse UserFriend
I implemented an undo/redo mechanism following a tutorial and some discussion on the forums.
My solution is working fine if I have one document open: my operations can be executed and undone/redone properly, everything working as expected. As soon as I open a second editor and switch back to the first editor, all my operations are lost. If I now execute an operation in my second editor and switch back to my first editor, I can undo this operation even if the focus is on the first editor.

So, it seems that switching to another editor doesn't change the "active" context in the OperationHistory.

My code is as follow:

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"
                  label="Undo"
                  style="push">
            </command>
            <command
                  commandId="org.eclipse.ui.edit.redo"
                  label="Redo"
                  style="push">
            </command>
         </menu>
      </menuContribution>


ApplicationActionBarAdvisor.java
	@Override
	protected void makeActions(IWorkbenchWindow window) {
		register(ActionFactory.UNDO.create(window));
		register(ActionFactory.REDO.create(window));
	}


Editor class (createGlobalActionHandlers is called in my init method):
	protected void createGlobalActionHandlers() {
		undoContext = new ObjectUndoContext(this);
		undoRedoActionGroup = new UndoRedoActionGroup(this.getSite(),
				undoContext, true);
		IActionBars actionBars = getEditorSite().getActionBars();
		undoRedoActionGroup.fillActionBars(actionBars);
	}

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


Do I need to do something special in the setFocus (and eventually dispose) method in order to notify the OperationHistory that the context changed ? I though this was done automatically by the framework.
Re: Undo/Redo not working properly with multiple documents [message #760433 is a reply to message #760364] Fri, 02 December 2011 06:13 Go to previous messageGo to next message
Eclipse UserFriend
I finally found a working solution: in the editor setFocus method, I add the following code:
	@Override
	public void setFocus() {
		undoRedoActionGroup.fillActionBars(getEditorSite().getActionBars());
	}
Re: Undo/Redo not working properly with multiple documents [message #761445 is a reply to message #760433] Tue, 06 December 2011 08:41 Go to previous message
Eclipse UserFriend
Just as an aside, you should not do anything in the part setFocus() method other than determine which control gets focus. It is called if you click on a part tab, not if you click in a control in the part.

PW
Previous Topic:How to use 'ASTParser' on RCP
Next Topic: How to control the minimized view docking place?
Goto Forum:
  


Current Time: Mon Nov 03 15:53:07 EST 2025

Powered by FUDForum. Page generated in 0.04189 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top