Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PriorityGrid: flattening, priority and hierarchy sorting, nullable types, search bar hiding and fixes #892

Open
wants to merge 39 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1be50e5
Introduces flattening of types without a known type editor.
SamXion May 10, 2021
6283977
removed unnecessary dependency
SamXion May 10, 2021
07da337
Merge branch 'HandyOrg:master' into Flattening-PropertyGrid
SamirKharchi May 10, 2021
b30c1c6
Hides the search bar element.
SamXion May 10, 2021
9d57852
Introduces a dependency property ShowSearchBar in order to hide the s…
SamXion May 10, 2021
3d1d1c8
Merge branch 'Hide-SearchBar' of https://github.com/SamirKharchi/Hand…
SamXion May 10, 2021
2fa58eb
Merge pull request #1 from SamirKharchi/Flattening-PropertyGrid
SamirKharchi May 10, 2021
4ce3526
Merge branch 'master' into Hide-SearchBar
SamirKharchi May 10, 2021
37e4326
Merge pull request #2 from SamirKharchi/Hide-SearchBar
SamirKharchi May 10, 2021
003af5e
This introduces hierarchy level sorting (assumes flattening properties).
SamXion May 10, 2021
858a410
Merge pull request #3 from SamirKharchi/Sort-By-Hierarchy
SamirKharchi May 10, 2021
c474be7
Fixes that the root component is assigned to the PropertyItem and the…
SamXion May 11, 2021
b028dbf
Merge branch 'master' into Flattening-PropertyGrid
SamirKharchi May 11, 2021
c4acbc2
Merge pull request #4 from SamirKharchi/Flattening-PropertyGrid
SamirKharchi May 11, 2021
b628b78
Adds support for nullable types
SamXion May 11, 2021
559cb81
Merge pull request #5 from SamirKharchi/Nullable-Types-Support
SamirKharchi May 11, 2021
b798e43
Fixes that custom editors are not correctly created.
SamXion May 11, 2021
14a0c8c
Merge pull request #6 from SamirKharchi/Fix-CustomEditor-Support
SamirKharchi May 11, 2021
c5b9c33
Enum type editor now uses and favors existing enum entry descriptions.
SamXion May 11, 2021
809386a
Merge pull request #7 from SamirKharchi/Improve-Enum-Display-By-Using…
SamirKharchi May 11, 2021
5c1f1db
See https://github.com/HandyOrg/HandyControl/pull/818
SamXion May 11, 2021
13a9a9f
Merge pull request #8 from SamirKharchi/Add-KeepCenterOnSizeChanged-a…
SamirKharchi May 11, 2021
5ed5fbf
Fixes a crash scenario when the enum was not set or null
SamXion May 11, 2021
f5811bd
Merge pull request #9 from SamirKharchi/Fix-Enum-Bug
SamirKharchi May 11, 2021
c9bb625
Added support for GroupHeaderTemplate and GroupHeaderMargin
SamXion May 12, 2021
2cefb58
Merge pull request #10 from SamirKharchi/Fix-Enum-Bug
SamirKharchi May 12, 2021
62fb546
Merge branch 'HandyOrg:master' into master
SamirKharchi Jun 3, 2021
9da7d34
Merge remote-tracking branch 'upstream/master'
SamirKharchi Jul 2, 2021
cfcb503
New sorting options and extentability
SamXion Jul 2, 2021
d558fac
Merge pull request #13 from SamirKharchi/FlatteingSortingExtentibility
SamirKharchi Jul 2, 2021
ff10175
revert unnecessary commit
SamirKharchi Jul 2, 2021
8c580cd
Revert wrong sync changes
SamirKharchi Jul 2, 2021
576e8bd
theme update
SamirKharchi Jul 2, 2021
9b5182f
Merge pull request #14 from SamirKharchi/FlatteingSortingExtentibility
SamirKharchi Jul 2, 2021
de587ed
Merge branch 'HandyOrg:master' into master
SamirKharchi Jul 4, 2021
64ccd9f
Merge branch 'HandyOrg:master' into master
SamirKharchi Jul 10, 2021
433347d
Fixes crash when adding items to a carousel that was not initialised …
SamirKharchi Jul 14, 2021
7931714
Merge pull request #15 from SamirKharchi/Fix-crash-when-post-adding-t…
SamirKharchi Jul 14, 2021
06a1fd1
Merge branch 'master' into master
SamirKharchi Nov 5, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added support for GroupHeaderTemplate and GroupHeaderMargin
Also fixes a bug when CraeteDefaultEditor was called (type was not referenced so it didn't update to be the underlying type).
  • Loading branch information
SamXion committed May 12, 2021
commit c9bb62584246b8525e2d026dee54be4c741be408
Original file line number Diff line number Diff line change
@@ -124,6 +124,25 @@ public Flattening FlattenChildProperties
set => SetValue(FlattenChildPropertiesProperty, value);
}

