Skip to content
Snippets Groups Projects
Commit 172d0a12 authored by Paul McCarthy's avatar Paul McCarthy
Browse files

Sequences of changes recorded by the editor can now be grouped into a

single entity for undo/redo purposes.
parent 3eae4584
No related branches found
No related tags found
No related merge requests found
......@@ -57,6 +57,7 @@ class Editor(props.HasProperties):
# undone.
self._doneList = []
self._doneIndex = -1
self._inGroup = False
self._displayCtx.addListener('selectedImage',
self._name,
......@@ -98,7 +99,7 @@ class Editor(props.HasProperties):
old, new, offset = self._selection.getLastChange()
change = SelectionChange(image, offset, old, new)
self._do(change)
self._changeMade(change)
def getSelection(self):
......@@ -129,18 +130,37 @@ class Editor(props.HasProperties):
newVals[selectBlock] = oldVals[selectBlock]
change = ValueChange(image, offset, oldVals, newVals)
self._do(change)
self._applyChange(change)
self._changeMade( change)
def startChangeGroup(self):
self._inGroup = True
self._doneIndex += 1
self._doneList.append([])
def _do(self, change):
log.debug('Starting change group - merging subsequent '
'changes at index {} of {}'.format(self._doneIndex,
len(self._doneList)))
self._applyChange(change)
del self._doneList[self._doneIndex + 1:]
self._doneList.append(change)
def endChangeGroup(self):
self._inGroup = False
log.debug('Ending change group at {} of {}'.format(
self._doneIndex, len(self._doneList)))
self._doneIndex += 1
self.canUndo = True
self.canRedo = False
def _changeMade(self, change):
if self._inGroup:
self._doneList[self._doneIndex].append(change)
else:
del self._doneList[self._doneIndex + 1:]
self._doneList.append(change)
self._doneIndex += 1
self.canUndo = True
self.canRedo = False
log.debug('New change ({} of {})'.format(self._doneIndex,
len(self._doneList)))
......@@ -155,11 +175,16 @@ class Editor(props.HasProperties):
change = self._doneList[self._doneIndex]
self._revertChange(change)
if not isinstance(change, collections.Sequence):
change = [change]
for c in reversed(change):
self._revertChange(c)
self._doneIndex -= 1
self.canRedo = True
self._inGroup = False
self.canRedo = True
if self._doneIndex == -1:
self.canUndo = False
......@@ -172,12 +197,17 @@ class Editor(props.HasProperties):
len(self._doneList)))
change = self._doneList[self._doneIndex + 1]
if not isinstance(change, collections.Sequence):
change = [change]
self._applyChange(change)
for c in change:
self._applyChange(c)
self._doneIndex += 1
self.canUndo = True
self._inGroup = False
self.canUndo = True
if self._doneIndex == len(self._doneList) - 1:
self.canRedo = False
......
......@@ -262,7 +262,9 @@ class OrthoEditProfile(orthoviewprofile.OrthoViewProfile):
def _selModeLeftMouseDown(self, ev, canvas, mousePos, canvasPos):
self._editor.startChangeGroup()
if self.selectionMode == 'replace':
self._editor.getSelection().clearSelection()
......@@ -276,8 +278,15 @@ class OrthoEditProfile(orthoviewprofile.OrthoViewProfile):
self._applySelection( canvas, voxel)
self._makeSelectionAnnotation(canvas, voxel)
def _selModeLeftMouseUp(self, ev, canvas, mousePos, canvasPos):
self._editor.endChangeGroup()
def _deselModeLeftMouseDown(self, ev, canvas, mousePos, canvasPos):
self._editor.startChangeGroup()
voxel = self._getVoxelLocation(canvasPos)
self._applySelection( canvas, voxel, False)
self._makeSelectionAnnotation(canvas, voxel)
......@@ -286,7 +295,11 @@ class OrthoEditProfile(orthoviewprofile.OrthoViewProfile):
def _deselModeLeftMouseDrag(self, ev, canvas, mousePos, canvasPos):
voxel = self._getVoxelLocation(canvasPos)
self._applySelection( canvas, voxel, False)
self._makeSelectionAnnotation(canvas, voxel)
self._makeSelectionAnnotation(canvas, voxel)
def _deselModeLeftMouseUp(self, ev, canvas, mousePos, canvasPos):
self._editor.endChangeGroup()
def _selintModeMouseMove(self, ev, canvas, mousePos, canvasPos):
......@@ -295,6 +308,8 @@ class OrthoEditProfile(orthoviewprofile.OrthoViewProfile):
def _selintModeLeftMouseDown(self, ev, canvas, mousePos, canvasPos):
self._editor.startChangeGroup()
self._editor.getSelection().clearSelection()
self._selecting = True
self._lastDist = 0
......@@ -360,4 +375,5 @@ class OrthoEditProfile(orthoviewprofile.OrthoViewProfile):
def _selintModeLeftMouseUp(self, ev, canvas, mousePos, canvasPos):
self._editor.endChangeGroup()
self._selecting = False
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment