Library drag-in
This commit is contained in:
@@ -9,18 +9,25 @@ from bedit_gui.documents import Document as GuiDocument
|
||||
from bedit_gui.models import Icon, ShapeID
|
||||
|
||||
FORMAT_VERSION = 1
|
||||
COMPONENTS_MIME = "application/x-bedit-components+json"
|
||||
|
||||
|
||||
def export_components(document: GuiDocument, components: list[Component]) -> dict[str, Any]:
|
||||
roots = {document.component_id(component): component for component in components}
|
||||
serialized = document_to_data(Document(format_version=1, id=ID(), name="Clipboard", root=roots))
|
||||
component_ids = _all_component_ids(roots)
|
||||
icons = {}
|
||||
for component_id in component_ids:
|
||||
icon = document.stored_component_icon(component_id)
|
||||
if icon is not None:
|
||||
icons[str(component_id)] = icon.to_data()
|
||||
return {"format_version": FORMAT_VERSION, "type": "components", "components": serialized["root"], "icons": icons}
|
||||
icons[component_id] = icon
|
||||
return export_component_data(roots, icons)
|
||||
|
||||
|
||||
def export_component_data(components: dict[ComponentID, Component], icons: dict[ComponentID, Icon]) -> dict[str, Any]:
|
||||
serialized = document_to_data(Document(format_version=1, id=ID(), name="Clipboard", root=components))
|
||||
component_ids = set(_all_component_ids(components))
|
||||
icon_data = {str(component_id): icon.to_data() for component_id, icon in icons.items() if component_id in component_ids}
|
||||
return {"format_version": FORMAT_VERSION, "type": "components", "components": serialized["root"], "icons": icon_data}
|
||||
|
||||
|
||||
def import_components(payload: dict[str, Any]) -> tuple[dict[ComponentID, Component], dict[ComponentID, Icon]]:
|
||||
|
||||
Reference in New Issue
Block a user