Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added: "Record Undo" option.

"Record Undo" is reset when loading or saving a level.
Long undo operations can be canceled.
  • Loading branch information...
commit 963d2a728c28a976ddb58972f0c15480aede8914 1 parent c5e5ceb
@codewarrior0 codewarrior0 authored
View
1  editortools/brush.py
@@ -853,7 +853,6 @@ def mouseUp(self, evt, pos, direction):
self.editor.level,
self.draggedPositions,
self.getBrushOptions())
- self.performWithRetry(op)
box = op.dirtyBox()
self.editor.addOperation(op)
View
21 editortools/clone.py
@@ -193,13 +193,16 @@ def dirtyBox(self):
return self._dirtyBox
def perform(self, recordUndo=True):
- if recordUndo:
- chunks = set()
- for op in self.blockCopyOps:
- chunks.update(op.dirtyBox().chunkPositions)
- self.undoLevel = self.extractUndoChunks(self.level, chunks)
- [i.perform(False) for i in self.blockCopyOps]
- [i.perform(recordUndo) for i in self.selectionOps]
+ with setWindowCaption("COPYING - "):
+ self.editor.freezeStatus("Copying %0.1f million blocks" % (float(self._dirtyBox.volume) / 1048576.,))
+ if recordUndo:
+ chunks = set()
+ for op in self.blockCopyOps:
+ chunks.update(op.dirtyBox().chunkPositions)
+ self.undoLevel = self.extractUndoChunks(self.level, chunks)
+
+ [i.perform(False) for i in self.blockCopyOps]
+ [i.perform(recordUndo) for i in self.selectionOps]
def undo(self):
super(CloneOperation, self).undo()
@@ -955,10 +958,6 @@ def confirm(self):
self.editor.toolbar.selectTool(-1) # deselect tool so that the clone tool's selection change doesn't update its schematic
- with setWindowCaption("COPYING - "):
- self.editor.freezeStatus("Copying %0.1f million blocks" % (float(destVolume) / 1048576.,))
- self.performWithRetry(op)
-
self.editor.addUnsavedEdit()
self.editor.addOperation(op)
View
6 editortools/editortool.py
@@ -293,9 +293,3 @@ def hidePanel(self):
self.panel.parent.remove(self.panel)
self.panel = None
- def performWithRetry(self, op, recordUndo=True):
- try:
- op.perform(recordUndo)
- except MemoryError:
- self.editor.invalidateAllChunks()
- op.perform(recordUndo)
View
1  editortools/fill.py
@@ -244,7 +244,6 @@ def confirm(self):
blocksToReplace = []
op = BlockFillOperation(self.editor, self.editor.level, self.selectionBox(), self.blockInfo, blocksToReplace)
- self.performWithRetry(op)
self.editor.addOperation(op)
View
1  editortools/filter.py
@@ -403,7 +403,6 @@ def confirm(self):
op = FilterOperation(self.editor, self.editor.level, self.selectionBox(), filterModule, self.panel.filterOptionsPanel.options)
self.editor.level.showProgress = showProgress
- self.performWithRetry(op)
self.editor.addOperation(op)
self.editor.addUnsavedEdit()
View
7 editortools/operation.py
@@ -2,6 +2,7 @@
import os
import shutil
import tempfile
+import albow
from pymclevel import BoundingBox
import numpy
from albow.root import Cancel
@@ -57,7 +58,11 @@ def _extractUndo():
undoLevel.saveInPlace()
if chunkCount > 25 or chunkCount < 1:
- showProgress("Recording undo...", _extractUndo())
+ if "Canceled" == showProgress("Recording undo...", _extractUndo(), cancel=True):
+ if albow.ask("Continue with undo disabled?", ["Continue", "Cancel"]) == "Cancel":
+ raise Cancel
+ else:
+ return None
else:
exhaust(_extractUndo())
View
15 editortools/select.py
@@ -401,7 +401,6 @@ def nudgeBlocks(self, dir):
dir = dir * (16, 16, 16)
op = NudgeBlocksOperation(self.editor, self.editor.level, self.selectionBox(), dir)
- self.performWithRetry(op)
self.editor.addOperation(op)
self.editor.addUnsavedEdit()
@@ -416,8 +415,7 @@ def nudgeSelection(self, dir):
return
op = NudgeSelectionOperation(self, dir)
- self.performWithRetry(op)
- # self.editor.addOperation(op)
+ self.editor.addOperation(op)
def nudgePoint(self, p, n):
if self.selectionBox() is None:
@@ -608,7 +606,6 @@ def mouseUp(self, evt, pos, direction):
o, m = self.selectionPointsFromDragResize()
op = SelectionOperation(self, (o, m))
- self.performWithRetry(op)
self.editor.addOperation(op)
self.dragResizeFace = None
@@ -622,13 +619,12 @@ def mouseUp(self, evt, pos, direction):
if self.dragStartPoint != pos or self.clickSelectionInProgress:
op = SelectionOperation(self, (self.dragStartPoint, pos))
- self.performWithRetry(op)
self.editor.addOperation(op)
self.selectionInProgress = False
self.currentCorner = 1
self.clickSelectionInProgress = False
self.dragStartPoint = None
-
+
else:
points = self.getSelectionPoints()
if not all(points):
@@ -639,7 +635,6 @@ def mouseUp(self, evt, pos, direction):
self.clickSelectionInProgress = True
else:
op = SelectionOperation(self, points)
- self.performWithRetry(op)
self.editor.addOperation(op)
self.selectOtherCorner()
@@ -947,12 +942,10 @@ def selectNone(self):
def selectAll(self):
box = self.editor.level.bounds
op = SelectionOperation(self, self.selectionPointsFromBox(box))
- self.performWithRetry(op)
self.editor.addOperation(op)
def deselect(self):
op = SelectionOperation(self, None)
- self.performWithRetry(op)
self.editor.addOperation(op)
def setSelectionPoint(self, pointNumber, newPoint):
@@ -996,14 +989,13 @@ def deleteBlocks(self):
else:
self._deleteBlocks()
- def _deleteBlocks(self, recordUndo=True):
+ def _deleteBlocks(self):
box = self.selectionBox()
if None is box:
return
op = BlockFillOperation(self.editor, self.editor.level, box, self.editor.level.materials.Air, [])
with setWindowCaption("DELETING - "):
self.editor.freezeStatus("Deleting {0} blocks".format(box.volume))
- self.performWithRetry(op, recordUndo)
self.editor.addOperation(op)
self.editor.invalidateBox(box)
@@ -1030,7 +1022,6 @@ def undo(self):
editor.renderer.invalidateEntitiesInBox(box)
op = DeleteEntitiesOperation(self.editor, self.editor.level)
- self.performWithRetry(op, recordUndo)
if recordUndo:
self.editor.addOperation(op)
self.editor.addUnsavedEdit()
View
23 leveleditor.py
@@ -55,7 +55,7 @@
from OpenGL import GL
from OpenGL import GLU
-from albow import alert, ask, AttrRef, Button, Column, get_font, Grid, input_text, IntField, Menu, root, Row, TableColumn, TableView, TextField, TimeField, Widget
+from albow import alert, ask, AttrRef, Button, Column, get_font, Grid, input_text, IntField, Menu, root, Row, TableColumn, TableView, TextField, TimeField, Widget, CheckBox
from albow.controls import Label, SmallValueDisplay, ValueDisplay
from albow.dialogs import Dialog, QuickDialog, wrapped_label
from albow.openglwidgets import GLOrtho, GLViewport
@@ -1488,8 +1488,10 @@ def showViewOptions():
self.viewportButton = Button("Camera View", action=self.swapViewports,
tooltipText="Shortcut: TAB")
+ self.recordUndoButton = mceutils.CheckBoxLabel("Record Undo", ref=AttrRef(self, 'recordUndo'))
+
row = (mcEditButton, viewDistanceDown, Label("View Distance:"), viewDistanceReadout, viewDistanceUp,
- readoutGrid, viewButton, self.viewportButton)
+ readoutGrid, viewButton, self.viewportButton, self.recordUndoButton)
# row += (Button("CR Info", action=self.showChunkRendererInfo), )
row = Row(row)
@@ -1948,6 +1950,7 @@ def loadFile(self, filename):
self.undoStack = []
self.loadLevel(level)
+ self.recordUndo = True
self.clearUnsavedEdits()
self.renderer.position = self.currentViewport.cameraPosition
@@ -2098,6 +2101,7 @@ def saveFile(self):
self.freezeStatus("Saving...")
self.level.saveInPlace()
+ self.recordUndo = True
self.clearUnsavedEdits()
def addUnsavedEdit(self):
@@ -2131,7 +2135,7 @@ def clearUnsavedEdits(self):
def saveInfoLabelText(self):
if self.unsavedEdits == 0:
return ""
- return "{0} unsaved edits. CTRL-S to save. ".format(self.unsavedEdits)
+ return "{0} unsaved edits. CTRL-S to save. {1}".format(self.unsavedEdits, "" if self.recordUndo else "(UNDO DISABLED)")
@property
def viewDistanceLabelText(self):
@@ -3357,7 +3361,18 @@ def selectionChanged(self):
self.currentTool.selectionChanged()
def addOperation(self, op):
- self.undoStack.append(op)
+ if self.recordUndo:
+ self.undoStack.append(op)
+ self.performWithRetry(op)
+
+ recordUndo = True
+
+ def performWithRetry(self, op):
+ try:
+ op.perform(self.recordUndo)
+ except MemoryError:
+ self.invalidateAllChunks()
+ op.perform(self.recordUndo)
def quit(self):
self.mouseLookOff()
Please sign in to comment.
Something went wrong with that request. Please try again.