Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » global undo
global undo [message #444304] Mon, 13 February 2006 17:14 Go to next message
Martin Wood is currently offline Martin WoodFriend
Messages: 28
Registered: July 2009
Junior Member
Hello,

I've searched the archives and read as much as i can but i still cant figure out
how to get the undo and redo buttons to activate after performing an undoable
operation.

First I have the code in my ApplicationActionBarAdvisor which creates the undo /
redo buttons.

I have also created the action (which implements IWorkbenchWindowActionDelegate)
and operation. The action use the global undo context as seen below :

IUndoableOperation operation = new ClearLibraryOperation(window.getShell());

IOperationHistory operationHistory =
OperationHistoryFactory.getOperationHistory();

IWorkbench workbench = window.getWorkbench();

// Get global undo context
IUndoContext undoContext = workbench.getOperationSupport().getUndoContext();

operation.addContext(undoContext);

try
{
operationHistory.execute(operation, null, null);
}
catch (ExecutionException e)
{
//
}

The action is added to the application from within an actionSet definition in
plugin.xml, theyre not specifically view actions. So far this works fine, im
just confused as to how I get the menu buttons to do their thing.

Do i need to make the action a RetargetAction? and if so how does that affect
the declaration of actions within the plugin.xml ?

any help is greatly appreciated.

thanks,

Martin
Re: global undo [message #444330 is a reply to message #444304] Mon, 13 February 2006 22:04 Go to previous messageGo to next message
Martin Wood is currently offline Martin WoodFriend
Messages: 28
Registered: July 2009
Junior Member
Ok, well a minor update.

I notice that after I tried adding this in my view's createPartControl :

IUndoContext undoContext =
PlatformUI.getWorkbench().getOperationSupport().getUndoConte xt();

getViewSite().getActionBars().setGlobalActionHandler(ActionF actory.UNDO.getId(),
new UndoActionHandler(getSite(), undoContext));

getViewSite().getActionBars().setGlobalActionHandler(ActionF actory.REDO.getId(),
new RedoActionHandler(getSite(), undoContext));

as described in an earlier thread, then the menu items from undo / redo are
activated, but only when that view has the focus.

Is there any way to make the undo / redo menu items available no matter which
window has the focus?

I thought that using this 'global undo context' would provide for that but it
doesnt appear to..although i think that im really misunderstanding how this
system is supposed to work.

thanks,

Martin


Martin Wood wrote:
> Hello,
>
> I've searched the archives and read as much as i can but i still cant
> figure out how to get the undo and redo buttons to activate after
> performing an undoable operation.
Re: global undo [message #444338 is a reply to message #444330] Tue, 14 February 2006 05:59 Go to previous messageGo to next message
rick cameron is currently offline rick cameronFriend
Messages: 9
Registered: July 2009
Junior Member
Hi, Martin

I think you're trying to do the same thing I am - see my posting from 12/02.

It looks to me like the undo framework is oriented to each view or editor
having its own undo stack. Thus, the actions that are put on the menu defer
to the action handler in the active view/editor. If there is no action
handler for undo (resp. redo) in the active view/editor (or no operation to
undo/redo) the action, and therefore the menu item, is disabled.

If you want to have a single undo stack for the whole app, and have the menu
items always enabled when there is an operation to be undone or redone, I
think you'd have to write a different implementation of IAction that doesn't
defer to the active view/editor, but just queries the operation history
directly. As I said in my posting, you'd probably combine code from the
standard undo/redo actions and the standard action handlers.

If I get this going, I'll let you know.

Cheers

- rick

"Martin Wood" <flashdev@relivethefuture.com> wrote in message
news:dsqvp5$h0t$1@utils.eclipse.org...
> Ok, well a minor update.
>
> I notice that after I tried adding this in my view's createPartControl :
>
> IUndoContext undoContext =
> PlatformUI.getWorkbench().getOperationSupport().getUndoConte xt();
>
> getViewSite().getActionBars().setGlobalActionHandler(ActionF actory.UNDO.getId(),
> new UndoActionHandler(getSite(), undoContext));
>
> getViewSite().getActionBars().setGlobalActionHandler(ActionF actory.REDO.getId(),
> new RedoActionHandler(getSite(), undoContext));
>
> as described in an earlier thread, then the menu items from undo / redo
> are activated, but only when that view has the focus.
>
> Is there any way to make the undo / redo menu items available no matter
> which window has the focus?
>
> I thought that using this 'global undo context' would provide for that but
> it doesnt appear to..although i think that im really misunderstanding how
> this system is supposed to work.
>
> thanks,
>
> Martin
>
>
> Martin Wood wrote:
>> Hello,
>>
>> I've searched the archives and read as much as i can but i still cant
>> figure out how to get the undo and redo buttons to activate after
>> performing an undoable operation.
Re: global undo [message #444346 is a reply to message #444338] Tue, 14 February 2006 12:01 Go to previous messageGo to next message
Martin Wood is currently offline Martin WoodFriend
Messages: 28
Registered: July 2009
Junior Member
rick cameron wrote:
> Hi, Martin
>
> I think you're trying to do the same thing I am - see my posting from 12/02.

ah, yes.. my thunderbird based searching abilities didnt pick that up for some
reason.

> It looks to me like the undo framework is oriented to each view or editor
> having its own undo stack. Thus, the actions that are put on the menu defer
> to the action handler in the active view/editor. If there is no action
> handler for undo (resp. redo) in the active view/editor (or no operation to
> undo/redo) the action, and therefore the menu item, is disabled.

Yeah, thats about how i understand it as well.

> If you want to have a single undo stack for the whole app, and have the menu
> items always enabled when there is an operation to be undone or redone, I
> think you'd have to write a different implementation of IAction that doesn't
> defer to the active view/editor, but just queries the operation history
> directly. As I said in my posting, you'd probably combine code from the
> standard undo/redo actions and the standard action handlers.

ok, thanks for the ideas, i'll look into it some more as well and see what i
come up with.

The situation im aiming for is to have a global undo stack combined with local
undo for particular editors. So operations that are related to View A are always
available whereas operations that are related to Editor B are only available
when it is active.

Im thinking that i might need to use multiple contexts to achieve this, where
every view / editor uses the global context but can also specify its own
particular context.


> If I get this going, I'll let you know.

Please do. I'll also post here if i get any further.

thanks,

Martin
Re: global undo [message #444547 is a reply to message #444338] Fri, 17 February 2006 11:29 Go to previous message
Eclipse UserFriend
Originally posted by: daniel.megert.eclipse.org

rick cameron wrote:

>Hi, Martin
>
>I think you're trying to do the same thing I am - see my posting from 12/02.
>
>It looks to me like the undo framework is oriented to each view or editor
>having its own undo stack. Thus, the actions that are put on the menu defer
>to the action handler in the active view/editor. If there is no action
>handler for undo (resp. redo) in the active view/editor (or no operation to
>undo/redo) the action, and therefore the menu item, is disabled.
>
>
You're right, the story is per active part but those parts can all have
the same context (or in other words: undo stack). Important is that each
part registers the Undo/RedoActionHandler with that same context via
setGlobalActionHandler(...). If you only need a global context then
you're best bet is to use IOperationHistory.GLOBAL_UNDO_CONTEXT.

Dani

>If you want to have a single undo stack for the whole app, and have the menu
>items always enabled when there is an operation to be undone or redone, I
>think you'd have to write a different implementation of IAction that doesn't
>defer to the active view/editor, but just queries the operation history
>directly. As I said in my posting, you'd probably combine code from the
>standard undo/redo actions and the standard action handlers.
>
>If I get this going, I'll let you know.
>
>Cheers
>
>- rick
>
>"Martin Wood" <flashdev@relivethefuture.com> wrote in message
>news:dsqvp5$h0t$1@utils.eclipse.org...
>
>
>>Ok, well a minor update.
>>
>>I notice that after I tried adding this in my view's createPartControl :
>>
>>IUndoContext undoContext =
>> PlatformUI.getWorkbench().getOperationSupport().getUndoConte xt();
>>
>> getViewSite().getActionBars().setGlobalActionHandler(ActionF actory.UNDO.getId(),
>>new UndoActionHandler(getSite(), undoContext));
>>
>> getViewSite().getActionBars().setGlobalActionHandler(ActionF actory.REDO.getId(),
>>new RedoActionHandler(getSite(), undoContext));
>>
>>as described in an earlier thread, then the menu items from undo / redo
>>are activated, but only when that view has the focus.
>>
>>Is there any way to make the undo / redo menu items available no matter
>>which window has the focus?
>>
>>I thought that using this 'global undo context' would provide for that but
>>it doesnt appear to..although i think that im really misunderstanding how
>>this system is supposed to work.
>>
>>thanks,
>>
>>Martin
>>
>>
>>Martin Wood wrote:
>>
>>
>>>Hello,
>>>
>>>I've searched the archives and read as much as i can but i still cant
>>>figure out how to get the undo and redo buttons to activate after
>>>performing an undoable operation.
>>>
>>>
>
>
>
>
Previous Topic:Plugin In Editor and Squiggles
Next Topic:AbstractTextEditor and quickdiff
Goto Forum:
  


Current Time: Sun Dec 08 00:21:31 GMT 2024

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

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

Back to the top