Document handling

New/Open/Save/Save as and Undo/Redo
This commit is contained in:
2026-07-26 13:41:23 +02:00
parent 38b8ee34ff
commit 4c3b8b4b6d
12 changed files with 506 additions and 4 deletions

View File

@@ -0,0 +1,36 @@
from PySide6.QtCore import QObject
from bedit_gui.documents import Document
from bedit_gui.views.main_window import MainWindow
class UndoController(QObject):
def __init__(self, document: Document, window: MainWindow) -> None:
super().__init__(window)
self.document = document
self.window = window
undo_action = window.ui.actionUndo
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_stack.canUndoChanged.connect(undo_action.setEnabled)
undo_stack.canRedoChanged.connect(redo_action.setEnabled)
undo_stack.undoTextChanged.connect(self._update_undo_text)
undo_stack.redoTextChanged.connect(self._update_redo_text)
undo_action.setEnabled(undo_stack.canUndo())
redo_action.setEnabled(undo_stack.canRedo())
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)