This commit is contained in:
2026-07-26 14:46:18 +02:00
parent 810f993830
commit 3bd6cfb81d
8 changed files with 259 additions and 3 deletions

View File

@@ -6,12 +6,15 @@ from typing import Protocol
from PySide6.QtCore import QEvent, QObject
from bedit_gui.documents import Document
from bedit_gui.services.application_logging import get_logger
from bedit_gui.views.dialogs.document_dialogs import (
DocumentDialogs,
SaveChangesChoice,
)
from bedit_gui.views.main_window import MainWindow
logger = get_logger(__name__)
class DocumentDialogProvider(Protocol):
def choose_open_path(self, current_path: Path | None) -> Path | None: ...
@@ -51,6 +54,7 @@ class DocumentController(QObject):
def new_document(self) -> None:
if self.maybe_save_changes():
self.document.new()
logger.info("Created new document")
def open_document(self) -> None:
if not self.maybe_save_changes():
@@ -63,7 +67,10 @@ class DocumentController(QObject):
try:
self.document.open(path)
except (OSError, TypeError, ValueError) as exc:
logger.exception("Could not open document %s", path)
self.dialogs.show_file_error("Could not open document", exc)
else:
logger.info("Opened document: %s", path)
def save_document(self) -> bool:
if self.document.path is None:
@@ -71,8 +78,10 @@ class DocumentController(QObject):
try:
self.document.save()
except (OSError, TypeError, ValueError) as exc:
logger.exception("Could not save document %s", self.document.path)
self.dialogs.show_file_error("Could not save document", exc)
return False
logger.info("Saved document: %s", self.document.path)
return True
def save_document_as(self) -> bool:
@@ -83,8 +92,10 @@ class DocumentController(QObject):
try:
self.document.save_as(path)
except (OSError, TypeError, ValueError) as exc:
logger.exception("Could not save document as %s", path)
self.dialogs.show_file_error("Could not save document", exc)
return False
logger.info("Saved document as: %s", path)
return True
def maybe_save_changes(self) -> bool: