diff --git a/OpenNest/Forms/BomFileDialog.cs b/OpenNest/Forms/BomFileDialog.cs
new file mode 100644
index 00000000..4db4b0bb
--- /dev/null
+++ b/OpenNest/Forms/BomFileDialog.cs
@@ -0,0 +1,20 @@
+using System.Windows.Forms;
+
+namespace OpenNest.Forms
+{
+ /// The BOM workbook picker shared by the BOM import forms.
+ internal static class BomFileDialog
+ {
+ /// Asks for a BOM file; null when the operator cancels.
+ public static string Show(IWin32Window owner)
+ {
+ using var dialog = new OpenFileDialog
+ {
+ Title = "Select BOM File",
+ Filter = "Excel Files|*.xlsx|All Files|*.*",
+ FilterIndex = 1,
+ };
+ return dialog.ShowDialog(owner) == DialogResult.OK ? dialog.FileName : null;
+ }
+ }
+}
diff --git a/OpenNest/Forms/BomImportForm.cs b/OpenNest/Forms/BomImportForm.cs
index 19a4b916..284ea8d3 100644
--- a/OpenNest/Forms/BomImportForm.cs
+++ b/OpenNest/Forms/BomImportForm.cs
@@ -46,23 +46,17 @@ namespace OpenNest.Forms
private void BrowseBom_Click(object sender, EventArgs e)
{
- using var dlg = new OpenFileDialog
- {
- Title = "Select BOM File",
- Filter = "Excel Files|*.xlsx|All Files|*.*",
- FilterIndex = 1,
- };
-
- if (dlg.ShowDialog(this) != DialogResult.OK)
+ var fileName = BomFileDialog.Show(this);
+ if (fileName == null)
return;
- txtBomFile.Text = dlg.FileName;
+ txtBomFile.Text = fileName;
if (string.IsNullOrWhiteSpace(txtDxfFolder.Text))
- txtDxfFolder.Text = Path.GetDirectoryName(dlg.FileName);
+ txtDxfFolder.Text = Path.GetDirectoryName(fileName);
if (string.IsNullOrWhiteSpace(txtJobName.Text))
- txtJobName.Text = BomImportRows.JobName(dlg.FileName);
+ txtJobName.Text = BomImportRows.JobName(fileName);
}
private void BrowseDxf_Click(object sender, EventArgs e)
diff --git a/OpenNest/Forms/ImportBomToSetForm.cs b/OpenNest/Forms/ImportBomToSetForm.cs
index bcc580e1..87b7beaf 100644
--- a/OpenNest/Forms/ImportBomToSetForm.cs
+++ b/OpenNest/Forms/ImportBomToSetForm.cs
@@ -274,18 +274,14 @@ namespace OpenNest.Forms
private void BrowseBomButton_Click(object sender, EventArgs e)
{
- using var dialog = new OpenFileDialog
- {
- Title = "Select BOM File",
- Filter = "Excel Files|*.xlsx|All Files|*.*",
- };
- if (dialog.ShowDialog(this) != DialogResult.OK)
+ var fileName = BomFileDialog.Show(this);
+ if (fileName == null)
return;
- bomBox.Text = dialog.FileName;
+ bomBox.Text = fileName;
if (string.IsNullOrWhiteSpace(folderBox.Text))
- folderBox.Text = Path.GetDirectoryName(dialog.FileName);
- nameBox.Text = BomImportRows.JobName(dialog.FileName);
+ folderBox.Text = Path.GetDirectoryName(fileName);
+ nameBox.Text = BomImportRows.JobName(fileName);
}
private void BrowseFolderButton_Click(object sender, EventArgs e)