Multi-Deletion of Characters + Confirmation Dialog

-Since multi-selection of characters is now possible, it's more intuitive that all selected characters should be deleted.

-Added a confirmation dialog before character-deletion? Why the heck  was this not a thing before? It was way too easy to accidentally delete characters, with no way to restore them without external source-control or backups.
This commit is contained in:
tntscreed 2023-03-07 20:56:54 +01:00
parent 06f8ab3519
commit 953ce4bd15
2 changed files with 22 additions and 8 deletions

View file

@ -514,7 +514,7 @@ class MainWindow(QMainWindow, Ui_MainWindow):
pass pass
def deleteCharacter(self): def deleteCharacter(self):
ID = self.lstCharacters.removeCharacter() ID = self.lstCharacters.removeCharacters()
if ID is None: if ID is None:
return return
for itemID in self.mdlOutline.findItemsByPOV(ID): for itemID in self.mdlOutline.findItemsByPOV(ID):

View file

@ -2,7 +2,7 @@
# --!-- coding: utf8 --!-- # --!-- coding: utf8 --!--
from PyQt5.QtCore import QSize, QModelIndex, Qt from PyQt5.QtCore import QSize, QModelIndex, Qt
from PyQt5.QtGui import QPixmap, QColor, QIcon, QBrush from PyQt5.QtGui import QPixmap, QColor, QIcon, QBrush
from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QColorDialog, QDialog from PyQt5.QtWidgets import QTreeWidget, QTreeWidgetItem, QColorDialog, QDialog, QMessageBox
from manuskript.enums import Character from manuskript.enums import Character
from manuskript.functions import iconColor, mainWindow from manuskript.functions import iconColor, mainWindow
@ -138,15 +138,29 @@ class characterTreeView(QTreeWidget):
self._model.addCharacter(importance=curr_importance) self._model.addCharacter(importance=curr_importance)
def removeCharacter(self): def removeCharacters(self):
""" """
Removes selected character. Removes selected characters.
""" """
ID = self.currentCharacterID() IDs = self.currentCharacterIDs()
if ID is None:
# If none of the IDs are valid, do nothing.
if not any(IDs):
return None return None
self._model.removeCharacter(ID)
return ID #Get confirmation from user
confirm = QMessageBox.warning(
self, "Delete selected character(s)?",
"Are you sure you want to delete the selected character(s)?",
QMessageBox.Yes | QMessageBox.No
)
if confirm != QMessageBox.Yes:
return None
#Delete all selected characters
for ID in IDs:
self._model.removeCharacter(ID)
return IDs
def choseCharacterColor(self): def choseCharacterColor(self):
ID = self.currentCharacterID() ID = self.currentCharacterID()