Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Standard Undo menu item never enables
Standard Undo menu item never enables [message #540628] Wed, 16 June 2010 18:19 Go to next message
Joel is currently offline Joel
Messages: 16
Registered: October 2009
Junior Member
Hi, I added the standard undo/redo menu items to my menu, but when I add an IUndoableOperation to the global operation history, the undo menu item never enables as i would expect it to. What am i missing?

Here is my menu contribution with the undo/redo items:
         <menu
               label="Edit"
               mnemonic="E">
            <command
                  commandId="org.eclipse.ui.edit.undo"
                  style="push">
            </command>
            <command
                  commandId="org.eclipse.ui.edit.redo"
                  style="push">
            </command>
         </menu>

The items show up fine with their standard labels and even icons.

Here is the code that adds the operation to the history:
                        IWorkbench workbench = getSite().getWorkbenchWindow().getWorkbench();
                        IOperationHistory operationHistory = workbench.getOperationSupport().getOperationHistory();
                        IUndoContext undoContext = workbench.getOperationSupport().getUndoContext();
                        locationOp.addContext(undoContext);
                        OperationHistoryFactory.getOperationHistory().execute(locationOp, null, null);
                        operationHistory.execute(locationOp, null, null);


(edit: I also found through debug tracing that the UndoActionHandler is never created. I could create it myself, but then I don't know how I would add it to the menu with standard icon/label, as all my menus are command-contributed and thus no in-code menu creation can be used.)

Thanks in advance.

[Updated on: Wed, 16 June 2010 18:52]

Report message to a moderator

Re: Standard Undo menu item never enables [message #540795 is a reply to message #540628] Thu, 17 June 2010 11:59 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

Undo and Redo have not yet been fully converted to commands/handlers.
You need to create them in your ActionBarAdviror.

Check out what is done with undoAction in
org.eclipse.ui.internal.ide.WorkbenchActionBuilder

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Standard Undo menu item never enables [message #540896 is a reply to message #540795] Thu, 17 June 2010 14:53 Go to previous messageGo to next message
Joel is currently offline Joel
Messages: 16
Registered: October 2009
Junior Member
Hi, Paul, thanks for you reply. I'm afraid I can't create them in my ActionBarAdvisor because the Edit menu is contributed by my plugin and should only be visible in my plugin's perspective.

I did test adding it to the action bar advisor and it does work that way (i had to take it out). Is there a way to add them as an extension (action or command) and still get the standard functionality? Or a way to add it in my plugin activator?

The mixing of creating action extensions, creating actions in the ActionBarAdvisor, and creating commands, has been the biggest time waster and frustrator for me in my using the eclipse platform. Crying or Very Sad I wish there was a thorough resource on the in's and out's of mixing them (since one who dares to use the new-ish command framework is forced to do so).

Edit: So far, the closest I've come is to contribute the "undo" item as a command, using the predefined id (org.eclipse.ui.edit.undo), and have the commandHandler delegate to the UndoActionHandler (i have to create a new one for each event since the ctor takes a part and i don't know the part until handling the event). The problem with this is that the Undo item does not enable/disable, and does not append the operation label to "undo", e.g. "Undo delete selection".

[Updated on: Thu, 17 June 2010 15:41]

Report message to a moderator

Re: Standard Undo menu item never enables [message #541126 is a reply to message #540896] Fri, 18 June 2010 12:35 Go to previous messageGo to next message
Paul Webster is currently offline Paul Webster
Messages: 6859
Registered: July 2009
Location: Ottawa
Senior Member

you might be able to get away with simply registering the action and
disposing it in the ActionBarAdvisor. Does that help? for example,
only have:

undoAction = ActionFactory.UNDO.create(window);
register(undoAction);

redoAction = ActionFactory.REDO.create(window);
register(redoAction);

That sets up handlers for the undo/redo commands, but doesn't add them
to any MenuManagers.


re: state of the system. Visibility of actions, commands, and action
extension points goes:

1) Programmatic actions: This applies to MenuManagers and IActions
created in the ActionBarAdvisers for WorkbenchWindows, view dropdown
actions created from the IActionBars, and view programmatic actions
contributed to the MenuManager before registerContextMenu(*) is called.

2) org.eclipse.ui.menus (commands). These are applied after the
programmatic actions, and can see any separators or MenuManager supplied
in #1. menuContributions can also see each other.

3) action extension points. These are applied last. The can see menus
and separators from #1 and #2, but they can't see each other.

PW

--
Paul Webster
http://wiki.eclipse.org/Platform_Command_Framework
http://wiki.eclipse.org/Command_Core_Expressions
http://wiki.eclipse.org/Menu_Contributions
http://wiki.eclipse.org/Menus_Extension_Mapping
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/workbench.htm


Re: Standard Undo menu item never enables [message #541190 is a reply to message #540896] Fri, 18 June 2010 15:24 Go to previous message
Joel is currently offline Joel
Messages: 16
Registered: October 2009
Junior Member

I ended up just creating them in code in the ActionBarAdvisor and letting Undo/Redo be global as their created to be, always available for all perspectives. (We decided that'd be acceptable for the rest of the app to have the menu, since later we might want undo/redo for other modules.)

That is an interesting idea, registering them only. I'm not sure if i tried that. Will have to remember that if this comes up again. Thank you.
Previous Topic:Help --> About is never refreshed
Next Topic:Does not match outer scope rule error
Goto Forum:
  


Current Time: Thu Oct 23 05:19:54 GMT 2014

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

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