Renaming the document root and components from the tree

This commit is contained in:
Joppe Blondel
2026-07-26 16:14:51 +02:00
parent a96bde9642
commit d9304ba2e0
6 changed files with 98 additions and 30 deletions
@@ -0,0 +1,19 @@
from PySide6.QtGui import QUndoCommand
from bedit_core.models import Component
class RenameComponentCommand(QUndoCommand):
def __init__(self, document, component: Component, new_name: str) -> None:
super().__init__("Rename component")
self.document = document
self.component = component
self.old_name = component.name
self.new_name = new_name
def redo(self) -> None:
self.component.name = self.new_name
self.document.model_changed.emit(self.document.model)
def undo(self) -> None:
self.component.name = self.old_name
self.document.model_changed.emit(self.document.model)
@@ -0,0 +1,18 @@
from PySide6.QtGui import QUndoCommand
class RenameDocumentCommand(QUndoCommand):
def __init__(self, document, new_name: str) -> None:
super().__init__("Rename document")
self.document = document
self.old_name = document.model.name
self.new_name = new_name
def redo(self) -> None:
self.document.model.name = self.new_name
self.document.model_changed.emit(self.document.model)
def undo(self) -> None:
self.document.model.name = self.old_name
self.document.model_changed.emit(self.document.model)