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
def deleteCharacter(self):
ID = self.lstCharacters.removeCharacter()
ID = self.lstCharacters.removeCharacters()
if ID is None:
return
for itemID in self.mdlOutline.findItemsByPOV(ID):

View file

@ -2,7 +2,7 @@
# --!-- coding: utf8 --!--
from PyQt5.QtCore import QSize, QModelIndex, Qt
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.functions import iconColor, mainWindow
@ -138,15 +138,29 @@ class characterTreeView(QTreeWidget):
self._model.addCharacter(importance=curr_importance)
def removeCharacter(self):
def removeCharacters(self):
"""
Removes selected character.
Removes selected characters.
"""
ID = self.currentCharacterID()
if ID is None:
IDs = self.currentCharacterIDs()
# If none of the IDs are valid, do nothing.
if not any(IDs):
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):
ID = self.currentCharacterID()