Document handling
New/Open/Save/Save as and Undo/Redo
This commit is contained in:
36
src/bedit_gui/controllers/undo_controller.py
Normal file
36
src/bedit_gui/controllers/undo_controller.py
Normal 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)
|
||||
Reference in New Issue
Block a user