Use session.beginSimpleCommand in a few places

This commit is contained in:
David Vierra 2017-07-02 12:46:31 -10:00
parent acdc51b88e
commit 0cf53710d8
3 changed files with 15 additions and 44 deletions

View File

@ -202,10 +202,6 @@ class ReplaceValueTagType(object):
DOUBLE = 7
class NBTReplaceCommand(SimpleRevisionCommand):
pass
class FindReplaceNBTResults(QtGui.QWidget, Ui_findNBTResults):
pass
@ -565,12 +561,9 @@ class FindReplaceNBT(QtGui.QWidget, Ui_findNBTWidget):
yield
command = NBTReplaceCommand(self.editorSession, "Replace NBT data") # xxx replace details
with command.begin():
with self.editorSession.beginSimpleCommand(self.tr("Replace NBT data")):
showProgress("Replacing NBT data...", _replace())
self.editorSession.pushCommand(command)
def replaceAll(self):
self.replaceEntries(self.resultsModel.results)

View File

@ -334,45 +334,36 @@ class InspectorWidget(QtGui.QWidget, Ui_inspectorWidget):
if self.currentChunk.TerrainPopulated == value:
return
command = InspectPropertyChangeCommand(self.editorSession,
self.tr("Change chunk (%s, %s) property TerrainPopulated")
% self.currentChunk.chunkPosition)
with command.begin():
with self.editorSession.beginSimpleCommand(self.tr("Change chunk (%s, %s) property TerrainPopulated")
% self.currentChunk.chunkPosition):
self.currentChunk.TerrainPopulated = value
self.editorSession.pushCommand(command)
def lightPopulatedDidChange(self, value):
if self.currentChunk.rootTag["Level"]["LightPopulated"].value == value:
return
command = InspectPropertyChangeCommand(self.editorSession,
self.tr("Change chunk (%s, %s) property LightPopulated")
% self.currentChunk.chunkPosition)
with command.begin():
with self.editorSession.beginSimpleCommand(self.tr("Change chunk (%s, %s) property LightPopulated")
% self.currentChunk.chunkPosition):
self.currentChunk.rootTag["Level"]["LightPopulated"].value = value
self.editorSession.pushCommand(command)
def inhabitedTimeDidChange(self, value):
if self.currentChunk.rootTag["Level"]["InhabitedTime"].value == value:
return
command = InspectPropertyChangeCommand(self.editorSession,
self.tr("Change chunk (%s, %s) property InhabitedTime")
% self.currentChunk.chunkPosition)
with command.begin():
with self.editorSession.beginSimpleCommand(self.tr("Change chunk (%s, %s) property InhabitedTime")
% self.currentChunk.chunkPosition):
self.currentChunk.rootTag["Level"]["InhabitedTime"].value = value
self.editorSession.pushCommand(command)
def updateTimeDidChange(self, value):
if self.currentChunk.rootTag["Level"]["LastUpdate"].value == value:
return
command = InspectPropertyChangeCommand(self.editorSession,
self.tr("Change chunk (%s, %s) property LastUpdate")
% self.currentChunk.chunkPosition)
with command.begin():
with self.editorSession.beginSimpleCommand(self.tr("Change chunk (%s, %s) property LastUpdate")
% self.currentChunk.chunkPosition):
self.currentChunk.rootTag["Level"]["LastUpdate"].value = value
self.editorSession.pushCommand(command)
def chunkTabDidChange(self, index):
if self.chunkTabWidget.widget(index) is self.chunkPropertiesTab:
@ -392,6 +383,3 @@ class InspectorWidget(QtGui.QWidget, Ui_inspectorWidget):
# cx = self.cxSpinBox.value()
# cz = self.czSpinBox.value()
# self.selectChunk(cx, cz)
class InspectPropertyChangeCommand(SimpleRevisionCommand):
pass

View File

@ -65,10 +65,6 @@ class NBTEditorItemDelegate(QtGui.QStyledItemDelegate):
super(NBTEditorItemDelegate, self).setModelData(editor, model, index)
class NBTDataChangeCommand(SimpleRevisionCommand):
pass
@registerCustomWidget
class NBTEditorWidget(QtGui.QWidget):
"""
@ -268,22 +264,18 @@ class NBTEditorWidget(QtGui.QWidget):
else:
text = "Unknown data changed."
command = NBTDataChangeCommand(self.editorSession, text)
with command.begin():
with self.editorSession.beginSimpleCommand(text):
self.rootTagRef.dirty = True
self.editorSession.worldEditor.syncToDisk()
self.editorSession.pushCommand(command)
self.tagValueChanged.emit(index.data(NBTTreeModel.NBTPathRole))
def rowsDidInsert(self, index):
name = self.tagNameForUndo(index.parent())
text = "%sInsert NBT tag under %s" % (self.undoCommandPrefixText, name)
command = NBTDataChangeCommand(self.editorSession, text)
with command.begin():
with self.editorSession.beginSimpleCommand(text):
self.rootTagRef.dirty = True
self.editorSession.worldEditor.syncToDisk()
self.editorSession.pushCommand(command)
doomedTagName = None
@ -291,11 +283,9 @@ class NBTEditorWidget(QtGui.QWidget):
name = self.tagNameForUndo(index)
text = "%sRemove NBT tag %s from %s" % (self.undoCommandPrefixText, self.doomedTagName, name)
command = NBTDataChangeCommand(self.editorSession, text)
with command.begin():
with self.editorSession.beginSimpleCommand(text):
self.rootTagRef.dirty = True
self.editorSession.worldEditor.syncToDisk()
self.editorSession.pushCommand(command)
tagValueChanged = QtCore.Signal(list)
tagAdded = QtCore.Signal(list)