Wiresheet: Ctrl+click to select several links, delete them together
Ctrl+click toggles a link in the selection; Del or the link popup deletes every selected link after one confirmation, as a single undoable step. On a device, links the device refuses stay and are named in one warning. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+48
-22
@@ -155,6 +155,7 @@ def reset_to_startup_state():
|
||||
app_state.selected_tree_item_id = None
|
||||
app_state.link_mark_element = None
|
||||
app_state.selected_link_tag = None
|
||||
app_state.selected_link_tags.clear()
|
||||
|
||||
app_state.active_components_list.clear()
|
||||
app_state.tree_element_map.clear()
|
||||
@@ -1108,6 +1109,15 @@ def add_component(kit_name, type_name, grid_x, grid_y, parent=None):
|
||||
|
||||
def remove_link(link_element):
|
||||
"""Removes a <link> element from the <links> section and repaints."""
|
||||
remove_links([link_element])
|
||||
|
||||
|
||||
def remove_links(link_elements):
|
||||
"""Removes several <link> elements as one undoable step, and repaints.
|
||||
|
||||
On a device each link is unlinked there first; one the device refuses stays in the
|
||||
DOM, and the rest still go, with the refusals named in a single warning.
|
||||
"""
|
||||
if app_state.xml_root_element is None:
|
||||
return
|
||||
|
||||
@@ -1115,35 +1125,51 @@ def remove_link(link_element):
|
||||
if links_elem is None:
|
||||
return
|
||||
|
||||
from_ref = link_element.get("from", "")
|
||||
to_ref = link_element.get("to", "")
|
||||
commands = []
|
||||
failures = []
|
||||
for link_element in link_elements:
|
||||
if link_element not in list(links_elem):
|
||||
continue
|
||||
from_ref = link_element.get("from", "")
|
||||
to_ref = link_element.get("to", "")
|
||||
|
||||
if app_state.live_mode:
|
||||
if not live_hooks.live_delete_link(*link_ends(from_ref, to_ref)):
|
||||
live_hooks.warn_failure("Delete Link",
|
||||
f"The link {from_ref} → {to_ref} was not removed from the device")
|
||||
return
|
||||
if app_state.live_mode:
|
||||
if not live_hooks.live_delete_link(*link_ends(from_ref, to_ref)):
|
||||
failures.append(f"{from_ref} → {to_ref}")
|
||||
continue
|
||||
|
||||
try:
|
||||
index = list(links_elem).index(link_element)
|
||||
links_elem.remove(link_element)
|
||||
except ValueError:
|
||||
|
||||
from_slot = from_ref.rsplit(".", 1)[-1] if "." in from_ref else from_ref
|
||||
to_slot = to_ref.rsplit(".", 1)[-1] if "." in to_ref else to_ref
|
||||
label = f"delete link {from_slot}→{to_slot}"
|
||||
if app_state.live_mode:
|
||||
commands.append(LiveLinkCommand(links_elem, index, link_element,
|
||||
present=False, label=label))
|
||||
else:
|
||||
commands.append(undo.DeleteLinkCommand(links_elem, index, link_element,
|
||||
label=label))
|
||||
|
||||
# Removed in order, each index taken after the ones before it went, so the composite
|
||||
# puts them back last-first and every one lands where it was.
|
||||
if len(commands) == 1:
|
||||
undo.push(commands[0])
|
||||
elif commands:
|
||||
undo.push(undo.CompositeCommand(commands, label=f"delete {len(commands)} links"))
|
||||
|
||||
if failures:
|
||||
noun = "link" if len(failures) == 1 else "links"
|
||||
verb = "was" if len(failures) == 1 else "were"
|
||||
live_hooks.warn_failure(
|
||||
"Delete Link",
|
||||
f"The {noun} {', '.join(failures)} {verb} not removed from the device")
|
||||
|
||||
if not commands:
|
||||
return
|
||||
|
||||
from_slot = from_ref.rsplit(".", 1)[-1] if "." in from_ref else from_ref
|
||||
to_slot = to_ref.rsplit(".", 1)[-1] if "." in to_ref else to_ref
|
||||
if app_state.live_mode:
|
||||
undo.push(LiveLinkCommand(
|
||||
links_elem, index, link_element, present=False,
|
||||
label=f"delete link {from_slot}→{to_slot}"
|
||||
))
|
||||
else:
|
||||
undo.push(undo.DeleteLinkCommand(
|
||||
links_elem, index, link_element,
|
||||
label=f"delete link {from_slot}→{to_slot}"
|
||||
))
|
||||
|
||||
app_state.selected_link_tag = None
|
||||
app_state.selected_link_tags.clear()
|
||||
app_state.mark_dirty()
|
||||
wiresheet.render_current_sheet()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user