public static readonly DependencyProperty GroupHeaderTemplateProperty = DependencyProperty.Register(
nameof(GroupHeaderTemplate), typeof(DataTemplate), typeof(PropertyGrid), new PropertyMetadata(default(DataTemplate)));

public DataTemplate GroupHeaderTemplate
{
get => (DataTemplate) GetValue(GroupHeaderTemplateProperty);
set => SetValue(GroupHeaderTemplateProperty, value);
}

public static readonly DependencyProperty GroupHeaderMarginProperty = DependencyProperty.Register(
nameof(GroupHeaderMargin), typeof(Thickness), typeof(PropertyGrid),
new FrameworkPropertyMetadata(new Thickness(0, 0, 0, 6), FrameworkPropertyMetadataOptions.AffectsMeasure));

public Thickness GroupHeaderMargin
{
get => (Thickness) GetValue(GroupHeaderMarginProperty);
set => SetValue(GroupHeaderMarginProperty, value);
}

public override void OnApplyTemplate()
{
if (_searchBar != null)
Original file line number Diff line number Diff line change
@@ -12,33 +12,33 @@ public class PropertyResolver
{
private static readonly Dictionary<Type, EditorTypeCode> TypeCodeDic = new Dictionary<Type, EditorTypeCode>
{
[typeof(string)] = EditorTypeCode.PlainText,
[typeof(sbyte)] = EditorTypeCode.SByteNumber,
[typeof(byte)] = EditorTypeCode.ByteNumber,
[typeof(short)] = EditorTypeCode.Int16Number,
[typeof(ushort)] = EditorTypeCode.UInt16Number,
[typeof(int)] = EditorTypeCode.Int32Number,
[typeof(uint)] = EditorTypeCode.UInt32Number,
[typeof(long)] = EditorTypeCode.Int64Number,
[typeof(ulong)] = EditorTypeCode.UInt64Number,
[typeof(float)] = EditorTypeCode.SingleNumber,
[typeof(double)] = EditorTypeCode.DoubleNumber,
[typeof(bool)] = EditorTypeCode.Switch,
[typeof(DateTime)] = EditorTypeCode.DateTime,
[typeof(string)] = EditorTypeCode.PlainText,
[typeof(sbyte)] = EditorTypeCode.SByteNumber,
[typeof(byte)] = EditorTypeCode.ByteNumber,
[typeof(short)] = EditorTypeCode.Int16Number,
[typeof(ushort)] = EditorTypeCode.UInt16Number,
[typeof(int)] = EditorTypeCode.Int32Number,
[typeof(uint)] = EditorTypeCode.UInt32Number,
[typeof(long)] = EditorTypeCode.Int64Number,
[typeof(ulong)] = EditorTypeCode.UInt64Number,
[typeof(float)] = EditorTypeCode.SingleNumber,
[typeof(double)] = EditorTypeCode.DoubleNumber,
[typeof(bool)] = EditorTypeCode.Switch,
[typeof(DateTime)] = EditorTypeCode.DateTime,
[typeof(HorizontalAlignment)] = EditorTypeCode.HorizontalAlignment,
[typeof(VerticalAlignment)] = EditorTypeCode.VerticalAlignment,
[typeof(ImageSource)] = EditorTypeCode.ImageSource
[typeof(VerticalAlignment)] = EditorTypeCode.VerticalAlignment,
[typeof(ImageSource)] = EditorTypeCode.ImageSource
};

public string ResolveCategory(PropertyDescriptor propertyDescriptor)
{
var categoryAttribute = propertyDescriptor.Attributes.OfType<CategoryAttribute>().FirstOrDefault();

return categoryAttribute == null ?
Lang.Miscellaneous :
string.IsNullOrEmpty(categoryAttribute.Category) ?
Lang.Miscellaneous :
categoryAttribute.Category;
if (categoryAttribute == null || string.IsNullOrEmpty(categoryAttribute.Category))
{
return Lang.Miscellaneous;
}
return categoryAttribute.Category;
}

public int? ResolveHierarchyLevel(PropertyDescriptor propertyDescriptor)
@@ -84,41 +84,41 @@ public PropertyEditorBase ResolveEditor(PropertyDescriptor propertyDescriptor)

public virtual PropertyEditorBase CreateDefaultEditor(Type type)
{
var underlyingType = Nullable.GetUnderlyingType(type);
if (underlyingType is not null)
if (!PropertyResolver.IsKnownEditorType(ref type))
{
type = underlyingType;
return new ReadOnlyTextPropertyEditor();
}
if (type.IsSubclassOf(typeof(Enum)))
{
return (PropertyEditorBase) new EnumPropertyEditor();
}

return TypeCodeDic.TryGetValue(type, out var editorType)
? editorType switch
{
EditorTypeCode.PlainText => new PlainTextPropertyEditor(),
EditorTypeCode.SByteNumber => new NumberPropertyEditor(sbyte.MinValue, sbyte.MaxValue),
EditorTypeCode.ByteNumber => new NumberPropertyEditor(byte.MinValue, byte.MaxValue),
EditorTypeCode.Int16Number => new NumberPropertyEditor(short.MinValue, short.MaxValue),
EditorTypeCode.UInt16Number => new NumberPropertyEditor(ushort.MinValue, ushort.MaxValue),
EditorTypeCode.Int32Number => new NumberPropertyEditor(int.MinValue, int.MaxValue),
EditorTypeCode.UInt32Number => new NumberPropertyEditor(uint.MinValue, uint.MaxValue),
EditorTypeCode.Int64Number => new NumberPropertyEditor(long.MinValue, long.MaxValue),
EditorTypeCode.UInt64Number => new NumberPropertyEditor(ulong.MinValue, ulong.MaxValue),
EditorTypeCode.SingleNumber => new NumberPropertyEditor(float.MinValue, float.MaxValue),
EditorTypeCode.DoubleNumber => new NumberPropertyEditor(double.MinValue, double.MaxValue),
EditorTypeCode.Switch => new SwitchPropertyEditor(),
EditorTypeCode.DateTime => new DateTimePropertyEditor(),
EditorTypeCode.HorizontalAlignment => new HorizontalAlignmentPropertyEditor(),
EditorTypeCode.VerticalAlignment => new VerticalAlignmentPropertyEditor(),
EditorTypeCode.ImageSource => new ImagePropertyEditor(),
_ => new ReadOnlyTextPropertyEditor()
}
: type.IsSubclassOf(typeof(Enum))
? (PropertyEditorBase) new EnumPropertyEditor()
: new ReadOnlyTextPropertyEditor();
return TypeCodeDic[type] switch
{
EditorTypeCode.PlainText => new PlainTextPropertyEditor(),
EditorTypeCode.SByteNumber => new NumberPropertyEditor(sbyte.MinValue, sbyte.MaxValue),
EditorTypeCode.ByteNumber => new NumberPropertyEditor(byte.MinValue, byte.MaxValue),
EditorTypeCode.Int16Number => new NumberPropertyEditor(short.MinValue, short.MaxValue),
EditorTypeCode.UInt16Number => new NumberPropertyEditor(ushort.MinValue, ushort.MaxValue),
EditorTypeCode.Int32Number => new NumberPropertyEditor(int.MinValue, int.MaxValue),
EditorTypeCode.UInt32Number => new NumberPropertyEditor(uint.MinValue, uint.MaxValue),
EditorTypeCode.Int64Number => new NumberPropertyEditor(long.MinValue, long.MaxValue),
EditorTypeCode.UInt64Number => new NumberPropertyEditor(ulong.MinValue, ulong.MaxValue),
EditorTypeCode.SingleNumber => new NumberPropertyEditor(float.MinValue, float.MaxValue),
EditorTypeCode.DoubleNumber => new NumberPropertyEditor(double.MinValue, double.MaxValue),
EditorTypeCode.Switch => new SwitchPropertyEditor(),
EditorTypeCode.DateTime => new DateTimePropertyEditor(),
EditorTypeCode.HorizontalAlignment => new HorizontalAlignmentPropertyEditor(),
EditorTypeCode.VerticalAlignment => new VerticalAlignmentPropertyEditor(),
EditorTypeCode.ImageSource => new ImagePropertyEditor(),
_ => new ReadOnlyTextPropertyEditor()
};
}

public virtual PropertyEditorBase CreateEditor(Type type) => Activator.CreateInstance(type) as PropertyEditorBase ?? new ReadOnlyTextPropertyEditor();
public virtual PropertyEditorBase CreateEditor(Type type) =>
Activator.CreateInstance(type) as PropertyEditorBase ?? new ReadOnlyTextPropertyEditor();

public static bool IsKnownEditorType(Type type)
public static bool IsKnownEditorType(ref Type type)
{
var underlyingType = Nullable.GetUnderlyingType(type);
if (underlyingType is not null)
@@ -129,6 +129,8 @@ public static bool IsKnownEditorType(Type type)
return TypeCodeDic.ContainsKey(type) || type.IsSubclassOf(typeof(Enum));
}

public static bool IsKnownEditorType(Type type) => IsKnownEditorType(ref type);

private enum EditorTypeCode
{
PlainText,
Original file line number Diff line number Diff line change
@@ -117,12 +117,12 @@
</Style>

<Style x:Key="PropertyGroupItemBaseStyle" TargetType="GroupItem">
<Setter Property="Margin" Value="0,0,0,6"/>
<Setter Property="Padding" Value="10,6,6,0"/>
<Setter Property="Margin" Value="{Binding Path=GroupHeaderMargin, RelativeSource={RelativeSource AncestorType={x:Type hc:PropertyGrid}, Mode=FindAncestor}, FallbackValue='0,0,0,6'}" />
<Setter Property="Padding" Value="10,6,6,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<Expander Header="{Binding Name}" IsExpanded="True">
<Expander Header="{Binding Name}" IsExpanded="True" HeaderTemplate="{Binding Path=GroupHeaderTemplate, RelativeSource={RelativeSource AncestorType={x:Type hc:PropertyGrid}, Mode=FindAncestor}}">
<Border BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" CornerRadius="0,0,4,4">
<ItemsPresenter Margin="{TemplateBinding Padding}"/>
</Border>
4 changes: 2 additions & 2 deletions src/Shared/HandyControl_Shared/Themes/Theme.xaml
Original file line number Diff line number Diff line change
@@ -9772,12 +9772,12 @@
</Style.Triggers>
</Style>
<Style x:Key="PropertyGroupItemBaseStyle" TargetType="GroupItem">
<Setter Property="Margin" Value="0,0,0,6" />
<Setter Property="Margin" Value="{Binding Path=GroupHeaderMargin, RelativeSource={RelativeSource AncestorType={x:Type hc:PropertyGrid}, Mode=FindAncestor}, FallbackValue='0,0,0,6'}" />
<Setter Property="Padding" Value="10,6,6,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<Expander Header="{Binding Name}" IsExpanded="True">
<Expander Header="{Binding Name}" IsExpanded="True" HeaderTemplate="{Binding Path=GroupHeaderTemplate, RelativeSource={RelativeSource AncestorType={x:Type hc:PropertyGrid}, Mode=FindAncestor}}">
<Border BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" CornerRadius="0,0,4,4">
<ItemsPresenter Margin="{TemplateBinding Padding}" />
</Border>