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:
@@ -1,3 +1,4 @@
|
|||||||
|
using System.IO;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace ExportDXF
|
namespace ExportDXF
|
||||||
@@ -13,6 +14,35 @@ namespace ExportDXF
|
|||||||
|
|
||||||
public string Source { get; set; }
|
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()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(DrawingNo))
|
if (string.IsNullOrEmpty(DrawingNo))
|
||||||
|
|||||||
@@ -487,6 +487,9 @@ namespace ExportDXF.Forms
|
|||||||
equipmentBox.Text = drawingInfo.EquipmentNo;
|
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
|
// Load drawings for the selected equipment, then set drawing number
|
||||||
await UpdateDrawingDropdownAsync();
|
await UpdateDrawingDropdownAsync();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user