Skip to content

Commit

Permalink
wip: don't allow dropping of files etc :)
Browse files Browse the repository at this point in the history
  • Loading branch information
mchilvers committed Apr 5, 2024
1 parent b51ad19 commit 04d40b6
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/tools/builder/src/python/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,11 @@ def _on_dragover_component(self, event, component):

event.stopPropagation()

if self._component_being_dragged is None and not event.dataTransfer.getData("move"):
print("Nah!!")
event.preventDefault()
return

self.find_nearest_component(event)

# Rule 1: You can't drop a component onto itself.
Expand Down Expand Up @@ -489,28 +494,22 @@ def _on_drop_component(self, event, component):
# a) Moving a component that is already on the page.
move_data = event.dataTransfer.getData("move")
if move_data:
# Rule 1: You can't drop a component onto itself :)
if move_data == component.id:
return

# Remove the component being moved from its old location.
component_to_drop = Component.get_component_by_id(move_data)

# Rule 2: You also can't drop a container onto one of its own children!
if isinstance(component_to_drop, Container):
for item in component_to_drop.content:
if item.id == component.id:
return

# Remove the component being moved from its old container.
component_to_drop.parent.remove(component_to_drop)

# Or...
#
# b) Adding a new component to the page.
else:
component_blueprint_json = event.dataTransfer.getData("widget")
component_blueprint = json.loads(component_blueprint_json)
component_to_drop = create_component(component_blueprint["name"])
if component_blueprint_json:
component_blueprint = json.loads(component_blueprint_json)
component_to_drop = create_component(component_blueprint["name"])

else:
print("Don't know what this is!")
return

# Remove any drop zone active classes ##########################################

Expand Down

0 comments on commit 04d40b6

Please sign in to comment.