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

@@ -1,8 +1,11 @@
from PySide6.QtCore import QObject
from bedit_gui.documents import Document
from bedit_gui.services.application_logging import get_logger
from bedit_gui.views.main_window import MainWindow
logger = get_logger(__name__)
class UndoController(QObject):
def __init__(self, document: Document, window: MainWindow) -> None:
@@ -15,8 +18,8 @@ class UndoController(QObject):
redo_action = window.ui.actionRedo
undo_stack = document.undo_stack
undo_action.triggered.connect(undo_stack.undo)
redo_action.triggered.connect(undo_stack.redo)
undo_action.triggered.connect(self.undo)
redo_action.triggered.connect(self.redo)
undo_stack.canUndoChanged.connect(undo_action.setEnabled)
undo_stack.canRedoChanged.connect(redo_action.setEnabled)
@@ -27,10 +30,20 @@ class UndoController(QObject):
undo_action.setEnabled(undo_stack.canUndo())
redo_action.setEnabled(undo_stack.canRedo())
def undo(self) -> None:
command = self.document.undo_stack.undoText()
self.document.undo_stack.undo()
logger.info("Undo: %s", command)
def redo(self) -> None:
command = self.document.undo_stack.redoText()
self.document.undo_stack.redo()
logger.info("Redo: %s", command)
def _update_undo_text(self, command: str) -> None:
text = f"Undo {command}" if command else "Undo"
self.window.ui.actionUndo.setText(text)
def _update_redo_text(self, command: str) -> None:
text = f"Redo {command}" if command else "Redo"
self.window.ui.actionRedo.setText(text)
self.window.ui.actionRedo.setText(text)