feat: auto-populate title from part description when opening documents

Adds a Description property to DrawingInfo that extracts the
descriptive text after the equipment/drawing number, excluding the
file extension. MainForm now sets the title box from this description
when no title was already set by the API history lookup.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-02-20 05:53:08 -05:00
parent 53aa23f762
commit 71c65e0bf5
2 changed files with 33 additions and 0 deletions

View File

@@ -1,3 +1,4 @@
using System.IO;
using System.Text.RegularExpressions;
namespace ExportDXF
@@ -13,6 +14,35 @@ namespace ExportDXF
public string Source { get; set; }
/// <summary>
/// The descriptive text after the equipment/drawing number (e.g. "Prox switch bracket for drive").
/// </summary>
public string Description
{
get
{
if (string.IsNullOrEmpty(Source) || string.IsNullOrEmpty(EquipmentNo))
return null;
// Strip equipment number (and optional drawing number) from the source to get the description
var prefix = string.IsNullOrEmpty(DrawingNo)
? EquipmentNo
: EquipmentNo + " " + DrawingNo;
var desc = Source;
if (desc.StartsWith(prefix, System.StringComparison.OrdinalIgnoreCase))
desc = desc.Substring(prefix.Length);
// Remove file extension (e.g. ".SLDPRT")
var ext = Path.GetExtension(desc);
if (!string.IsNullOrEmpty(ext))
desc = desc.Substring(0, desc.Length - ext.Length);
desc = desc.Trim();
return string.IsNullOrEmpty(desc) ? null : desc;
}
}
public override string ToString()
{
if (string.IsNullOrEmpty(DrawingNo))

View File

@@ -487,6 +487,9 @@ namespace ExportDXF.Forms
equipmentBox.Text = drawingInfo.EquipmentNo;
}
if (string.IsNullOrEmpty(titleBox.Text) && !string.IsNullOrEmpty(drawingInfo.Description))
titleBox.Text = drawingInfo.Description;
// Load drawings for the selected equipment, then set drawing number
await UpdateDrawingDropdownAsync();