refactor(ui): rename controls and improve drawing selection

- Rename form controls from generic names to descriptive ones:
  - button1 → runButton
  - richTextBox1 → logTextBox
  - comboBox1 → viewFlipDeciderBox
  - comboBox2 → drawingNoBox
- Preserve drawing selection when switching equipment
- Auto-populate drawing number from active document

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-30 17:29:47 -04:00
parent d29d9a0e06
commit cc34fb43b6
2 changed files with 85 additions and 70 deletions

View File

@@ -29,15 +29,15 @@
private void InitializeComponent() private void InitializeComponent()
{ {
this.activeDocTitleBox = new System.Windows.Forms.TextBox(); this.activeDocTitleBox = new System.Windows.Forms.TextBox();
this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.logTextBox = new System.Windows.Forms.RichTextBox();
this.label1 = new System.Windows.Forms.Label(); this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button(); this.runButton = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox(); this.viewFlipDeciderBox = new System.Windows.Forms.ComboBox();
this.label4 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label();
this.equipmentNoBox = new System.Windows.Forms.ComboBox(); this.equipmentNoBox = new System.Windows.Forms.ComboBox();
this.label5 = new System.Windows.Forms.Label(); this.label5 = new System.Windows.Forms.Label();
this.comboBox2 = new System.Windows.Forms.ComboBox(); this.drawingNoBox = new System.Windows.Forms.ComboBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// activeDocTitleBox // activeDocTitleBox
@@ -52,18 +52,18 @@
this.activeDocTitleBox.TabIndex = 1; this.activeDocTitleBox.TabIndex = 1;
this.activeDocTitleBox.TextChanged += new System.EventHandler(this.activeDocTitleBox_TextChanged); this.activeDocTitleBox.TextChanged += new System.EventHandler(this.activeDocTitleBox_TextChanged);
// //
// richTextBox1 // logTextBox
// //
this.richTextBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.logTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.richTextBox1.BackColor = System.Drawing.Color.White; this.logTextBox.BackColor = System.Drawing.Color.White;
this.richTextBox1.Location = new System.Drawing.Point(12, 106); this.logTextBox.Location = new System.Drawing.Point(12, 106);
this.richTextBox1.Name = "richTextBox1"; this.logTextBox.Name = "logTextBox";
this.richTextBox1.ReadOnly = true; this.logTextBox.ReadOnly = true;
this.richTextBox1.Size = new System.Drawing.Size(866, 556); this.logTextBox.Size = new System.Drawing.Size(866, 556);
this.richTextBox1.TabIndex = 10; this.logTextBox.TabIndex = 10;
this.richTextBox1.Text = ""; this.logTextBox.Text = "";
// //
// label1 // label1
// //
@@ -74,17 +74,17 @@
this.label1.TabIndex = 0; this.label1.TabIndex = 0;
this.label1.Text = "Active document :"; this.label1.Text = "Active document :";
// //
// button1 // runButton
// //
this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.runButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.button1.Image = global::ExportDXF.Properties.Resources.play; this.runButton.Image = global::ExportDXF.Properties.Resources.play;
this.button1.Location = new System.Drawing.Point(884, 13); this.runButton.Location = new System.Drawing.Point(884, 13);
this.button1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.runButton.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.button1.Name = "button1"; this.runButton.Name = "runButton";
this.button1.Size = new System.Drawing.Size(46, 56); this.runButton.Size = new System.Drawing.Size(46, 56);
this.button1.TabIndex = 11; this.runButton.TabIndex = 11;
this.button1.UseVisualStyleBackColor = true; this.runButton.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click); this.runButton.Click += new System.EventHandler(this.button1_Click);
// //
// label3 // label3
// //
@@ -95,14 +95,14 @@
this.label3.TabIndex = 2; this.label3.TabIndex = 2;
this.label3.Text = "View flip decider :"; this.label3.Text = "View flip decider :";
// //
// comboBox1 // viewFlipDeciderBox
// //
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.viewFlipDeciderBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.FormattingEnabled = true; this.viewFlipDeciderBox.FormattingEnabled = true;
this.comboBox1.Location = new System.Drawing.Point(130, 44); this.viewFlipDeciderBox.Location = new System.Drawing.Point(130, 44);
this.comboBox1.Name = "comboBox1"; this.viewFlipDeciderBox.Name = "viewFlipDeciderBox";
this.comboBox1.Size = new System.Drawing.Size(432, 25); this.viewFlipDeciderBox.Size = new System.Drawing.Size(432, 25);
this.comboBox1.TabIndex = 3; this.viewFlipDeciderBox.TabIndex = 3;
// //
// label4 // label4
// //
@@ -131,28 +131,28 @@
this.label5.TabIndex = 6; this.label5.TabIndex = 6;
this.label5.Text = "Drawing #"; this.label5.Text = "Drawing #";
// //
// comboBox2 // drawingNoBox
// //
this.comboBox2.FormattingEnabled = true; this.drawingNoBox.FormattingEnabled = true;
this.comboBox2.Location = new System.Drawing.Point(388, 75); this.drawingNoBox.Location = new System.Drawing.Point(388, 75);
this.comboBox2.Name = "comboBox2"; this.drawingNoBox.Name = "drawingNoBox";
this.comboBox2.Size = new System.Drawing.Size(174, 25); this.drawingNoBox.Size = new System.Drawing.Size(174, 25);
this.comboBox2.TabIndex = 7; this.drawingNoBox.TabIndex = 7;
// //
// MainForm // MainForm
// //
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
this.ClientSize = new System.Drawing.Size(942, 674); this.ClientSize = new System.Drawing.Size(942, 674);
this.Controls.Add(this.comboBox2); this.Controls.Add(this.drawingNoBox);
this.Controls.Add(this.equipmentNoBox); this.Controls.Add(this.equipmentNoBox);
this.Controls.Add(this.label5); this.Controls.Add(this.label5);
this.Controls.Add(this.comboBox1); this.Controls.Add(this.viewFlipDeciderBox);
this.Controls.Add(this.label4); this.Controls.Add(this.label4);
this.Controls.Add(this.label3); this.Controls.Add(this.label3);
this.Controls.Add(this.label1); this.Controls.Add(this.label1);
this.Controls.Add(this.richTextBox1); this.Controls.Add(this.logTextBox);
this.Controls.Add(this.activeDocTitleBox); this.Controls.Add(this.activeDocTitleBox);
this.Controls.Add(this.button1); this.Controls.Add(this.runButton);
this.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Font = new System.Drawing.Font("Segoe UI", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.MaximizeBox = false; this.MaximizeBox = false;
@@ -167,16 +167,16 @@
#endregion #endregion
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button runButton;
private System.Windows.Forms.TextBox activeDocTitleBox; private System.Windows.Forms.TextBox activeDocTitleBox;
private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.RichTextBox logTextBox;
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label3; private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboBox1; private System.Windows.Forms.ComboBox viewFlipDeciderBox;
private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label4;
private System.Windows.Forms.ComboBox equipmentNoBox; private System.Windows.Forms.ComboBox equipmentNoBox;
private System.Windows.Forms.Label label5; private System.Windows.Forms.Label label5;
private System.Windows.Forms.ComboBox comboBox2; private System.Windows.Forms.ComboBox drawingNoBox;
} }
} }

