add forbidden exceptions on closed elements

This commit is contained in:
Maxime Réaux 2026-02-13 11:38:59 +01:00
parent 42eb625ef6
commit 88bd28e949
6 changed files with 151 additions and 71 deletions

View file

@ -3,11 +3,7 @@ from pathlib import Path
from PyQt6.QtWidgets import QMessageBox
from warchron.model.model import Model
from warchron.model.exception import (
DeletionForbidden,
DeletionRequiresConfirmation,
UpdateRequiresConfirmation,
)
from warchron.model.exception import DomainError, RequiresConfirmation
from warchron.view.view import View
from warchron.constants import ItemType, RefreshScope
from warchron.controller.navigation_controller import NavigationController
@ -199,15 +195,15 @@ class AppController:
self.rounds.edit_round_battle(item_id)
self.navigation.refresh(RefreshScope.CURRENT_SELECTION_DETAILS)
self.is_dirty = True
except UpdateRequiresConfirmation as e:
except RequiresConfirmation as e:
reply = QMessageBox.question(
self.view,
"Confirm update",
e.message,
str(e),
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
)
if reply == QMessageBox.StandardButton.Yes:
e.apply_update()
e.action()
self.navigation.refresh(RefreshScope.CURRENT_SELECTION_DETAILS)
def delete_item(self, item_type: str, item_id: str) -> None:
@ -253,19 +249,19 @@ class AppController:
RefreshScope.WARS_TREE, item_type=ItemType.CAMPAIGN, item_id=camp_id
)
self.is_dirty = True
except DeletionForbidden as e:
except DomainError as e:
QMessageBox.warning(
self.view,
"Deletion forbidden",
e.reason,
str(e),
)
except DeletionRequiresConfirmation as e:
except RequiresConfirmation as e:
reply = QMessageBox.question(
self.view,
"Confirm deletion",
e.message,
str(e),
QMessageBox.StandardButton.Yes | QMessageBox.StandardButton.No,
)
if reply == QMessageBox.StandardButton.Yes:
e.cleanup_action()
e.action()
self.navigation.refresh(RefreshScope.CURRENT_SELECTION_DETAILS)