2025-02-26 07:37:19 -03:00
|
|
|
|
using System.Collections.ObjectModel;
|
2025-03-01 19:28:29 -03:00
|
|
|
|
using System.ComponentModel; // Add this for PropertyChangedEventHandler and PropertyChangedEventArgs
|
2025-02-26 07:37:19 -03:00
|
|
|
|
using System.Reflection;
|
2025-03-01 19:28:29 -03:00
|
|
|
|
using System.Text.Json.Serialization;
|
2025-02-26 07:37:19 -03:00
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
|
|
using CtrEditor.ObjetosSim;
|
|
|
|
|
|
|
|
|
|
namespace CtrEditor.Controls
|
|
|
|
|
{
|
2025-03-01 19:28:29 -03:00
|
|
|
|
public class FilterChangedEventArgs : EventArgs
|
|
|
|
|
{
|
|
|
|
|
public osVisFilterViewModel FilterViewModel { get; private set; }
|
|
|
|
|
|
|
|
|
|
public FilterChangedEventArgs(osVisFilterViewModel viewModel)
|
|
|
|
|
{
|
|
|
|
|
FilterViewModel = viewModel;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-26 07:37:19 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Interaction logic for osVisFilter.xaml
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class osVisFilter : UserControl
|
|
|
|
|
{
|
|
|
|
|
public osVisFilter()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2025-03-01 19:28:29 -03:00
|
|
|
|
DataContext = FilterViewModel = new osVisFilterViewModel { Parent = this }; // Set the Parent property
|
2025-02-26 07:37:19 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public osVisFilterViewModel FilterViewModel { get; private set; }
|
|
|
|
|
|
2025-03-01 19:28:29 -03:00
|
|
|
|
public event EventHandler<FilterChangedEventArgs> FilterChanged;
|
|
|
|
|
|
|
|
|
|
public virtual void OnFilterChanged() // Changed from protected to public
|
|
|
|
|
{
|
|
|
|
|
FilterChanged?.Invoke(this, new FilterChangedEventArgs(FilterViewModel));
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-26 07:37:19 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the type filters based on the provided types
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void UpdateAvailableTypes(IEnumerable<Type> types)
|
|
|
|
|
{
|
|
|
|
|
FilterViewModel.UpdateTypeFilters(types);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// ViewModel for the osVisFilter control
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class osVisFilterViewModel : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private bool showAll = true;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private bool showCloned;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private bool showAutoCreated;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private bool showEnableOnAllPages;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private bool showOnThisPage;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private ObservableCollection<TypeFilterItem> typeFilters = new ObservableCollection<TypeFilterItem>();
|
|
|
|
|
|
2025-03-01 19:28:29 -03:00
|
|
|
|
partial void OnShowAllChanged(bool value)
|
|
|
|
|
{
|
|
|
|
|
NotifyFilterChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partial void OnShowClonedChanged(bool value)
|
|
|
|
|
{
|
|
|
|
|
NotifyFilterChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partial void OnShowAutoCreatedChanged(bool value)
|
|
|
|
|
{
|
|
|
|
|
NotifyFilterChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partial void OnShowEnableOnAllPagesChanged(bool value)
|
|
|
|
|
{
|
|
|
|
|
NotifyFilterChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partial void OnShowOnThisPageChanged(bool value)
|
|
|
|
|
{
|
|
|
|
|
NotifyFilterChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
partial void OnTypeFiltersChanged(ObservableCollection<TypeFilterItem> value)
|
|
|
|
|
{
|
|
|
|
|
if (value != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var filter in value)
|
|
|
|
|
{
|
|
|
|
|
filter.PropertyChanged += (s, e) =>
|
|
|
|
|
{
|
|
|
|
|
if (e.PropertyName == nameof(TypeFilterItem.IsSelected))
|
|
|
|
|
{
|
|
|
|
|
NotifyFilterChanged();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void NotifyFilterChanged()
|
|
|
|
|
{
|
|
|
|
|
if (this.Parent is osVisFilter filter)
|
|
|
|
|
{
|
|
|
|
|
filter.OnFilterChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
|
|
|
|
public osVisFilter Parent { get; set; }
|
|
|
|
|
|
2025-02-26 07:37:19 -03:00
|
|
|
|
public osVisFilterViewModel()
|
|
|
|
|
{
|
|
|
|
|
// PropertyChanged listeners could be added here if needed
|
2025-03-01 19:28:29 -03:00
|
|
|
|
if (this.Parent is osVisFilter filter)
|
|
|
|
|
{
|
|
|
|
|
filter.OnFilterChanged();
|
|
|
|
|
}
|
2025-02-26 07:37:19 -03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Updates the type filters based on the provided types
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void UpdateTypeFilters(IEnumerable<Type> types)
|
|
|
|
|
{
|
|
|
|
|
// Remove types that are no longer present
|
|
|
|
|
var typesToRemove = TypeFilters
|
|
|
|
|
.Where(tf => !types.Contains(tf.Type))
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var item in typesToRemove)
|
|
|
|
|
{
|
2025-03-01 19:28:29 -03:00
|
|
|
|
UnsubscribeFromTypeFilter(item);
|
2025-02-26 07:37:19 -03:00
|
|
|
|
TypeFilters.Remove(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Add new types that aren't already in the list
|
|
|
|
|
foreach (var type in types)
|
|
|
|
|
{
|
|
|
|
|
if (!TypeFilters.Any(tf => tf.Type == type))
|
|
|
|
|
{
|
2025-03-01 19:28:29 -03:00
|
|
|
|
var newFilter = new TypeFilterItem(type)
|
2025-02-26 07:37:19 -03:00
|
|
|
|
{
|
|
|
|
|
DisplayName = GetTypeDisplayName(type),
|
|
|
|
|
IsSelected = true
|
2025-03-01 19:28:29 -03:00
|
|
|
|
};
|
|
|
|
|
SubscribeToTypeFilter(newFilter);
|
|
|
|
|
TypeFilters.Add(newFilter);
|
2025-02-26 07:37:19 -03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-01 19:28:29 -03:00
|
|
|
|
private void SubscribeToTypeFilter(TypeFilterItem filter)
|
|
|
|
|
{
|
|
|
|
|
filter.PropertyChanged += TypeFilter_PropertyChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UnsubscribeFromTypeFilter(TypeFilterItem filter)
|
|
|
|
|
{
|
|
|
|
|
filter.PropertyChanged -= TypeFilter_PropertyChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TypeFilter_PropertyChanged(object sender, PropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.PropertyName == nameof(TypeFilterItem.IsSelected))
|
|
|
|
|
{
|
|
|
|
|
NotifyFilterChanged();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-26 07:37:19 -03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets the display name for a type, using the NombreClase static method if available
|
|
|
|
|
/// </summary>
|
|
|
|
|
private string GetTypeDisplayName(Type type)
|
|
|
|
|
{
|
|
|
|
|
var methodInfo = type.GetMethod("NombreClase",
|
|
|
|
|
BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
|
|
|
|
return methodInfo != null ?
|
|
|
|
|
methodInfo.Invoke(null, null)?.ToString() :
|
|
|
|
|
type.Name;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Represents a type filter item with selection state
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class TypeFilterItem : ObservableObject
|
|
|
|
|
{
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private bool isSelected = true;
|
|
|
|
|
|
|
|
|
|
[ObservableProperty]
|
|
|
|
|
private string displayName;
|
|
|
|
|
|
|
|
|
|
public Type Type { get; }
|
|
|
|
|
|
|
|
|
|
public TypeFilterItem(Type type)
|
|
|
|
|
{
|
|
|
|
|
Type = type;
|
|
|
|
|
DisplayName = type?.Name ?? "Unknown Type";
|
|
|
|
|
}
|
2025-03-01 19:28:29 -03:00
|
|
|
|
|
|
|
|
|
partial void OnIsSelectedChanged(bool value)
|
|
|
|
|
{
|
|
|
|
|
OnPropertyChanged(nameof(IsSelected));
|
|
|
|
|
}
|
2025-02-26 07:37:19 -03:00
|
|
|
|
}
|
|
|
|
|
}
|