Creado Control osVisFilter
This commit is contained in:
parent
b6b078f8ce
commit
3d70992b1a
|
@ -0,0 +1,52 @@
|
||||||
|
<UserControl x:Class="CtrEditor.Controls.osVisFilter" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:CtrEditor.Controls"
|
||||||
|
mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="200">
|
||||||
|
<UserControl.Resources>
|
||||||
|
<Style x:Key="FilterCheckBoxStyle" TargetType="CheckBox">
|
||||||
|
<Setter Property="Margin" Value="0,2,0,2" />
|
||||||
|
<Setter Property="FontSize" Value="12" />
|
||||||
|
</Style>
|
||||||
|
<Style x:Key="FilterHeaderStyle" TargetType="TextBlock">
|
||||||
|
<Setter Property="FontWeight" Value="Bold" />
|
||||||
|
<Setter Property="Margin" Value="0,5,0,2" />
|
||||||
|
</Style>
|
||||||
|
<Style x:Key="FilterSeparatorStyle" TargetType="Separator">
|
||||||
|
<Setter Property="Margin" Value="0,5,0,5" />
|
||||||
|
</Style>
|
||||||
|
</UserControl.Resources>
|
||||||
|
|
||||||
|
<Border BorderBrush="LightGray" BorderThickness="1" Padding="5">
|
||||||
|
<ScrollViewer VerticalScrollBarVisibility="Auto">
|
||||||
|
<StackPanel>
|
||||||
|
<!-- Fixed Filter Options -->
|
||||||
|
<TextBlock Text="Filter Options" Style="{StaticResource FilterHeaderStyle}" />
|
||||||
|
<CheckBox Content="All" IsChecked="{Binding ShowAll, Mode=TwoWay}"
|
||||||
|
Style="{StaticResource FilterCheckBoxStyle}" />
|
||||||
|
<CheckBox Content="Cloned" IsChecked="{Binding ShowCloned, Mode=TwoWay}"
|
||||||
|
Style="{StaticResource FilterCheckBoxStyle}" />
|
||||||
|
<CheckBox Content="Auto Created" IsChecked="{Binding ShowAutoCreated, Mode=TwoWay}"
|
||||||
|
Style="{StaticResource FilterCheckBoxStyle}" />
|
||||||
|
<CheckBox Content="Enable On All Pages" IsChecked="{Binding ShowEnableOnAllPages, Mode=TwoWay}"
|
||||||
|
Style="{StaticResource FilterCheckBoxStyle}" />
|
||||||
|
<CheckBox Content="Show On This Page" IsChecked="{Binding ShowOnThisPage, Mode=TwoWay}"
|
||||||
|
Style="{StaticResource FilterCheckBoxStyle}" />
|
||||||
|
|
||||||
|
<!-- Separator between fixed and dynamic options -->
|
||||||
|
<Separator Style="{StaticResource FilterSeparatorStyle}" />
|
||||||
|
|
||||||
|
<!-- Type Filter Options -->
|
||||||
|
<TextBlock Text="Object Types" Style="{StaticResource FilterHeaderStyle}" />
|
||||||
|
<ItemsControl ItemsSource="{Binding TypeFilters}">
|
||||||
|
<ItemsControl.ItemTemplate>
|
||||||
|
<DataTemplate>
|
||||||
|
<CheckBox Content="{Binding DisplayName}" IsChecked="{Binding IsSelected, Mode=TwoWay}"
|
||||||
|
Style="{StaticResource FilterCheckBoxStyle}" />
|
||||||
|
</DataTemplate>
|
||||||
|
</ItemsControl.ItemTemplate>
|
||||||
|
</ItemsControl>
|
||||||
|
</StackPanel>
|
||||||
|
</ScrollViewer>
|
||||||
|
</Border>
|
||||||
|
</UserControl>
|
|
@ -0,0 +1,121 @@
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Reflection;
|
||||||
|
using System.Windows;
|
||||||
|
using System.Windows.Controls;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CtrEditor.ObjetosSim;
|
||||||
|
|
||||||
|
namespace CtrEditor.Controls
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Interaction logic for osVisFilter.xaml
|
||||||
|
/// </summary>
|
||||||
|
public partial class osVisFilter : UserControl
|
||||||
|
{
|
||||||
|
public osVisFilter()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
DataContext = FilterViewModel = new osVisFilterViewModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
public osVisFilterViewModel FilterViewModel { get; private set; }
|
||||||
|
|
||||||
|
/// <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>();
|
||||||
|
|
||||||
|
public osVisFilterViewModel()
|
||||||
|
{
|
||||||
|
// PropertyChanged listeners could be added here if needed
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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)
|
||||||
|
{
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
TypeFilters.Add(new TypeFilterItem(type)
|
||||||
|
{
|
||||||
|
DisplayName = GetTypeDisplayName(type),
|
||||||
|
IsSelected = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <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";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -130,9 +130,6 @@ namespace CtrEditor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[ObservableProperty]
|
|
||||||
public ICollectionView vistaFiltrada;
|
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private float canvasLeft;
|
private float canvasLeft;
|
||||||
|
|
||||||
|
@ -276,13 +273,10 @@ namespace CtrEditor
|
||||||
habilitarEliminarUserControl = false;
|
habilitarEliminarUserControl = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
[ObservableProperty]
|
|
||||||
public ObjetosSimulablesFilterTypes osListFilter;
|
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private TipoSimulable selectedItem;
|
private TipoSimulable selectedItem;
|
||||||
|
|
||||||
public ICollectionView ObjetosSimulablesFiltered { get; }
|
|
||||||
public ICollectionView ObjetosSimulablesAllPages { get; }
|
public ICollectionView ObjetosSimulablesAllPages { get; }
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
|
@ -298,16 +292,10 @@ namespace CtrEditor
|
||||||
|
|
||||||
partial void OnObjetosSimulablesChanged(ObservableCollection<osBase> value)
|
partial void OnObjetosSimulablesChanged(ObservableCollection<osBase> value)
|
||||||
{
|
{
|
||||||
VistaFiltrada = CollectionViewSource.GetDefaultView(ObjetosSimulables);
|
|
||||||
VistaFiltrada.Filter = FiltrarObjetos;
|
|
||||||
ObjetosSimulables.CollectionChanged += (s, e) =>
|
|
||||||
{
|
|
||||||
VistaFiltrada.Refresh();
|
|
||||||
if (!inhibitSaveChangesControl && e.Action != NotifyCollectionChangedAction.Move)
|
|
||||||
HasUnsavedChanges = true;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Constructor
|
// Constructor
|
||||||
//
|
//
|
||||||
|
@ -319,10 +307,8 @@ namespace CtrEditor
|
||||||
OpenWorkDirectoryCommand = new RelayCommand(OpenWorkDirectory);
|
OpenWorkDirectoryCommand = new RelayCommand(OpenWorkDirectory);
|
||||||
datosDeTrabajo = new DatosDeTrabajo();
|
datosDeTrabajo = new DatosDeTrabajo();
|
||||||
|
|
||||||
OsListFilter = new ObjetosSimulablesFilterTypes();
|
// Initialize ObjetosSimulables first
|
||||||
OsListFilter.All = true;
|
ObjetosSimulables = new ObservableCollection<osBase>();
|
||||||
|
|
||||||
osListFilter.PropertyChanged += OsListFilter_PropertyChanged;
|
|
||||||
|
|
||||||
ObjetosSimulables = new ObservableCollection<osBase>();
|
ObjetosSimulables = new ObservableCollection<osBase>();
|
||||||
|
|
||||||
|
@ -380,21 +366,25 @@ namespace CtrEditor
|
||||||
|
|
||||||
_stateManager = new StateManager(EstadoPersistente.Instance.directorio, this);
|
_stateManager = new StateManager(EstadoPersistente.Instance.directorio, this);
|
||||||
_stateSerializer = new StateSerializer(this, datosDeTrabajo, simulationManager);
|
_stateSerializer = new StateSerializer(this, datosDeTrabajo, simulationManager);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OsListFilter_PropertyChanged(object? sender, PropertyChangedEventArgs e)
|
|
||||||
|
public void LoadStateObjetosSimulables()
|
||||||
{
|
{
|
||||||
VistaFiltrada.Refresh();
|
if (SelectedImage != null)
|
||||||
|
{
|
||||||
|
_stateSerializer.LoadState(SelectedImage);
|
||||||
|
|
||||||
|
// Restaurar visibilidad según el filtro actual
|
||||||
|
foreach (var obj in ObjetosSimulables)
|
||||||
|
{
|
||||||
|
if (obj.VisualRepresentation != null)
|
||||||
|
obj.VisualRepresentation.Visibility = Visibility.Visible;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool FiltrarObjetos(object item)
|
|
||||||
{
|
|
||||||
var objeto = item as osBase;
|
|
||||||
|
|
||||||
return osListFilter.All || (objeto.Cloned == osListFilter.Cloned) &&
|
|
||||||
(objeto.Enable_On_All_Pages == osListFilter.Enable_On_All_Pages) &&
|
|
||||||
(objeto.Show_On_This_Page == osListFilter.Show_On_This_Page);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void LoadInitialData()
|
public void LoadInitialData()
|
||||||
{
|
{
|
||||||
|
@ -838,14 +828,6 @@ namespace CtrEditor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LoadStateObjetosSimulables()
|
|
||||||
{
|
|
||||||
if (SelectedImage != null)
|
|
||||||
{
|
|
||||||
_stateSerializer.LoadState(SelectedImage);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Se cargan los datos de cada UserControl en el StackPanel
|
// Se cargan los datos de cada UserControl en el StackPanel
|
||||||
public void CargarPropiedadesosDatos(osBase selectedObject, Controls.PanelEdicionControl PanelEdicion, ResourceDictionary Resources)
|
public void CargarPropiedadesosDatos(osBase selectedObject, Controls.PanelEdicionControl PanelEdicion, ResourceDictionary Resources)
|
||||||
{
|
{
|
||||||
|
|
|
@ -261,12 +261,9 @@
|
||||||
|
|
||||||
</ToolBar>
|
</ToolBar>
|
||||||
</ToolBarTray>
|
</ToolBarTray>
|
||||||
<xctk:PropertyGrid Grid.Row="1" x:Name="PanelFilter" AutoGenerateProperties="True"
|
<!-- Filter Control -->
|
||||||
ShowDescriptionByTooltip="False" ShowSearchBox="False" ShowSortOptions="False"
|
|
||||||
ShowSummary="False" ShowTitle="False" SelectedObject="{Binding OsListFilter}">
|
|
||||||
</xctk:PropertyGrid>
|
|
||||||
<!-- ListBox -->
|
<!-- ListBox -->
|
||||||
<ListBox x:Name="ListaOs" Grid.Row="2" Margin="5" ItemsSource="{Binding VistaFiltrada}"
|
<ListBox x:Name="ListaOs" Grid.Row="2" Margin="5" ItemsSource="{Binding ObjetosSimulables}"
|
||||||
SelectedItem="{Binding SelectedItemOsList, Mode=TwoWay}"
|
SelectedItem="{Binding SelectedItemOsList, Mode=TwoWay}"
|
||||||
SelectionChanged="ListaOs_SelectionChanged">
|
SelectionChanged="ListaOs_SelectionChanged">
|
||||||
<ListBox.ItemTemplate>
|
<ListBox.ItemTemplate>
|
||||||
|
|
|
@ -403,18 +403,26 @@ namespace CtrEditor
|
||||||
|
|
||||||
public void SelectObject(osBase obj)
|
public void SelectObject(osBase obj)
|
||||||
{
|
{
|
||||||
if (!_selectedObjects.Contains(obj))
|
if (_mainWindow.DataContext is MainViewModel vm)
|
||||||
{
|
{
|
||||||
_selectedObjects.Add(obj);
|
// Add new object if not already selected
|
||||||
obj.IsSelected = true;
|
if (!_selectedObjects.Contains(obj))
|
||||||
|
|
||||||
// Agregar highlight visual solo si estamos en modo multi-selección
|
|
||||||
if (_mainWindow.DataContext is MainViewModel vm && vm.IsMultiSelectionActive)
|
|
||||||
{
|
{
|
||||||
AddSelectionHighlight(obj.VisualRepresentation);
|
// If not in multi-selection mode, clear existing selection first
|
||||||
}
|
if (!vm.IsMultiSelectionActive)
|
||||||
|
ClearSelection();
|
||||||
|
|
||||||
UpdateSelectionVisuals();
|
_selectedObjects.Add(obj);
|
||||||
|
obj.IsSelected = true;
|
||||||
|
|
||||||
|
// Add highlight visual only if in multi-selection mode
|
||||||
|
if (vm.IsMultiSelectionActive)
|
||||||
|
{
|
||||||
|
AddSelectionHighlight(obj.VisualRepresentation);
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateSelectionVisuals();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,19 +17,6 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
namespace CtrEditor
|
namespace CtrEditor
|
||||||
{
|
{
|
||||||
|
|
||||||
public partial class ObjetosSimulablesFilterTypes : ObservableObject
|
|
||||||
{
|
|
||||||
[ObservableProperty]
|
|
||||||
public bool cloned;
|
|
||||||
[ObservableProperty]
|
|
||||||
public bool enable_On_All_Pages;
|
|
||||||
[ObservableProperty]
|
|
||||||
public bool show_On_This_Page;
|
|
||||||
[ObservableProperty]
|
|
||||||
public bool all;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ConnectStateToBtnTextConverter : IValueConverter
|
public class ConnectStateToBtnTextConverter : IValueConverter
|
||||||
{
|
{
|
||||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
|
|
@ -36,8 +36,6 @@ namespace CtrEditor
|
||||||
private string _imagen;
|
private string _imagen;
|
||||||
private int _id;
|
private int _id;
|
||||||
|
|
||||||
public ObjetosSimulablesFilterTypes osListFilter;
|
|
||||||
|
|
||||||
public List<string> RecentDirectories { get; set; } = new List<string>();
|
public List<string> RecentDirectories { get; set; } = new List<string>();
|
||||||
|
|
||||||
public List<ColumnLanguageMapping> ColumnLanguages { get; set; } = new List<ColumnLanguageMapping>();
|
public List<ColumnLanguageMapping> ColumnLanguages { get; set; } = new List<ColumnLanguageMapping>();
|
||||||
|
|
Loading…
Reference in New Issue