Avoid creating world view when world list is offscreen.

Seems to fix the access violations, but that's not at all certain.
Hours of bisecting and single-stepping also blamed the simple import of
one of the UI files for the violations.

In any case, this avoids doubly creating the world view both when the
window is initialized and when it is shown on screen.
This commit is contained in:
David Vierra 2016-01-20 03:09:24 -10:00
parent 7a622bcd32
commit 358de35300

View File

@ -201,7 +201,7 @@ class WorldListWidget(QtGui.QDialog, Ui_worldList):
self._updateInstalls() self._updateInstalls()
self.savesFolderComboBox.currentIndexChanged.connect(self.reloadList) self.savesFolderComboBox.currentIndexChanged.connect(self.savesFolderChanged)
self.minecraftInstallBox.currentIndexChanged.connect(minecraftinstall.currentInstallOption.setValue) self.minecraftInstallBox.currentIndexChanged.connect(minecraftinstall.currentInstallOption.setValue)
self.minecraftVersionBox.currentIndexChanged[str].connect(minecraftinstall.currentVersionOption.setValue) self.minecraftVersionBox.currentIndexChanged[str].connect(minecraftinstall.currentVersionOption.setValue)
self.resourcePackBox.currentIndexChanged.connect(self.resourcePackChanged) self.resourcePackBox.currentIndexChanged.connect(self.resourcePackChanged)
@ -287,6 +287,15 @@ class WorldListWidget(QtGui.QDialog, Ui_worldList):
self.recentWorldsButton.setMenu(self.recentWorldsMenu) self.recentWorldsButton.setMenu(self.recentWorldsMenu)
def savesFolderChanged(self):
self.reloadList()
if len(self.worldListModel.worlds):
self.worldListView.setFocus()
self.worldListView.setCurrentIndex(self.worldListModel.createIndex(0, 0))
self.showWorld(self.worldListModel.worlds[0][0])
else:
self.removeWorldView()
def reloadList(self): def reloadList(self):
try: try:
itemData = self.savesFolderComboBox.itemData(self.savesFolderComboBox.currentIndex()) itemData = self.savesFolderComboBox.itemData(self.savesFolderComboBox.currentIndex())
@ -308,11 +317,6 @@ class WorldListWidget(QtGui.QDialog, Ui_worldList):
self.worldListModel = WorldListModel(worldFiles) self.worldListModel = WorldListModel(worldFiles)
self.worldListView.setModel(self.worldListModel) self.worldListView.setModel(self.worldListModel)
if len(self.worldListModel.worlds):
self.worldListView.setFocus()
self.worldListView.setCurrentIndex(self.worldListModel.createIndex(0, 0))
self.showWorld(self.worldListModel.worlds[0][0])
except EnvironmentError as e: except EnvironmentError as e:
setWidgetError(self, e) setWidgetError(self, e)
@ -323,9 +327,7 @@ class WorldListWidget(QtGui.QDialog, Ui_worldList):
def worldListItemClicked(self, index): def worldListItemClicked(self, index):
filename = index.data() filename = index.data()
if filename != self._currentFilename: self.showWorld(filename)
self._currentFilename = filename
self.showWorld(filename)
def worldListItemDoubleClicked(self, index): def worldListItemDoubleClicked(self, index):
row = index.row() row = index.row()
@ -333,6 +335,10 @@ class WorldListWidget(QtGui.QDialog, Ui_worldList):
self.editWorldClicked.emit(self.worldListModel.worlds[row][0]) self.editWorldClicked.emit(self.worldListModel.worlds[row][0])
def showWorld(self, filename): def showWorld(self, filename):
if filename == self._currentFilename:
return
self._currentFilename = filename
self.removeWorldView() self.removeWorldView()
try: try: