Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added listener for undo to keep dirty flag updated

Also made use of existing undo/redo actions in eclipse
Solves bug 1862

Use existing undo/redo menu alternatives
  • Loading branch information...
commit cd00e7e8cd590cf0d0dd415cd6487e01c230a8e0 1 parent 46333f9
Arvid Berg authored committed
View
17 plugins/net.bioclipse.cdk.jchempaint/src/net/bioclipse/cdk/jchempaint/editor/JChemPaintEditor.java
@@ -90,6 +90,8 @@
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.commands.ICommandService;
import org.eclipse.ui.contexts.IContextService;
+import org.eclipse.ui.operations.UndoActionHandler;
+import org.eclipse.ui.operations.UndoRedoActionGroup;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.ui.part.FileEditorInput;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
@@ -358,7 +360,7 @@ public void widgetDisposed( DisposeEvent e ) {
contextService.activateContext( "net.bioclipse.ui.contexts.JChemPaint" );
- createUndoRedoHangler();
+ createUndoRedoHandler();
}
private void createPartListener() {
@@ -408,13 +410,12 @@ public void partVisible( IWorkbenchPartReference partRef ) {
}
- private void createUndoRedoHangler() {
- // set up action handlers
- UndoHandler undoAction = new UndoHandler();
- RedoHandler redoAction = new RedoHandler();
- IActionBars actionBars = this.getEditorSite().getActionBars();
- actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),undoAction);
- actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(), redoAction);
+ private void createUndoRedoHandler() {
+ IEditorSite site = getEditorSite();
+ UndoRedoActionGroup actionGroup = new UndoRedoActionGroup( site,
+ widget.getUndoContext(),
+ true );
+ actionGroup.fillActionBars( site.getActionBars() );
}
private void createMenu() {
View
28 plugins/net.bioclipse.cdk.jchempaint/src/net/bioclipse/cdk/jchempaint/widgets/JChemPaintEditorWidget.java
@@ -40,8 +40,10 @@
import org.apache.log4j.Logger;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.commands.operations.IOperationHistory;
+import org.eclipse.core.commands.operations.IOperationHistoryListener;
import org.eclipse.core.commands.operations.IUndoContext;
import org.eclipse.core.commands.operations.IUndoableOperation;
+import org.eclipse.core.commands.operations.OperationHistoryEvent;
import org.eclipse.core.commands.operations.OperationHistoryFactory;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.ListenerList;
@@ -297,6 +299,29 @@ protected boolean shouldCreateToolTip( Event event ) {
prefListener = new GenerateLabelPrefChangedLisener( this );
Activator.getDefault().getPreferenceStore().addPropertyChangeListener( prefListener );
+ addUndoRedoListener();
+ }
+
+ private void addUndoRedoListener() {
+ operationHistory.addOperationHistoryListener(new IOperationHistoryListener() {
+
+ public void historyNotification(OperationHistoryEvent event) {
+ if(operationHistory.canUndo(undoContext)) {
+ setDirty(true);
+ }else setDirty(false);
+
+ if(!isDisposed()) {
+ Display.getDefault().asyncExec(new Runnable() {
+ public void run() {
+ hub.getRenderModel().setSelection( AbstractSelection.EMPTY_SELECTION );
+ hub.select( AbstractSelection.EMPTY_SELECTION );
+ structureChanged();
+ redraw();
+ }
+ });
+ }
+ }
+ });
}
private void setupControllerHub( ) {
@@ -796,6 +821,9 @@ public void undo() throws ExecutionException {
}
}
+ public IUndoContext getUndoContext() {
+ return undoContext;
+ }
public void redo() throws ExecutionException {
if (this.operationHistory.canRedo(this.undoContext)) {
Please sign in to comment.
Something went wrong with that request. Please try again.