using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; using CtrEditor.ObjetosSim; using Xceed.Wpf.Toolkit.PropertyGrid.Editors; using System.Linq; namespace CtrEditor.Models { public class ImageData : INotifyPropertyChanged { private string _customName; private List _tags; private string _etiquetas; public string FileName { get; set; } [DisplayName("Nombre personalizado")] public string CustomName { get => _customName; set { _customName = value; OnPropertyChanged(); } } [Browsable(false)] public List Tags { get => _tags ?? new List(); set { _tags = value; _etiquetas = string.Join(" ", value.Select(tag => tag.StartsWith("#") ? tag : "#" + tag)); OnPropertyChanged(); OnPropertyChanged(nameof(Etiquetas)); } } [DisplayName("Etiquetas")] [property: Editor(typeof(TagPropertyEditor), typeof(TagPropertyEditor))] public string Etiquetas { get => _etiquetas ?? string.Empty; set { _etiquetas = value ?? string.Empty; // Convertir string de etiquetas a List if (string.IsNullOrWhiteSpace(_etiquetas)) { _tags = new List(); } else { _tags = _etiquetas.Split(' ', StringSplitOptions.RemoveEmptyEntries) .Select(tag => tag.StartsWith("#") ? tag.Substring(1) : tag) .Where(tag => !string.IsNullOrWhiteSpace(tag)) .ToList(); } OnPropertyChanged(); OnPropertyChanged(nameof(Tags)); } } /// /// Lista de etiquetas sin el prefijo #, compatible con osBase /// [Browsable(false)] public List ListaEtiquetas { get { if (string.IsNullOrWhiteSpace(Etiquetas)) return new List(); return Etiquetas.Split(' ', StringSplitOptions.RemoveEmptyEntries) .Select(tag => tag.StartsWith("#") ? tag.Substring(1) : tag) .Where(tag => !string.IsNullOrWhiteSpace(tag)) .ToList(); } } public string DisplayName => !string.IsNullOrEmpty(CustomName) ? CustomName : FileName; public ImageData() { FileName = string.Empty; _customName = string.Empty; _tags = new List(); _etiquetas = string.Empty; } public ImageData(string fileName, string customName = null, List tags = null) { FileName = fileName; _customName = customName ?? string.Empty; _tags = tags ?? new List(); _etiquetas = string.Join(" ", _tags.Select(tag => tag.StartsWith("#") ? tag : "#" + tag)); } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } }