#nullable enable using System.Collections.Generic; using System.Linq; namespace UVC.UIToolkit { /// /// 드롭다운 목록 속성 데이터 클래스입니다. /// UI는 UTKDropdownPropertyItemView에서 담당합니다. /// public class UTKDropdownPropertyItem : UTKPropertyItemBase { #region Fields private List _choices; #endregion #region Properties /// 속성 타입 public override UTKPropertyType PropertyType => UTKPropertyType.DropdownList; /// 선택 가능한 항목 목록 public List Choices { get => _choices; set => _choices = value ?? new List(); } #endregion #region Constructor /// /// 드롭다운 속성을 생성합니다. /// /// 고유 ID /// 표시 이름 /// 선택 항목 목록 /// 초기 선택 값 /// 읽기 전용 여부 public UTKDropdownPropertyItem(string id, string name, List choices, string initialValue = "", bool isReadOnly = false) : base(id, name, initialValue) { _choices = choices ?? new List(); // initialValue가 choices에 없으면 첫 번째 항목 선택 if (!string.IsNullOrEmpty(initialValue) && !_choices.Contains(initialValue) && _choices.Count > 0) { Value = _choices[0]; } IsReadOnly = isReadOnly; } /// /// 드롭다운 속성을 생성합니다 (인덱스 기반). /// /// 고유 ID /// 표시 이름 /// 선택 항목 목록 /// 초기 선택 인덱스 /// 읽기 전용 여부 public UTKDropdownPropertyItem(string id, string name, IEnumerable choices, int selectedIndex = 0, bool isReadOnly = false) : base(id, name, string.Empty) { _choices = choices?.ToList() ?? new List(); if (_choices.Count > 0 && selectedIndex >= 0 && selectedIndex < _choices.Count) { Value = _choices[selectedIndex]; } else if (_choices.Count > 0) { Value = _choices[0]; } IsReadOnly = isReadOnly; } #endregion #region Public Methods /// 선택 항목 추가 public void AddChoice(string choice) { if (!_choices.Contains(choice)) { _choices.Add(choice); } } /// 선택 항목 제거 public bool RemoveChoice(string choice) { bool removed = _choices.Remove(choice); if (removed && Value == choice && _choices.Count > 0) { Value = _choices[0]; } return removed; } #endregion } }