Hooked up port editor in the document tree

This commit is contained in:
2026-07-26 17:20:37 +02:00
parent b417d85477
commit 8b45674cd2
9 changed files with 610 additions and 30 deletions

View File

@@ -5,11 +5,12 @@ from pathlib import Path
from PySide6.QtCore import QObject, Signal
from PySide6.QtGui import QUndoStack
from bedit_core.models import ID
from bedit_core.models import Document as CoreDocument, Component
from bedit_gui.services import document_files
from bedit_gui.commands.rename_document_command import RenameDocumentCommand
from bedit_core.models import ID, Component, Port, PortID
from bedit_core.models import Document as CoreDocument
from bedit_gui.commands.port_commands import AddPortCommand, ChangePortCommand, RemovePortCommand
from bedit_gui.commands.rename_component_command import RenameComponentCommand
from bedit_gui.commands.rename_document_command import RenameDocumentCommand
from bedit_gui.services import document_files
class Document(QObject):
@@ -84,5 +85,33 @@ class Document(QObject):
def rename(self, name: str) -> None:
self.undo_stack.push(RenameDocumentCommand(self, name))
def rename_component(self, component: Component, name:str) -> None:
def rename_component(self, component: Component, name: str) -> None:
self.undo_stack.push(RenameComponentCommand(self, component, name))
def update_component_ports(
self,
component: Component,
ports: dict[PortID, Port],
) -> None:
current = component.interface.ports
removed = [
RemovePortCommand(self, component, port_id)
for port_id in current.keys() - ports.keys()
]
added = [
AddPortCommand(self, component, port_id, ports[port_id])
for port_id in ports.keys() - current.keys()
]
changed = [
ChangePortCommand(self, component, port_id, ports[port_id])
for port_id in current.keys() & ports.keys()
if current[port_id] != ports[port_id]
]
commands = [*removed, *added, *changed]
if not commands:
return
self.undo_stack.beginMacro("Edit interface")
for command in commands:
self.undo_stack.push(command)
self.undo_stack.endMacro()