AI'ed clipboard
This commit is contained in:
@@ -6,14 +6,14 @@ from pathlib import Path
|
||||
from PySide6.QtCore import QObject, Signal
|
||||
from PySide6.QtGui import QUndoStack
|
||||
|
||||
from bedit_core.models import ID, Component, ComponentID, GraphImplementation, Port, PortID, Parameter, ParameterID, EquationImplementation
|
||||
from bedit_core.models import ID, Component, ComponentID, GraphImplementation, Port, PortID, Parameter, ParameterID
|
||||
from bedit_core.models import Document as CoreDocument
|
||||
from bedit_gui.commands.change_icon_command import ChangeIconCommand
|
||||
from bedit_gui.commands.port_commands import AddPortCommand, ChangePortCommand, RemovePortCommand
|
||||
from bedit_gui.commands.param_commands import AddParamCommand, ChangeParamCommand, RemoveParamCommand
|
||||
from bedit_gui.commands.rename_component_command import RenameComponentCommand
|
||||
from bedit_gui.commands.rename_document_command import RenameDocumentCommand
|
||||
from bedit_gui.commands.component_command import AddEmptyGraphComponent, AddEmptyEquationComponent, DeleteComponent
|
||||
from bedit_gui.commands.component_command import AddEmptyEquationComponent, AddEmptyGraphComponent, DeleteComponent, PasteComponents
|
||||
from bedit_gui.models import Icon, IconDatabase
|
||||
from bedit_gui.services import document_files
|
||||
|
||||
@@ -199,11 +199,45 @@ class Document(QObject):
|
||||
|
||||
def add_empty_graph_component(self, component: Component) -> None:
|
||||
if isinstance(component.implementation, GraphImplementation):
|
||||
self.undo_stack.push(AddEmptyGraphComponent(self, component))
|
||||
command = AddEmptyGraphComponent(self, component)
|
||||
command.component.name = self._unique_component_name(component.implementation.graph.components, command.component.name)
|
||||
self.undo_stack.push(command)
|
||||
|
||||
def add_empty_equation_component(self, component: Component) -> None:
|
||||
if isinstance(component.implementation, GraphImplementation):
|
||||
self.undo_stack.push(AddEmptyEquationComponent(self, component))
|
||||
command = AddEmptyEquationComponent(self, component)
|
||||
command.component.name = self._unique_component_name(component.implementation.graph.components, command.component.name)
|
||||
self.undo_stack.push(command)
|
||||
|
||||
def delete_component(self, component: Component) -> None:
|
||||
self.undo_stack.push(DeleteComponent(self, component))
|
||||
|
||||
def delete_components(self, components: list[Component]) -> None:
|
||||
if not components:
|
||||
return
|
||||
self.undo_stack.beginMacro("Delete components")
|
||||
for component in components:
|
||||
self.undo_stack.push(DeleteComponent(self, component))
|
||||
self.undo_stack.endMacro()
|
||||
|
||||
def paste_components(self, target: dict[ComponentID, Component], components: dict[ComponentID, Component], icons: dict[ComponentID, Icon]) -> None:
|
||||
if not components:
|
||||
return
|
||||
names = {component.name for component in target.values()}
|
||||
for component in components.values():
|
||||
component.name = self._unique_name(names, component.name)
|
||||
names.add(component.name)
|
||||
self.undo_stack.push(PasteComponents(self, target, components, icons))
|
||||
|
||||
@staticmethod
|
||||
def _unique_component_name(components: dict[ComponentID, Component], name: str) -> str:
|
||||
return Document._unique_name({component.name for component in components.values()}, name)
|
||||
|
||||
@staticmethod
|
||||
def _unique_name(names: set[str], name: str) -> str:
|
||||
if name not in names:
|
||||
return name
|
||||
index = 0
|
||||
while f"{name}_{index}" in names:
|
||||
index += 1
|
||||
return f"{name}_{index}"
|
||||
|
||||
Reference in New Issue
Block a user