feat: add context menu to delete drawings from the drawing list
Adds a right-click "Delete" option on the drawings tab that removes the selected drawing and all its placed parts from every plate. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Drawing;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenNest.Controls
|
||||
@@ -22,8 +23,25 @@ namespace OpenNest.Controls
|
||||
|
||||
imageSize = new Size(ItemHeight, ItemHeight - 10);
|
||||
nameFont = new Font(Font.FontFamily, 10, FontStyle.Bold);
|
||||
|
||||
var menu = new ContextMenuStrip();
|
||||
var deleteItem = new ToolStripMenuItem("Delete");
|
||||
deleteItem.Click += (s, e) =>
|
||||
{
|
||||
if (SelectedItem is Drawing drawing)
|
||||
DeleteRequested?.Invoke(this, drawing);
|
||||
};
|
||||
menu.Opening += (s, e) =>
|
||||
{
|
||||
if (SelectedItem == null)
|
||||
e.Cancel = true;
|
||||
};
|
||||
menu.Items.Add(deleteItem);
|
||||
ContextMenuStrip = menu;
|
||||
}
|
||||
|
||||
public event EventHandler<Drawing> DeleteRequested;
|
||||
|
||||
public Units Units { get; set; }
|
||||
|
||||
public bool HideDepletedParts { get; set; }
|
||||
|
||||
@@ -225,6 +225,7 @@ namespace OpenNest.Forms
|
||||
|
||||
Text = Nest.Name;
|
||||
drawingListBox1.Units = Nest.Units;
|
||||
drawingListBox1.DeleteRequested += drawingListBox1_DeleteRequested;
|
||||
}
|
||||
|
||||
public string LastSavePath { get; private set; }
|
||||
@@ -1026,6 +1027,32 @@ namespace OpenNest.Forms
|
||||
}
|
||||
}
|
||||
|
||||
private void drawingListBox1_DeleteRequested(object sender, Drawing drawing)
|
||||
{
|
||||
var result = MessageBox.Show(
|
||||
$"Delete drawing '{drawing.Name}' and all its parts from every plate?",
|
||||
"Delete Drawing",
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Warning,
|
||||
MessageBoxDefaultButton.Button2);
|
||||
|
||||
if (result != DialogResult.Yes)
|
||||
return;
|
||||
|
||||
foreach (var plate in Nest.Plates)
|
||||
{
|
||||
for (var i = plate.Parts.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (plate.Parts[i].BaseDrawing == drawing)
|
||||
plate.Parts.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
Nest.Drawings.Remove(drawing);
|
||||
UpdateDrawingList();
|
||||
PlateView.Invalidate();
|
||||
}
|
||||
|
||||
private void drawingListBox1_Click(object sender, EventArgs e)
|
||||
{
|
||||
addPart = true;
|
||||
|
||||
Reference in New Issue
Block a user