diff --git a/MainViewModel.cs b/MainViewModel.cs index 6f2b176..d8de8dc 100644 --- a/MainViewModel.cs +++ b/MainViewModel.cs @@ -416,37 +416,26 @@ namespace CtrEditor if (string.IsNullOrEmpty(imageName)) return; var imageData = GetOrCreateImageData(imageName); - var currentCustomName = imageData.CustomName; - var dialog = new PopUps.RenameImageWindow(imageName, currentCustomName); + var dialog = new PopUps.RenameImageWindow(imageName, imageData); dialog.Owner = MainWindow; if (dialog.ShowDialog() == true) { - string newName = dialog.NewImageName?.Trim() ?? string.Empty; - - if (newName != currentCustomName) + // El dialog ya ha modificado directamente el imageData + // Solo necesitamos verificar si debemos remover la entrada si está vacía + if (string.IsNullOrEmpty(imageData.CustomName) && + imageData.Tags.Count == 0 && + string.IsNullOrEmpty(imageData.Etiquetas)) { - if (string.IsNullOrEmpty(newName)) - { - // Si el nuevo nombre está vacío, removemos la entrada personalizada - imageData.CustomName = string.Empty; - if (string.IsNullOrEmpty(imageData.CustomName) && imageData.Tags.Count == 0) - { - _imageDataDictionary.Remove(imageName); - } - } - else - { - imageData.CustomName = newName; - } - - // Forzar actualización del UI usando CollectionViewSource - var collectionView = System.Windows.Data.CollectionViewSource.GetDefaultView(ListaImagenes); - collectionView?.Refresh(); - - HasUnsavedChanges = true; + _imageDataDictionary.Remove(imageName); } + + // Forzar actualización del UI usando CollectionViewSource + var collectionView = System.Windows.Data.CollectionViewSource.GetDefaultView(ListaImagenes); + collectionView?.Refresh(); + + HasUnsavedChanges = true; } } diff --git a/MainWindow.xaml b/MainWindow.xaml index 39a3283..78cd097 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -99,7 +99,7 @@ - + diff --git a/Models/ImageData.cs b/Models/ImageData.cs index 1683da0..e186d42 100644 --- a/Models/ImageData.cs +++ b/Models/ImageData.cs @@ -1,6 +1,9 @@ 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 { @@ -8,9 +11,11 @@ namespace CtrEditor.Models { private string _customName; private List _tags; + private string _etiquetas; public string FileName { get; set; } + [DisplayName("Nombre personalizado")] public string CustomName { get => _customName; @@ -21,13 +26,59 @@ namespace CtrEditor.Models } } + [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(); } } @@ -38,6 +89,7 @@ namespace CtrEditor.Models FileName = string.Empty; _customName = string.Empty; _tags = new List(); + _etiquetas = string.Empty; } public ImageData(string fileName, string customName = null, List tags = null) @@ -45,6 +97,7 @@ namespace CtrEditor.Models FileName = fileName; _customName = customName ?? string.Empty; _tags = tags ?? new List(); + _etiquetas = string.Join(" ", _tags.Select(tag => tag.StartsWith("#") ? tag : "#" + tag)); } public event PropertyChangedEventHandler PropertyChanged; diff --git a/ObjetosSim/TagEditorAttribute.cs b/ObjetosSim/TagEditorAttribute.cs index f1c4265..baa3ce6 100644 --- a/ObjetosSim/TagEditorAttribute.cs +++ b/ObjetosSim/TagEditorAttribute.cs @@ -5,6 +5,7 @@ using System.Windows.Data; using CtrEditor.PopUps; using Xceed.Wpf.Toolkit.PropertyGrid; using Xceed.Wpf.Toolkit.PropertyGrid.Editors; +using CtrEditor.Models; namespace CtrEditor.ObjetosSim { @@ -50,18 +51,18 @@ namespace CtrEditor.ObjetosSim { try { - // Obtener el objeto que se está editando - if (propertyItem.Instance is osBase osObject) - { - // Obtener el MainWindow para acceder a todos los objetos - var mainWindow = Application.Current.Windows - .OfType() - .FirstOrDefault(); + // Obtener el MainWindow para acceder a todos los objetos + var mainWindow = Application.Current.Windows + .OfType() + .FirstOrDefault(); - if (mainWindow?.DataContext is MainViewModel mainViewModel) + if (mainWindow?.DataContext is MainViewModel mainViewModel) + { + // Determinar si el objeto es osBase o ImageData + if (propertyItem.Instance is osBase osObject) { - // Abrir el editor de etiquetas - var tagEditor = new TagEditorWindow(osObject, mainViewModel.ObjetosSimulables); + // Abrir el editor de etiquetas para osBase + var tagEditor = new TagEditorWindow(osObject, mainViewModel.ObjetosSimulables, mainViewModel._imageDataDictionary); tagEditor.Owner = mainWindow; if (tagEditor.ShowDialog() == true) @@ -71,6 +72,22 @@ namespace CtrEditor.ObjetosSim textBox.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget(); } } + else if (propertyItem.Instance is ImageData imageData) + { + // Para ImageData, crear un osBase temporal para usar el editor + var tempOsBase = new osTextPlate(); + tempOsBase.Etiquetas = imageData.Etiquetas; + + var tagEditor = new TagEditorWindow(tempOsBase, mainViewModel.ObjetosSimulables, mainViewModel._imageDataDictionary); + tagEditor.Owner = mainWindow; + + if (tagEditor.ShowDialog() == true) + { + // Actualizar ImageData con las nuevas etiquetas + imageData.Etiquetas = tempOsBase.Etiquetas; + textBox.GetBindingExpression(TextBox.TextProperty)?.UpdateTarget(); + } + } } } catch (Exception ex) diff --git a/PopUps/RenameImageWindow.xaml b/PopUps/RenameImageWindow.xaml index b9cbf27..d5e4aa8 100644 --- a/PopUps/RenameImageWindow.xaml +++ b/PopUps/RenameImageWindow.xaml @@ -1,11 +1,11 @@ + xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit" + Title="Editar Información de Imagen" Height="400" Width="500" + WindowStartupLocation="CenterOwner" ResizeMode="CanResize"> - @@ -13,12 +13,43 @@ - + - - + + + + + + + + + + + + +