|
Re: Eclipse 4 undo/redo mechanism [message #1574395 is a reply to message #1573542] |
Tue, 20 January 2015 07:40 |
|
Hi,
I had the same "problem". My situation: I have a JFace SourceViewer based editor which needs undo/redo functionality.
I have created my own commands and handlers, f. e.:
import javax.inject.Inject;
import javax.inject.Named;
import org.eclipse.e4.core.di.annotations.CanExecute;
import org.eclipse.e4.core.di.annotations.Execute;
import org.eclipse.e4.core.services.adapter.Adapter;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.services.IServiceConstants;
import org.eclipse.jface.text.ITextOperationTarget;
public class UndoHandler {
@Inject
private Adapter _adapter;
@Execute
public void execute(@Named(IServiceConstants.ACTIVE_PART) final MPart part) {
final ITextOperationTarget opTarget = _adapter.adapt(part.getObject(),
ITextOperationTarget.class);
opTarget.doOperation(ITextOperationTarget.UNDO);
}
@CanExecute
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART) final MPart part) {
final ITextOperationTarget opTarget = _adapter.adapt(part.getObject(),
ITextOperationTarget.class);
if (opTarget == null)
return false;
boolean canDoOperation = opTarget.canDoOperation(ITextOperationTarget.UNDO);
return canDoOperation;
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03874 seconds