fix(layers): deleting a non-empty layer warns and removes its objects (#237)

Deleting a layer only dropped the layer record, leaving its objects in the
file still tagged with the (now-gone) layer name. Now:

- Empty layer → deleted straight away.
- Non-empty layer → a warning modal ("Layer X is not empty — N objects;
  deleting also removes them. Continue?") with Delete Objects / Cancel.
  Confirming erases every object on the layer, then removes the layer, as
  one undo step. The layer record is dropped before the erase so the
  locked-layer guard can't keep its objects.
- Layer "0" and the current layer can't be deleted (reported on the
  command line) instead of silently leaving a broken state.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Hakan Seven 2026-07-01 17:23:32 +03:00
commit 2712bb80e4
5 changed files with 146 additions and 17 deletions

View file

@ -104,6 +104,8 @@ impl OpenCADStudio {
// Dismissing these via ✕ is the cancel/decline path.
Some(Unsaved) => self.pending_close = None,
Some(AssocPrompt) => self.mark_assoc_prompted(),
// Cancel: leave the layer (and its objects) untouched.
Some(LayerDeleteWarning) => self.layer_delete_pending = None,
// Cancel: drop the working copy without touching the block.
Some(AttributeEditor) => {
self.attr_editor_handle = None;
@ -914,6 +916,8 @@ impl OpenCADStudio {
Message::LayerDelete => self.on_layer_delete(),
Message::LayerDeleteConfirm => self.on_layer_delete_confirm(),
Message::LayerSetCurrent => self.on_layer_set_current(),
Message::LayerSelect(idx) => {