Глобальное обновление #1
@@ -25,8 +25,8 @@ internal sealed class ImportApplication : Application
|
|||||||
Settings = settings;
|
Settings = settings;
|
||||||
Processors = processors;
|
Processors = processors;
|
||||||
|
|
||||||
//CurrentStage = ApplicationStage.InitialSettings;
|
CurrentStage = ApplicationStage.InitialSettings;
|
||||||
CurrentStage = ApplicationStage.Viewer;
|
//CurrentStage = ApplicationStage.Viewer;
|
||||||
}
|
}
|
||||||
|
|
||||||
#region "Поля"
|
#region "Поля"
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:fa="http://schemas.awesome.incremented/wpf/xaml/fontawesome.sharp"
|
xmlns:fa="http://schemas.awesome.incremented/wpf/xaml/fontawesome.sharp"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:struct="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.EntityViewStructure"
|
||||||
xmlns:viewmodel="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.ViewModel"
|
xmlns:viewmodel="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.ViewModel"
|
||||||
x:Name="_this"
|
x:Name="_this"
|
||||||
d:DataContext="{d:DesignInstance Type=viewmodel:ViewViewModel}"
|
d:DataContext="{d:DesignInstance Type=viewmodel:ViewViewModel}"
|
||||||
@@ -17,15 +18,15 @@
|
|||||||
<UserControl.Resources>
|
<UserControl.Resources>
|
||||||
<FontFamily x:Key="FontAwesome">/FontAwesome.Sharp;component/fonts/#Font Awesome 6 Free Solid</FontFamily>
|
<FontFamily x:Key="FontAwesome">/FontAwesome.Sharp;component/fonts/#Font Awesome 6 Free Solid</FontFamily>
|
||||||
|
|
||||||
|
<struct:ColorAdapterConverter x:Key="ColorAdapterConverter" />
|
||||||
|
|
||||||
<Style x:Key="ButtonStyle" TargetType="Button">
|
<Style x:Key="ButtonStyle" TargetType="Button">
|
||||||
<Setter Property="FontSize" Value="{Binding ButtonSize, ElementName=_this}" />
|
<Setter Property="FontSize" Value="{Binding ButtonSize, ElementName=_this}" />
|
||||||
<Setter Property="VerticalAlignment" Value="Center" />
|
<Setter Property="VerticalAlignment" Value="Center" />
|
||||||
<Setter Property="HorizontalAlignment" Value="Center" />
|
<Setter Property="HorizontalAlignment" Value="Center" />
|
||||||
<Setter Property="Margin" Value="0" />
|
|
||||||
<Setter Property="Padding" Value="0" />
|
|
||||||
<Setter Property="Width" Value="{Binding ButtonSize, ElementName=_this}" />
|
<Setter Property="Width" Value="{Binding ButtonSize, ElementName=_this}" />
|
||||||
<Setter Property="Height" Value="{Binding ButtonSize, ElementName=_this}" />
|
<Setter Property="Height" Value="{Binding ButtonSize, ElementName=_this}" />
|
||||||
<Setter Property="BorderThickness" Value="1" />
|
<Setter Property="BorderThickness" Value="2,2,1,1" />
|
||||||
|
|
||||||
<Setter Property="Background">
|
<Setter Property="Background">
|
||||||
<Setter.Value>
|
<Setter.Value>
|
||||||
@@ -41,7 +42,17 @@
|
|||||||
<Setter Property="Foreground" Value="Black" />
|
<Setter Property="Foreground" Value="Black" />
|
||||||
<Style.Triggers>
|
<Style.Triggers>
|
||||||
<Trigger Property="IsMouseOver" Value="True">
|
<Trigger Property="IsMouseOver" Value="True">
|
||||||
<Setter Property="Foreground" Value="DarkGray" />
|
<Setter Property="Foreground" Value="DarkSlateGray" />
|
||||||
|
<Setter Property="Background">
|
||||||
|
<Setter.Value>
|
||||||
|
<SolidColorBrush Color="Transparent" />
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
|
<Setter Property="BorderBrush">
|
||||||
|
<Setter.Value>
|
||||||
|
<SolidColorBrush Color="Transparent" />
|
||||||
|
</Setter.Value>
|
||||||
|
</Setter>
|
||||||
</Trigger>
|
</Trigger>
|
||||||
</Style.Triggers>
|
</Style.Triggers>
|
||||||
</Style>
|
</Style>
|
||||||
@@ -52,6 +63,14 @@
|
|||||||
TargetType="Button">
|
TargetType="Button">
|
||||||
<Setter Property="FontFamily" Value="{StaticResource FontAwesome}" />
|
<Setter Property="FontFamily" Value="{StaticResource FontAwesome}" />
|
||||||
</Style>
|
</Style>
|
||||||
|
|
||||||
|
<Style x:Key="HoverRow" TargetType="Grid">
|
||||||
|
<Style.Triggers>
|
||||||
|
<Trigger Property="IsMouseOver" Value="True">
|
||||||
|
<Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrush}}" />
|
||||||
|
</Trigger>
|
||||||
|
</Style.Triggers>
|
||||||
|
</Style>
|
||||||
</UserControl.Resources>
|
</UserControl.Resources>
|
||||||
|
|
||||||
<UserControl.BorderBrush>
|
<UserControl.BorderBrush>
|
||||||
@@ -63,7 +82,7 @@
|
|||||||
</UserControl.Background>
|
</UserControl.Background>
|
||||||
|
|
||||||
<ScrollViewer>
|
<ScrollViewer>
|
||||||
<ItemsControl ItemsSource="{Binding Rows}">
|
<ItemsControl AlternationCount="2" ItemsSource="{Binding Rows}">
|
||||||
<ItemsControl.ItemsPanel>
|
<ItemsControl.ItemsPanel>
|
||||||
<ItemsPanelTemplate>
|
<ItemsPanelTemplate>
|
||||||
<StackPanel Grid.IsSharedSizeScope="True" />
|
<StackPanel Grid.IsSharedSizeScope="True" />
|
||||||
@@ -72,7 +91,11 @@
|
|||||||
|
|
||||||
<ItemsControl.ItemTemplate>
|
<ItemsControl.ItemTemplate>
|
||||||
<DataTemplate>
|
<DataTemplate>
|
||||||
<Grid Height="{Binding ItemHeight, ElementName=_this}" Visibility="{Binding ItemVisibility}">
|
<Grid
|
||||||
|
x:Name="FooBar"
|
||||||
|
Height="{Binding ItemHeight, ElementName=_this}"
|
||||||
|
Visibility="{Binding ItemVisibility}">
|
||||||
|
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
<ColumnDefinition SharedSizeGroup="ColumnOne" />
|
<ColumnDefinition SharedSizeGroup="ColumnOne" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
@@ -86,13 +109,15 @@
|
|||||||
Ladder="{Binding Ladder}" />
|
Ladder="{Binding Ladder}" />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
Margin="-22,0,0,0"
|
Margin="-20,0,0,0"
|
||||||
|
Padding="0"
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Command="{Binding CollapseCommand}"
|
Command="{Binding CollapseCommand}"
|
||||||
Content="{Binding ButtonIcon}"
|
|
||||||
Style="{StaticResource FaButtonStyle}"
|
Style="{StaticResource FaButtonStyle}"
|
||||||
Visibility="{Binding ButtonVisibility}" />
|
Visibility="{Binding ButtonVisibility}">
|
||||||
|
<TextBlock Margin="-3,-3,0,0" Text="{Binding ButtonIcon}" />
|
||||||
|
</Button>
|
||||||
|
|
||||||
<TextBlock
|
<TextBlock
|
||||||
Margin="2,0,10,0"
|
Margin="2,0,10,0"
|
||||||
@@ -108,14 +133,35 @@
|
|||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
FontSize="{Binding TypeFontSize, ElementName=_this}"
|
FontSize="{Binding TypeFontSize, ElementName=_this}"
|
||||||
FontStyle="Italic"
|
FontStyle="Italic"
|
||||||
Text="{Binding Type}" />
|
Text="{Binding Type}">
|
||||||
|
<TextBlock.Foreground>
|
||||||
|
<MultiBinding Converter="{StaticResource ColorAdapterConverter}">
|
||||||
|
<Binding Path="AccentColor" />
|
||||||
|
</MultiBinding>
|
||||||
|
</TextBlock.Foreground>
|
||||||
|
</TextBlock>
|
||||||
<TextBlock
|
<TextBlock
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Center"
|
VerticalAlignment="Center"
|
||||||
Text="{Binding Value}" />
|
Text="{Binding Value}"
|
||||||
|
TextTrimming="CharacterEllipsis">
|
||||||
|
<TextBlock.Foreground>
|
||||||
|
<MultiBinding Converter="{StaticResource ColorAdapterConverter}">
|
||||||
|
<Binding Path="AccentColor" />
|
||||||
|
</MultiBinding>
|
||||||
|
</TextBlock.Foreground>
|
||||||
|
</TextBlock>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
|
<DataTemplate.Triggers>
|
||||||
|
<Trigger Property="ItemsControl.AlternationIndex" Value="0">
|
||||||
|
<Setter TargetName="FooBar" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrush}}" />
|
||||||
|
</Trigger>
|
||||||
|
<Trigger Property="ItemsControl.AlternationIndex" Value="1">
|
||||||
|
<Setter TargetName="FooBar" Property="Background" Value="{DynamicResource {x:Static SystemColors.ControlBrush}}" />
|
||||||
|
</Trigger>
|
||||||
|
</DataTemplate.Triggers>
|
||||||
</DataTemplate>
|
</DataTemplate>
|
||||||
</ItemsControl.ItemTemplate>
|
</ItemsControl.ItemTemplate>
|
||||||
</ItemsControl>
|
</ItemsControl>
|
||||||
|
|||||||
@@ -5,16 +5,18 @@
|
|||||||
xmlns:component="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.Component"
|
xmlns:component="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.Component"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:viewmodel="clr-namespace:Pf2eDataScrapper.WPF.EntityViewer.ViewModel"
|
||||||
Title="EntityForm"
|
Title="EntityForm"
|
||||||
Width="1400"
|
Width="1400"
|
||||||
Height="800"
|
Height="800"
|
||||||
|
d:DataContext="{d:DesignInstance Type=viewmodel:EntityFormViewModel}"
|
||||||
x:ClassModifier="internal"
|
x:ClassModifier="internal"
|
||||||
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
|
Background="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"
|
||||||
Loaded="Window_Loaded"
|
Loaded="Window_Loaded"
|
||||||
mc:Ignorable="d">
|
mc:Ignorable="d">
|
||||||
<Grid ClipToBounds="True">
|
<Grid ClipToBounds="True">
|
||||||
<Grid.RowDefinitions>
|
<Grid.RowDefinitions>
|
||||||
<RowDefinition Height="20" />
|
<RowDefinition Height="25" />
|
||||||
<RowDefinition Height="150" />
|
<RowDefinition Height="150" />
|
||||||
<RowDefinition Height="Auto" />
|
<RowDefinition Height="Auto" />
|
||||||
<RowDefinition Height="*" />
|
<RowDefinition Height="*" />
|
||||||
@@ -47,6 +49,11 @@
|
|||||||
Cursor="SizeNS"
|
Cursor="SizeNS"
|
||||||
ResizeDirection="Rows" />
|
ResizeDirection="Rows" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
Margin="3,4,0,0"
|
||||||
|
Click="Button_Click"
|
||||||
|
Content="<<< Вернуться в начало" />
|
||||||
|
|
||||||
<ListBox
|
<ListBox
|
||||||
x:Name="EntityTypeListBox"
|
x:Name="EntityTypeListBox"
|
||||||
Grid.Row="1"
|
Grid.Row="1"
|
||||||
@@ -75,7 +82,7 @@
|
|||||||
Grid.RowSpan="4"
|
Grid.RowSpan="4"
|
||||||
Grid.Column="4"
|
Grid.Column="4"
|
||||||
IsReadOnly="True"
|
IsReadOnly="True"
|
||||||
Text="{Binding TestText, Mode=OneWay}"
|
Text="{Binding SelectedEntityDescription, Mode=OneWay}"
|
||||||
TextWrapping="Wrap" />
|
TextWrapping="Wrap" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -12,11 +12,7 @@ internal partial class EntityForm : Window
|
|||||||
public Pf2eDbContext Context { get; }
|
public Pf2eDbContext Context { get; }
|
||||||
public EntityFormViewModel ViewModel { get; }
|
public EntityFormViewModel ViewModel { get; }
|
||||||
|
|
||||||
public EntityForm(
|
public EntityForm(Pf2eDbContext context, EntityFormViewModel viewModel)
|
||||||
Pf2eDbContext context,
|
|
||||||
EntityFormViewModel viewModel,
|
|
||||||
ViewViewModel entityViewViewModel
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
Context = context;
|
Context = context;
|
||||||
ViewModel = viewModel;
|
ViewModel = viewModel;
|
||||||
@@ -31,4 +27,9 @@ internal partial class EntityForm : Window
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void Window_Loaded(object sender, RoutedEventArgs e) { }
|
private void Window_Loaded(object sender, RoutedEventArgs e) { }
|
||||||
|
|
||||||
|
private void Button_Click(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
(Application.Current as ImportApplication)!.CurrentStage = ApplicationStage.InitialSettings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,12 +103,7 @@ internal class StructureBuilder
|
|||||||
return Create(name, value!, depth);
|
return Create(name, value!, depth);
|
||||||
}
|
}
|
||||||
|
|
||||||
StructureFieldReference reference = new StructureFieldReference(
|
StructureFieldReference reference = new(this, name, null, depth);
|
||||||
this,
|
|
||||||
name,
|
|
||||||
null,
|
|
||||||
depth
|
|
||||||
);
|
|
||||||
processed.AddReference(reference);
|
processed.AddReference(reference);
|
||||||
return reference;
|
return reference;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ namespace Pf2eDataScrapper.WPF.EntityViewer.EntityViewStructure;
|
|||||||
/// <param name="builder">Класс построения структуры данных.</param>
|
/// <param name="builder">Класс построения структуры данных.</param>
|
||||||
/// <param name="name">Название поля.</param>
|
/// <param name="name">Название поля.</param>
|
||||||
/// <param name="depth">Глубина поля.</param>
|
/// <param name="depth">Глубина поля.</param>
|
||||||
internal abstract class StructureField(StructureBuilder builder, string name, int depth) : INotifyPropertyChanged
|
internal abstract class StructureField(StructureBuilder builder, string name, int depth)
|
||||||
|
: INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Название поля.
|
/// Название поля.
|
||||||
@@ -216,3 +217,32 @@ internal class StructureFieldReference(
|
|||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override string GetValueString() => "<Reference>";
|
public override string GetValueString() => "<Reference>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Поле структуры пропускаемого объекта.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="builder">Класс построения структуры данных.</param>
|
||||||
|
/// <param name="name">Название поля.</param>
|
||||||
|
/// <param name="reference">Ссылка на объект.</param>
|
||||||
|
/// <param name="depth">Глубина поля.</param>
|
||||||
|
internal class StructureFieldIgnored(
|
||||||
|
StructureBuilder builder,
|
||||||
|
string name,
|
||||||
|
StructureFieldComplex? reference,
|
||||||
|
int depth
|
||||||
|
) : StructureField(builder, name, depth)
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Ссылка на объект.
|
||||||
|
/// </summary>
|
||||||
|
public StructureFieldComplex? Reference = reference;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override StructureFieldType FieldType => StructureFieldType.Reference;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override string GetTypeString() => Reference?.GetTypeString() ?? "???";
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override string GetValueString() => "<Ignored>";
|
||||||
|
}
|
||||||
|
|||||||
@@ -41,6 +41,19 @@ internal class StructureFieldComplex : StructureField
|
|||||||
}
|
}
|
||||||
private bool _collapsed;
|
private bool _collapsed;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Флаг, указывающий, что у этот элемент можно свернуть.
|
||||||
|
/// </summary>
|
||||||
|
public bool Collapsable
|
||||||
|
{
|
||||||
|
get => Fields.Count > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Значение поля идентификатора элемента.
|
||||||
|
/// </summary>
|
||||||
|
public string? IdValue { get; private set; }
|
||||||
|
|
||||||
/// <inheritdoc/>
|
/// <inheritdoc/>
|
||||||
public override bool Visible
|
public override bool Visible
|
||||||
{
|
{
|
||||||
@@ -118,14 +131,20 @@ internal class StructureFieldComplex : StructureField
|
|||||||
Type type = value.GetType();
|
Type type = value.GetType();
|
||||||
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
||||||
|
|
||||||
SetFieldsFromRecords(
|
var records = properties
|
||||||
properties
|
.Where(property => property.GetAttribute<Newtonsoft.Json.JsonIgnoreAttribute>() is null)
|
||||||
.Where(property =>
|
.Select(property => new FieldRecord(property.Name, property.GetValue(value, null)))
|
||||||
property.GetAttribute<Newtonsoft.Json.JsonIgnoreAttribute>() is null
|
.ToList();
|
||||||
)
|
|
||||||
.Select(property => new FieldRecord(property.Name, property.GetValue(value, null)))
|
var idRecord = records.FirstOrDefault(record => record.Name == "Id");
|
||||||
.ToList()
|
|
||||||
);
|
if (idRecord is not null && idRecord.Value is not null)
|
||||||
|
{
|
||||||
|
records.Remove(idRecord);
|
||||||
|
IdValue = idRecord.Value.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
SetFieldsFromRecords(records);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -203,6 +222,12 @@ internal class StructureFieldComplex : StructureField
|
|||||||
{
|
{
|
||||||
return Fields.Count.ToString() + (Fields.Count == 1 ? " item" : " items");
|
return Fields.Count.ToString() + (Fields.Count == 1 ? " item" : " items");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IdValue is not null)
|
||||||
|
{
|
||||||
|
return $"#{IdValue}";
|
||||||
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
using System.ComponentModel;
|
||||||
|
using System.Drawing;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
@@ -9,6 +10,9 @@ using System.Windows.Data;
|
|||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using FontAwesome.Sharp;
|
using FontAwesome.Sharp;
|
||||||
|
using static System.Runtime.InteropServices.JavaScript.JSType;
|
||||||
|
using static LinqToDB.Sql;
|
||||||
|
using Color = System.Windows.Media.Color;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.WPF.EntityViewer.EntityViewStructure;
|
namespace Pf2eDataScrapper.WPF.EntityViewer.EntityViewStructure;
|
||||||
|
|
||||||
@@ -27,7 +31,8 @@ internal class StructureRow : INotifyPropertyChanged
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Флаг наличия кнопки.
|
/// Флаг наличия кнопки.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool HasButton => Field.FieldType == StructureFieldType.Complex;
|
public bool HasButton =>
|
||||||
|
Field.FieldType == StructureFieldType.Complex && ((StructureFieldComplex)Field).Collapsable;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Флаг, указывающий, отображается ли строка.
|
/// Флаг, указывающий, отображается ли строка.
|
||||||
@@ -47,7 +52,10 @@ internal class StructureRow : INotifyPropertyChanged
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Иконка кнопки.
|
/// Иконка кнопки.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ButtonIcon => HasButton && !((StructureFieldComplex)Field).Collapsed ? IconChar.PlusSquare.ToChar() : IconChar.MinusSquare.ToChar();
|
public string ButtonIcon =>
|
||||||
|
HasButton && !((StructureFieldComplex)Field).Collapsed
|
||||||
|
? IconChar.PlusSquare.ToChar()
|
||||||
|
: IconChar.MinusSquare.ToChar();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Глубина отображения поля.
|
/// Глубина отображения поля.
|
||||||
@@ -78,7 +86,26 @@ internal class StructureRow : INotifyPropertyChanged
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Строковое представление значения поля.
|
/// Строковое представление значения поля.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string Value => Field.GetValueString();
|
public string Value => Field.GetValueString().Replace("\r", "").Replace("\n", "");
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Цвет значения
|
||||||
|
/// </summary>
|
||||||
|
public Color? AccentColor =>
|
||||||
|
Field switch
|
||||||
|
{
|
||||||
|
StructureFieldPrimitive primitive => System.Type.GetTypeCode(primitive.Type) switch
|
||||||
|
{
|
||||||
|
TypeCode.Boolean => Colors.DarkGoldenrod,
|
||||||
|
TypeCode.Int32 => Colors.Blue,
|
||||||
|
TypeCode.Double => Colors.Aqua,
|
||||||
|
TypeCode.String => Colors.Green,
|
||||||
|
_ => null,
|
||||||
|
},
|
||||||
|
StructureFieldEnum => Colors.Red,
|
||||||
|
StructureFieldNull => Colors.Transparent,
|
||||||
|
_ => null,
|
||||||
|
};
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Команда переключения.
|
/// Команда переключения.
|
||||||
@@ -147,3 +174,59 @@ internal class CollapseCommand(StructureRow structureRow) : ICommand
|
|||||||
field.Collapsed = !field.Collapsed;
|
field.Collapsed = !field.Collapsed;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ColorAdapterConverter : IMultiValueConverter
|
||||||
|
{
|
||||||
|
private byte Mix(byte a, byte b, double rate) =>
|
||||||
|
System.Convert.ToByte(Math.Round(a * rate + b * (1 - rate)));
|
||||||
|
|
||||||
|
public object? Convert(object[] value, Type targetType, object parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
Color textColor = System.Windows.SystemColors.WindowTextColor;
|
||||||
|
double a = textColor.A;
|
||||||
|
double r = textColor.R;
|
||||||
|
double g = textColor.G;
|
||||||
|
double b = textColor.B;
|
||||||
|
int n = 1 + value.Length;
|
||||||
|
|
||||||
|
foreach (var item in value)
|
||||||
|
{
|
||||||
|
if (item == null || item is not Color)
|
||||||
|
{
|
||||||
|
n--;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color color = (Color)item;
|
||||||
|
|
||||||
|
a += color.A;
|
||||||
|
r += color.R;
|
||||||
|
g += color.G;
|
||||||
|
b += color.B;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color resultColor = Color.FromArgb(
|
||||||
|
System.Convert.ToByte(Math.Round(a / n)),
|
||||||
|
System.Convert.ToByte(Math.Round(r / n)),
|
||||||
|
System.Convert.ToByte(Math.Round(g / n)),
|
||||||
|
System.Convert.ToByte(Math.Round(b / n))
|
||||||
|
);
|
||||||
|
|
||||||
|
var @switch = new Dictionary<Type, Func<object>>
|
||||||
|
{
|
||||||
|
{ typeof(System.Windows.Media.Brush), () => new SolidColorBrush(resultColor) },
|
||||||
|
};
|
||||||
|
|
||||||
|
return @switch.TryGetValue(targetType, out var action) ? action() : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public object[] ConvertBack(
|
||||||
|
object value,
|
||||||
|
Type[] targetType,
|
||||||
|
object parameter,
|
||||||
|
CultureInfo culture
|
||||||
|
)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ public class SelectedEntityStore
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
_selectedEntity = value;
|
_selectedEntity = value;
|
||||||
SelectedEntityTypeChanged?.Invoke(SelectedEntity);
|
SelectedEntityChanged?.Invoke(SelectedEntity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public event Action<Entity?>? SelectedEntityTypeChanged;
|
public event Action<Entity?>? SelectedEntityChanged;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Pf2eDataScrapper.WPF.EntityViewer.Stores;
|
using Pf2eDataScrapper.WPF.EntityViewer.Stores;
|
||||||
using Pf2eModel;
|
using Pf2eModel;
|
||||||
|
using Pf2eModel.Model.Base;
|
||||||
using Pf2eModel.Model.Enum;
|
using Pf2eModel.Model.Enum;
|
||||||
|
|
||||||
namespace Pf2eDataScrapper.WPF.EntityViewer.ViewModel;
|
namespace Pf2eDataScrapper.WPF.EntityViewer.ViewModel;
|
||||||
@@ -16,13 +17,15 @@ internal class EntityFormViewModel : ViewModelBase
|
|||||||
public EntityListViewModel DbEntityListViewModel { get; }
|
public EntityListViewModel DbEntityListViewModel { get; }
|
||||||
public ViewViewModel ViewViewModel { get; }
|
public ViewViewModel ViewViewModel { get; }
|
||||||
public SelectedEntityTypeStore SelectedEntityTypeStore { get; }
|
public SelectedEntityTypeStore SelectedEntityTypeStore { get; }
|
||||||
|
public SelectedEntityStore SelectedEntityStore { get; }
|
||||||
|
|
||||||
public EntityFormViewModel(
|
public EntityFormViewModel(
|
||||||
IServiceProvider serviceProvider,
|
IServiceProvider serviceProvider,
|
||||||
Pf2eDbContext context,
|
Pf2eDbContext context,
|
||||||
EntityListViewModel entityListViewModel,
|
EntityListViewModel entityListViewModel,
|
||||||
ViewViewModel viewViewModel,
|
ViewViewModel viewViewModel,
|
||||||
SelectedEntityTypeStore selectedEntityTypeStore
|
SelectedEntityTypeStore selectedEntityTypeStore,
|
||||||
|
SelectedEntityStore selectedEntityStore
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
ServiceProvider = serviceProvider;
|
ServiceProvider = serviceProvider;
|
||||||
@@ -30,7 +33,11 @@ internal class EntityFormViewModel : ViewModelBase
|
|||||||
DbEntityListViewModel = entityListViewModel;
|
DbEntityListViewModel = entityListViewModel;
|
||||||
ViewViewModel = viewViewModel;
|
ViewViewModel = viewViewModel;
|
||||||
SelectedEntityTypeStore = selectedEntityTypeStore;
|
SelectedEntityTypeStore = selectedEntityTypeStore;
|
||||||
|
SelectedEntityStore = selectedEntityStore;
|
||||||
|
|
||||||
Update();
|
Update();
|
||||||
|
|
||||||
|
SelectedEntityStore.SelectedEntityChanged += SelectedEntityStore_SelectedEntityChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update()
|
public void Update()
|
||||||
@@ -64,5 +71,19 @@ internal class EntityFormViewModel : ViewModelBase
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region "Текущий элемент"
|
||||||
|
|
||||||
|
public string SelectedEntityDescription
|
||||||
|
{
|
||||||
|
get => SelectedEntityStore.SelectedEntity?.Description ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectedEntityStore_SelectedEntityChanged(Entity? obj)
|
||||||
|
{
|
||||||
|
OnPropertyChanged(nameof(SelectedEntityDescription));
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public string TestText => SelectedEntityType?.ToString() ?? "null";
|
public string TestText => SelectedEntityType?.ToString() ?? "null";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,6 +87,7 @@ internal class EntityListViewModel : ViewModelBase
|
|||||||
set
|
set
|
||||||
{
|
{
|
||||||
_entities = [.. value];
|
_entities = [.. value];
|
||||||
|
SelectedEntity = Entities.FirstOrDefault();
|
||||||
OnPropertyChanged();
|
OnPropertyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -144,55 +145,24 @@ internal class EntityListViewModel : ViewModelBase
|
|||||||
|
|
||||||
#region "Запросы"
|
#region "Запросы"
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Поток, в котором будет выполняться запрос к базе данных.
|
|
||||||
/// </summary>
|
|
||||||
private Thread? _queryThread;
|
|
||||||
|
|
||||||
public void Reload()
|
|
||||||
{
|
|
||||||
Abort();
|
|
||||||
_queryThread = new(PerformQuery);
|
|
||||||
_queryThread.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Прерывает выполнение потока, если он ещё не завершён.
|
|
||||||
/// </summary>
|
|
||||||
public void Abort()
|
|
||||||
{
|
|
||||||
_queryThread?.Interrupt();
|
|
||||||
_queryThread = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Выполняет запрос к базе данных и обрабатывает результаты.
|
/// Выполняет запрос к базе данных и обрабатывает результаты.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void PerformQuery()
|
public void Reload()
|
||||||
{
|
{
|
||||||
try
|
Pf2eDbContext dbContext = new();
|
||||||
{
|
|
||||||
Pf2eDbContext dbContext = new();
|
|
||||||
|
|
||||||
IQueryable<Entity> query =
|
IQueryable<Entity> query =
|
||||||
Search == ""
|
Search == ""
|
||||||
? dbContext.Entities.Where(e => e.Type == SelectedEntityType)
|
? dbContext.Entities.Where(e => e.Type == SelectedEntityType)
|
||||||
:
|
:
|
||||||
// ReSharper disable once EntityFramework.UnsupportedServerSideFunctionCall
|
// ReSharper disable once EntityFramework.UnsupportedServerSideFunctionCall
|
||||||
dbContext.Entities.Where(e =>
|
dbContext.Entities.Where(e =>
|
||||||
e.Type == SelectedEntityType && Pf2eDbContext.LocaleSearch(e.Name, Search)
|
e.Type == SelectedEntityType && Pf2eDbContext.LocaleSearch(e.Name, Search)
|
||||||
);
|
);
|
||||||
|
|
||||||
EntitiesCount = query.Count();
|
EntitiesCount = query.Count();
|
||||||
Entities =
|
Entities = [.. query.OrderBy(e => e.Id).Skip((Page - 1) * PerPage).Take(PerPage).ToList()];
|
||||||
[
|
|
||||||
.. query.OrderBy(e => e.Id).Skip((Page - 1) * PerPage).Take(PerPage).ToList(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
catch (ThreadInterruptedException)
|
|
||||||
{
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ internal class ViewViewModel : ViewModelBase
|
|||||||
{
|
{
|
||||||
_rows = value;
|
_rows = value;
|
||||||
OnPropertyChanged();
|
OnPropertyChanged();
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private ObservableCollection<StructureRow> _rows = [];
|
private ObservableCollection<StructureRow> _rows = [];
|
||||||
@@ -45,14 +44,12 @@ internal class ViewViewModel : ViewModelBase
|
|||||||
Context = context;
|
Context = context;
|
||||||
SelectedEntityStore = selectedEntityStore;
|
SelectedEntityStore = selectedEntityStore;
|
||||||
|
|
||||||
SelectedEntityStore.SelectedEntityTypeChanged +=
|
SelectedEntityStore.SelectedEntityChanged += SelectedEntityStore_SelectedEntityTypeChanged;
|
||||||
SelectedEntityStore_SelectedEntityTypeChanged;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~ViewViewModel()
|
~ViewViewModel()
|
||||||
{
|
{
|
||||||
SelectedEntityStore.SelectedEntityTypeChanged -=
|
SelectedEntityStore.SelectedEntityChanged -= SelectedEntityStore_SelectedEntityTypeChanged;
|
||||||
SelectedEntityStore_SelectedEntityTypeChanged;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SelectedEntityStore_SelectedEntityTypeChanged(Pf2eModel.Model.Base.Entity? entity)
|
private void SelectedEntityStore_SelectedEntityTypeChanged(Pf2eModel.Model.Base.Entity? entity)
|
||||||
|
|||||||
Reference in New Issue
Block a user