View File

@@ -38,7 +38,7 @@ namespace ExportDXF.Forms
protected override async void OnLoad(EventArgs e) protected override async void OnLoad(EventArgs e)
{ {
base.OnLoad(e); base.OnLoad(e);
button1.Enabled = false; runButton.Enabled = false;
await InitializeAsync(); await InitializeAsync();
} }
private async Task InitializeAsync() private async Task InitializeAsync()
@@ -50,7 +50,7 @@ namespace ExportDXF.Forms
_solidWorksService.ActiveDocumentChanged += OnActiveDocumentChanged; _solidWorksService.ActiveDocumentChanged += OnActiveDocumentChanged;
LogMessage("Ready", Color.Green); LogMessage("Ready", Color.Green);
UpdateActiveDocumentDisplay(); UpdateActiveDocumentDisplay();
button1.Enabled = true; runButton.Enabled = true;
// Populate equipment and (initial) drawings // Populate equipment and (initial) drawings
await PopulateEquipmentAsync(); await PopulateEquipmentAsync();
} }
@@ -99,13 +99,29 @@ namespace ExportDXF.Forms
var selected = equipmentNoBox.SelectedItem as CutFabApiClient.ApiEquipment; var selected = equipmentNoBox.SelectedItem as CutFabApiClient.ApiEquipment;
if (selected == null) if (selected == null)
{ {
comboBox2.DataSource = null; drawingNoBox.DataSource = null;
return; return;
} }
// Store the currently selected drawing number
var currentSelectedDrawing = drawingNoBox.SelectedItem as CutFabApiClient.ApiDrawingSummary;
var previousDrawingNumber = currentSelectedDrawing?.DrawingNumber;
var drawings = await _apiClient.GetDrawingsForEquipmentAsync(selected.ID); var drawings = await _apiClient.GetDrawingsForEquipmentAsync(selected.ID);
comboBox2.DisplayMember = nameof(CutFabApiClient.ApiDrawingSummary.DrawingNumber); drawingNoBox.DisplayMember = nameof(CutFabApiClient.ApiDrawingSummary.DrawingNumber);
comboBox2.ValueMember = nameof(CutFabApiClient.ApiDrawingSummary.ID); drawingNoBox.ValueMember = nameof(CutFabApiClient.ApiDrawingSummary.ID);
comboBox2.DataSource = drawings; drawingNoBox.DataSource = drawings;
// Try to restore the previous selection if it exists in the new list
if (!string.IsNullOrEmpty(previousDrawingNumber) && drawings.Count > 0)
{
var matchingDrawing = drawings.FirstOrDefault(d => d.DrawingNumber == previousDrawingNumber);
if (matchingDrawing != null)
{
drawingNoBox.SelectedItem = matchingDrawing;
}
}
LogMessage($"Loaded {drawings.Count} drawing(s) for equipment {selected.EquipmentNumber}"); LogMessage($"Loaded {drawings.Count} drawing(s) for equipment {selected.EquipmentNumber}");
} }
catch (Exception ex) catch (Exception ex)
@@ -129,8 +145,8 @@ namespace ExportDXF.Forms
items.Remove(automatic); items.Remove(automatic);
items.Insert(0, automatic); items.Insert(0, automatic);
} }
comboBox1.DataSource = items; viewFlipDeciderBox.DataSource = items;
comboBox1.DisplayMember = "Name"; viewFlipDeciderBox.DisplayMember = "Name";
} }
private async void button1_Click(object sender, EventArgs e) private async void button1_Click(object sender, EventArgs e)
{ {
@@ -157,7 +173,7 @@ namespace ExportDXF.Forms
return; return;
} }
var viewFlipDecider = GetSelectedViewFlipDecider(); var viewFlipDecider = GetSelectedViewFlipDecider();
var drawingNumberText = comboBox2.Text?.Trim(); var drawingNumberText = drawingNoBox.Text?.Trim();
var selectedEquipment = equipmentNoBox.SelectedItem as CutFabApiClient.ApiEquipment; var selectedEquipment = equipmentNoBox.SelectedItem as CutFabApiClient.ApiEquipment;
var exportContext = new ExportContext var exportContext = new ExportContext
{ {
@@ -190,30 +206,30 @@ namespace ExportDXF.Forms
} }
private void CancelExport() private void CancelExport()
{ {
button1.Enabled = false; runButton.Enabled = false;
_cancellationTokenSource?.Cancel(); _cancellationTokenSource?.Cancel();
} }
private IViewFlipDecider GetSelectedViewFlipDecider() private IViewFlipDecider GetSelectedViewFlipDecider()
{ {
var item = comboBox1.SelectedItem as ViewFlipDeciderComboboxItem; var item = viewFlipDeciderBox.SelectedItem as ViewFlipDeciderComboboxItem;
return item?.ViewFlipDecider; return item?.ViewFlipDecider;
} }
private void UpdateUIForExportStart() private void UpdateUIForExportStart()
{ {
activeDocTitleBox.Enabled = false; activeDocTitleBox.Enabled = false;
comboBox1.Enabled = false; viewFlipDeciderBox.Enabled = false;
button1.Image = Properties.Resources.stop_alt; runButton.Image = Properties.Resources.stop_alt;
if (richTextBox1.TextLength != 0) if (logTextBox.TextLength != 0)
{ {
richTextBox1.AppendText("\n\n"); logTextBox.AppendText("\n\n");
} }
} }
private void UpdateUIForExportComplete() private void UpdateUIForExportComplete()
{ {
activeDocTitleBox.Enabled = true; activeDocTitleBox.Enabled = true;
comboBox1.Enabled = true; viewFlipDeciderBox.Enabled = true;
button1.Image = Properties.Resources.play; runButton.Image = Properties.Resources.play;
button1.Enabled = true; runButton.Enabled = true;
} }
private void OnActiveDocumentChanged(object sender, EventArgs e) private void OnActiveDocumentChanged(object sender, EventArgs e)
{ {
@@ -233,20 +249,19 @@ namespace ExportDXF.Forms
private void UpdatePrefixFromActiveDocument() private void UpdatePrefixFromActiveDocument()
{ {
var activeDoc = _solidWorksService.GetActiveDocument(); var activeDoc = _solidWorksService.GetActiveDocument();
if (activeDoc == null) if (activeDoc == null)
{
return; return;
}
if (activeDoc.DocumentType == DocumentType.Drawing) if (activeDoc.DocumentType == DocumentType.Drawing)
{ {
var drawingInfo = DrawingInfo.Parse(activeDoc.Title); var drawingInfo = DrawingInfo.Parse(activeDoc.Title);
if (drawingInfo != null) if (drawingInfo != null)
{ {
drawingNoBox.Text = drawingInfo.ToString();
} }
} }
else
{
}
} }
private void activeDocTitleBox_TextChanged(object sender, EventArgs e) private void activeDocTitleBox_TextChanged(object sender, EventArgs e)
{ {
@@ -261,13 +276,13 @@ namespace ExportDXF.Forms
} }
if (color.HasValue) if (color.HasValue)
{ {
richTextBox1.AppendText(message + System.Environment.NewLine, color.Value); logTextBox.AppendText(message + System.Environment.NewLine, color.Value);
} }
else else
{ {
richTextBox1.AppendText(message + System.Environment.NewLine); logTextBox.AppendText(message + System.Environment.NewLine);
} }
richTextBox1.ScrollToCaret(); logTextBox.ScrollToCaret();
} }
} }
} }