-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Pin properties dev tool update #12315
Changes from all commits
f7e2d24
1f2c003
931897b
309a132
05f3cb9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
+1 −1 | Numerge/LoadedPackage.cs | |
+1 −16 | Numerge/NugetPackageMerger.cs | |
+4 −5 | Numerge/Numerge.csproj |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System; | ||
using System.Globalization; | ||
using Avalonia.Data.Converters; | ||
|
||
namespace Avalonia.Diagnostics.Converters | ||
{ | ||
internal class PinnedToBoolConverter : IValueConverter | ||
{ | ||
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
if (value is string status) | ||
{ | ||
return status.Equals("Pinned", StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) | ||
{ | ||
if (value is bool isPinned) | ||
{ | ||
return isPinned ? "Pinned" : "Unpinned"; | ||
} | ||
|
||
return "Unknown"; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,12 @@ internal class AvaloniaPropertyViewModel : PropertyViewModel | |
private string _priority; | ||
private string _group; | ||
private readonly Type _propertyType; | ||
private enum PinnedStatus | ||
{ | ||
Pinned, | ||
Unpinned | ||
} | ||
private PinnedStatus _isPinned; | ||
|
||
#nullable disable | ||
// Remove "nullable disable" after MemberNotNull will work on our CI. | ||
|
@@ -19,6 +25,7 @@ public AvaloniaPropertyViewModel(AvaloniaObject o, AvaloniaProperty property) | |
{ | ||
_target = o; | ||
Property = property; | ||
_isPinned = PinnedStatus.Unpinned; | ||
|
||
Name = property.IsAttached ? | ||
$"[{property.OwnerType.Name}.{property.Name}]" : | ||
|
@@ -33,6 +40,21 @@ public AvaloniaPropertyViewModel(AvaloniaObject o, AvaloniaProperty property) | |
public override string Name { get; } | ||
public override bool? IsAttached => Property.IsAttached; | ||
public override string Priority => _priority; | ||
public override string IsPinned | ||
{ | ||
get => _isPinned.ToString(); | ||
set | ||
{ | ||
try | ||
{ | ||
if (Enum.TryParse(value, out PinnedStatus pinState)) | ||
{ | ||
_isPinned = pinState; | ||
} | ||
} | ||
catch { } | ||
} | ||
Comment on lines
+45
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is bad convention to be changing the data type in the property accessors. Whatever the underlying type is really should stay exposed as the property type. |
||
} | ||
public override Type AssignedType => _assignedType; | ||
|
||
public override object? Value | ||
|
@@ -55,7 +77,6 @@ public override object? Value | |
public override Type PropertyType => _propertyType; | ||
public override bool IsReadonly => Property.IsReadOnly; | ||
|
||
// [MemberNotNull(nameof(_type), nameof(_group), nameof(_priority))] | ||
public override void Update() | ||
{ | ||
if (Property.IsDirect) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,12 @@ internal class ClrPropertyViewModel : PropertyViewModel | |
private Type _assignedType; | ||
private object? _value; | ||
private readonly Type _propertyType; | ||
private enum PinnedStatus | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this enum can go away. Still, you shouldn't have two of the exact same enum defined. |
||
{ | ||
Pinned, | ||
Unpinned | ||
} | ||
private PinnedStatus _isPinned; | ||
|
||
#nullable disable | ||
// Remove "nullable disable" after MemberNotNull will work on our CI. | ||
|
@@ -17,6 +23,7 @@ public ClrPropertyViewModel(object o, PropertyInfo property) | |
{ | ||
_target = o; | ||
Property = property; | ||
_isPinned = PinnedStatus.Unpinned; | ||
|
||
if (property.DeclaringType == null || !property.DeclaringType.IsInterface) | ||
{ | ||
|
@@ -42,6 +49,22 @@ public ClrPropertyViewModel(object o, PropertyInfo property) | |
public override Type PropertyType => _propertyType; | ||
public override bool IsReadonly => !Property.CanWrite; | ||
|
||
//determines if property is pinned to top in dev tools | ||
public override string IsPinned | ||
{ | ||
get => _isPinned.ToString(); | ||
set | ||
{ | ||
try | ||
{ | ||
if (Enum.TryParse(value, out PinnedStatus pinState)) | ||
{ | ||
_isPinned = pinState; | ||
} | ||
} | ||
catch { } | ||
} | ||
} | ||
public override object? Value | ||
{ | ||
get => _value; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ internal abstract class PropertyViewModel : ViewModelBase | |
public abstract string Name { get; } | ||
public abstract string Group { get; } | ||
public abstract Type AssignedType { get; } | ||
public abstract string IsPinned { get; set; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So... three type? Bool in ConvertBack, String here and also the Enum?... should be just one as mentioned before. Am I missing something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, when it was only a bool passing it in as a groupdescription would have the groups titled true and false rather than pinned and unpinned. If there is another way to have the group descriptions renamed I will implement that but, I wasn't able to find anything. Even just hiding the name of the group would be a good option if possible. |
||
public abstract Type? DeclaringType { get; } | ||
public abstract object? Value { get; set; } | ||
public abstract string Priority { get; } | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why define this as an enum? The "Is" name prefix implies it is a bool. If you keep it as a bool you can avoid the converter entirely, correct?