Skip to content

Commit

Permalink
Added listener for undo to keep dirty flag updated
Browse files Browse the repository at this point in the history
Also made use of existing undo/redo actions in eclipse
Solves bug 1862

Use existing undo/redo menu alternatives
  • Loading branch information
Arvid Berg authored and egonw committed May 26, 2010
1 parent 46333f9 commit cd00e7e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -358,7 +360,7 @@ public void widgetDisposed( DisposeEvent e ) {

contextService.activateContext( "net.bioclipse.ui.contexts.JChemPaint" );

createUndoRedoHangler();
createUndoRedoHandler();
}

private void createPartListener() {
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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( ) {
Expand Down Expand Up @@ -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)) {
Expand Down

0 comments on commit cd00e7e

Please sign in to comment.