feat: Add ParamDrawingPanel UI component.
This commit is contained in:
parent
f8e6443d04
commit
63db980cdc
@ -732,14 +732,14 @@ namespace CadParamPluging.UI
|
||||
if (!string.IsNullOrEmpty(val))
|
||||
{
|
||||
// 尝试选中
|
||||
int idx = cb.FindStringExact(val);
|
||||
if (idx >= 0)
|
||||
for (int i = 0; i < cb.Items.Count; i++)
|
||||
{
|
||||
cb.SelectedIndex = idx;
|
||||
return;
|
||||
if (cb.Items[i] is DropdownItem item && string.Equals(item.Value, val, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
cb.SelectedIndex = i;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// 如果没有,可能手动 Text? ComboBoxStyle.DropDownList 不允许。
|
||||
// 如果是 DropDownList 且不在列表中,就无法选中。
|
||||
}
|
||||
}
|
||||
|
||||
@ -758,7 +758,7 @@ namespace CadParamPluging.UI
|
||||
|
||||
private TemplateParams CollectTemplateParams()
|
||||
{
|
||||
var specialCondition = _cbScale.Text?.Trim();
|
||||
var specialCondition = GetComboBoxValue(_cbScale);
|
||||
if (string.Equals(specialCondition, "无", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
specialCondition = null;
|
||||
@ -766,13 +766,29 @@ namespace CadParamPluging.UI
|
||||
|
||||
return new TemplateParams
|
||||
{
|
||||
ProjectType = _cbProjectType.Text?.Trim(),
|
||||
DrawingType = _cbDrawingType.Text?.Trim(),
|
||||
SheetSize = _cbSheetSize.Text?.Trim(),
|
||||
ProjectType = GetComboBoxValue(_cbProjectType),
|
||||
DrawingType = GetComboBoxValue(_cbDrawingType),
|
||||
SheetSize = GetComboBoxValue(_cbSheetSize),
|
||||
Scale = specialCondition
|
||||
};
|
||||
}
|
||||
|
||||
private class DropdownItem
|
||||
{
|
||||
public string Display { get; set; }
|
||||
public string Value { get; set; }
|
||||
public override string ToString() => Display;
|
||||
}
|
||||
|
||||
private static string GetComboBoxValue(ComboBox cb)
|
||||
{
|
||||
if (cb.SelectedItem is DropdownItem item)
|
||||
{
|
||||
return item.Value;
|
||||
}
|
||||
return cb.Text?.Trim();
|
||||
}
|
||||
|
||||
private static ComboBox CreateComboBox(System.Collections.Generic.IEnumerable<string> items)
|
||||
{
|
||||
var cb = new ComboBox
|
||||
@ -781,15 +797,7 @@ namespace CadParamPluging.UI
|
||||
Width = 160
|
||||
};
|
||||
|
||||
var arr = (items ?? Enumerable.Empty<string>()).Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToArray();
|
||||
if (arr.Length > 0)
|
||||
{
|
||||
cb.Items.AddRange(arr);
|
||||
}
|
||||
if (cb.Items.Count > 0)
|
||||
{
|
||||
cb.SelectedIndex = 0;
|
||||
}
|
||||
ResetComboBoxItems(cb, items);
|
||||
return cb;
|
||||
}
|
||||
|
||||
@ -800,7 +808,7 @@ namespace CadParamPluging.UI
|
||||
return;
|
||||
}
|
||||
|
||||
var previous = cb.Text;
|
||||
var previousValue = GetComboBoxValue(cb);
|
||||
var arr = (items ?? Enumerable.Empty<string>()).Where(s => !string.IsNullOrWhiteSpace(s)).Select(s => s.Trim()).ToArray();
|
||||
|
||||
cb.BeginUpdate();
|
||||
@ -809,8 +817,23 @@ namespace CadParamPluging.UI
|
||||
cb.Items.Clear();
|
||||
if (arr.Length > 0)
|
||||
{
|
||||
cb.Items.AddRange(arr);
|
||||
var idx = Array.FindIndex(arr, v => string.Equals(v, previous, StringComparison.OrdinalIgnoreCase));
|
||||
var dropDownItems = new System.Collections.Generic.List<DropdownItem>();
|
||||
foreach (var item in arr)
|
||||
{
|
||||
string display = item;
|
||||
if (item == "中心冲孔")
|
||||
{
|
||||
display = "无扩孔";
|
||||
}
|
||||
else if (item == "非中心冲孔" || item == "非中心冲孔有扩孔")
|
||||
{
|
||||
display = "有扩孔";
|
||||
}
|
||||
dropDownItems.Add(new DropdownItem { Display = display, Value = item });
|
||||
}
|
||||
cb.Items.AddRange(dropDownItems.ToArray());
|
||||
|
||||
var idx = dropDownItems.FindIndex(v => string.Equals(v.Value, previousValue, StringComparison.OrdinalIgnoreCase));
|
||||
cb.SelectedIndex = idx >= 0 ? idx : 0;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user