Fix #330 - "Delete Map" unimplemented
This commit is contained in:
parent
4b86472577
commit
055a947ab5
@ -44,6 +44,10 @@ class MapListModel(QtCore.QAbstractListModel):
|
||||
def getMap(self, mapID):
|
||||
return self.editorSession.worldEditor.getMap(mapID)
|
||||
|
||||
def deleteMap(self, mapID):
|
||||
self.mapIDs.remove(mapID)
|
||||
self.editorSession.worldEditor.deleteMap(mapID)
|
||||
|
||||
def imageForMapID(self, mapID):
|
||||
try:
|
||||
mapData = self.getMap(mapID)
|
||||
@ -92,8 +96,12 @@ class MapPanel(QtGui.QWidget, Ui_mapWidget):
|
||||
|
||||
self.importImageButton.clicked.connect(self.importImage)
|
||||
|
||||
self.currentlyEditingLabel.setVisible(False)
|
||||
self.deleteMapButton.clicked.connect(self.deleteMap)
|
||||
|
||||
self.currentlyEditingLabel.setVisible(False)
|
||||
self.displayFirstMap()
|
||||
|
||||
def displayFirstMap(self):
|
||||
if len(self.mapListModel.mapIDs):
|
||||
index = self.mapListModel.index(0, 0)
|
||||
self.mapListView.setCurrentIndex(index)
|
||||
@ -183,7 +191,18 @@ class MapPanel(QtGui.QWidget, Ui_mapWidget):
|
||||
newMap.colors[:] = colors
|
||||
newMap.save()
|
||||
|
||||
self.reloadModel()
|
||||
self.reloadModel()
|
||||
self.displayMapID(newMap.mapID)
|
||||
|
||||
def deleteMap(self):
|
||||
idx = self.mapListView.currentIndex()
|
||||
if idx.isValid():
|
||||
mapID = self.mapListModel.data(idx, MapListModel.MapIDRole)
|
||||
with self.editorSession.beginSimpleCommand(self.tr("Delete Map {0}").format(mapID)):
|
||||
self.mapListModel.deleteMap(mapID)
|
||||
|
||||
self.reloadModel()
|
||||
self.displayFirstMap()
|
||||
|
||||
def reloadModel(self):
|
||||
self.mapListModel = MapListModel(self.editorSession)
|
||||
|
@ -1045,8 +1045,11 @@ class AnvilWorldAdapter(object):
|
||||
def getMap(self, mapID):
|
||||
return AnvilMapData(self.getMapTag(mapID), mapID, self)
|
||||
|
||||
def _getMapPath(self, mapID):
|
||||
return "data/map_%s.dat" % mapID
|
||||
|
||||
def getMapTag(self, mapID):
|
||||
mapPath = "data/map_%s.dat" % mapID
|
||||
mapPath = self._getMapPath(mapID)
|
||||
if not self.selectedRevision.containsFile(mapPath):
|
||||
raise KeyError("Map %s not found" % mapID)
|
||||
|
||||
@ -1055,8 +1058,7 @@ class AnvilWorldAdapter(object):
|
||||
return mapNBT
|
||||
|
||||
def saveMapTag(self, mapID, mapTag):
|
||||
mapPath = "data/map_%s.dat" % mapID
|
||||
self.selectedRevision.writeFile(mapPath, mapTag.save())
|
||||
self.selectedRevision.writeFile(self._getMapPath(mapID), mapTag.save())
|
||||
|
||||
def createMap(self):
|
||||
# idcounts.dat should hold the ID number of the last created map
|
||||
@ -1079,6 +1081,9 @@ class AnvilWorldAdapter(object):
|
||||
mapData.save()
|
||||
return mapData
|
||||
|
||||
def deleteMap(self, mapID):
|
||||
self.selectedRevision.deleteFile(self._getMapPath(mapID))
|
||||
|
||||
|
||||
class AnvilMapData(NBTCompoundRef):
|
||||
def __init__(self, mapTag, mapID, adapter):
|
||||
|
@ -605,6 +605,9 @@ class WorldEditor(object):
|
||||
def createMap(self):
|
||||
return self.adapter.createMap()
|
||||
|
||||
def deleteMap(self, mapID):
|
||||
return self.adapter.deleteMap(mapID)
|
||||
|
||||
# --- Players ---
|
||||
|
||||
def listPlayers(self):
|
||||
|
Reference in New Issue
Block a user