Image Editor - On flip or rotate, ensure undo button visibility is updated.

This commit is contained in:
Alan Evans 2019-05-17 19:00:10 -03:00
parent 401e3687de
commit 9de420fde6

View File

@ -122,14 +122,12 @@ public final class EditorModel implements Parcelable, RendererContext.Ready {
return; return;
} }
UndoRedoStacks stacks = cropping ? cropUndoRedoStacks : undoRedoStacks; getActiveUndoRedoStacks(cropping).pushState(editorElementHierarchy.getRoot());
stacks.pushState(editorElementHierarchy.getRoot());
} }
public void undo() { public void undo() {
boolean cropping = isCropping(); boolean cropping = isCropping();
UndoRedoStacks stacks = cropping ? cropUndoRedoStacks : undoRedoStacks; UndoRedoStacks stacks = getActiveUndoRedoStacks(cropping);
undoRedo(stacks.getUndoStack(), stacks.getRedoStack(), cropping); undoRedo(stacks.getUndoStack(), stacks.getRedoStack(), cropping);
@ -138,7 +136,7 @@ public final class EditorModel implements Parcelable, RendererContext.Ready {
public void redo() { public void redo() {
boolean cropping = isCropping(); boolean cropping = isCropping();
UndoRedoStacks stacks = cropping ? cropUndoRedoStacks : undoRedoStacks; UndoRedoStacks stacks = getActiveUndoRedoStacks(cropping);
undoRedo(stacks.getRedoStack(), stacks.getUndoStack(), cropping); undoRedo(stacks.getRedoStack(), stacks.getUndoStack(), cropping);
@ -239,12 +237,20 @@ public final class EditorModel implements Parcelable, RendererContext.Ready {
} }
public void postEdit(boolean allowScaleToRepairCrop) { public void postEdit(boolean allowScaleToRepairCrop) {
if (isCropping()) { boolean cropping = isCropping();
if (cropping) {
ensureFitsBounds(allowScaleToRepairCrop); ensureFitsBounds(allowScaleToRepairCrop);
} }
UndoRedoStacks stacks = isCropping() ? cropUndoRedoStacks : undoRedoStacks; updateUndoRedoAvailableState(getActiveUndoRedoStacks(cropping));
updateUndoRedoAvailableState(stacks); }
/**
* @param cropping Set to true if cropping is underway.
* @return The correct stack for the mode of operation.
*/
private UndoRedoStacks getActiveUndoRedoStacks(boolean cropping) {
return cropping ? cropUndoRedoStacks : undoRedoStacks;
} }
private void ensureFitsBounds(boolean allowScaleToRepairCrop) { private void ensureFitsBounds(boolean allowScaleToRepairCrop) {
@ -536,23 +542,25 @@ public final class EditorModel implements Parcelable, RendererContext.Ready {
} }
public void rotate90clockwise() { public void rotate90clockwise() {
pushUndoPoint(); flipRotate(90, 1, 1);
editorElementHierarchy.flipRotate(90, 1, 1, visibleViewPort, invalidate);
} }
public void rotate90anticlockwise() { public void rotate90anticlockwise() {
pushUndoPoint(); flipRotate(-90, 1, 1);
editorElementHierarchy.flipRotate(-90, 1, 1, visibleViewPort, invalidate);
} }
public void flipHorizontal() { public void flipHorizontal() {
pushUndoPoint(); flipRotate(0, -1, 1);
editorElementHierarchy.flipRotate(0, -1, 1, visibleViewPort, invalidate);
} }
public void flipVertical() { public void flipVertical() {
flipRotate(0, 1, -1);
}
private void flipRotate(int degrees, int scaleX, int scaleY) {
pushUndoPoint(); pushUndoPoint();
editorElementHierarchy.flipRotate(0, 1, -1, visibleViewPort, invalidate); editorElementHierarchy.flipRotate(degrees, scaleX, scaleY, visibleViewPort, invalidate);
updateUndoRedoAvailableState(getActiveUndoRedoStacks(isCropping()));
} }
public EditorElement getRoot() { public EditorElement getRoot() {