Browse Source

Set IsReadOnly instead, use ConvertToInvariantString, Fix TextBox foreground on selected row

pull/10368/head
pr8x 4 years ago
parent
commit
1fc1c26cb7
  1. 5
      src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml.cs
  2. 32
      src/Avalonia.Diagnostics/Diagnostics/Views/PropertyValueEditorView.cs
  3. 1
      src/Avalonia.Themes.Simple/Controls/TextBox.xaml

5
src/Avalonia.Diagnostics/Diagnostics/Views/MainView.xaml.cs

@ -1,7 +1,6 @@
using Avalonia.Controls; using Avalonia.Controls;
using Avalonia.Diagnostics.ViewModels; using Avalonia.Diagnostics.ViewModels;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml; using Avalonia.Markup.Xaml;
using Avalonia.Threading; using Avalonia.Threading;
@ -18,7 +17,7 @@ namespace Avalonia.Diagnostics.Views
public MainView() public MainView()
{ {
InitializeComponent(); InitializeComponent();
AddHandler(KeyDownEvent, PreviewKeyDown, RoutingStrategies.Tunnel); AddHandler(KeyUpEvent, PreviewKeyUp);
_console = this.GetControl<ConsoleView>("console"); _console = this.GetControl<ConsoleView>("console");
_consoleSplitter = this.GetControl<GridSplitter>("consoleSplitter"); _consoleSplitter = this.GetControl<GridSplitter>("consoleSplitter");
_rootGrid = this.GetControl<Grid>("rootGrid"); _rootGrid = this.GetControl<Grid>("rootGrid");
@ -58,7 +57,7 @@ namespace Avalonia.Diagnostics.Views
AvaloniaXamlLoader.Load(this); AvaloniaXamlLoader.Load(this);
} }
private void PreviewKeyDown(object? sender, KeyEventArgs e) private void PreviewKeyUp(object? sender, KeyEventArgs e)
{ {
if (e.Key == Key.Escape) if (e.Key == Key.Escape)
{ {

32
src/Avalonia.Diagnostics/Diagnostics/Views/PropertyValueEditorView.cs

@ -10,7 +10,6 @@ using Avalonia.Data.Converters;
using Avalonia.Diagnostics.Controls; using Avalonia.Diagnostics.Controls;
using Avalonia.Diagnostics.ViewModels; using Avalonia.Diagnostics.ViewModels;
using Avalonia.Input; using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Layout; using Avalonia.Layout;
using Avalonia.Markup.Xaml.Converters; using Avalonia.Markup.Xaml.Converters;
using Avalonia.Media; using Avalonia.Media;
@ -48,7 +47,7 @@ namespace Avalonia.Diagnostics.Views
private static bool ImplementsInterface<TInterface>(Type type) private static bool ImplementsInterface<TInterface>(Type type)
{ {
var interfaceType = typeof(TInterface); var interfaceType = typeof(TInterface);
return type == interfaceType || type.GetInterface(interfaceType.FullName!) != null; return type == interfaceType || interfaceType.IsAssignableFrom(type);
} }
private Control? UpdateControl() private Control? UpdateControl()
@ -60,7 +59,8 @@ namespace Avalonia.Diagnostics.Views
TControl CreateControl<TControl>(AvaloniaProperty valueProperty, TControl CreateControl<TControl>(AvaloniaProperty valueProperty,
IValueConverter? converter = null, IValueConverter? converter = null,
Action<TControl>? init = null) Action<TControl>? init = null,
AvaloniaProperty? readonlyProperty = null)
where TControl : Control, new() where TControl : Control, new()
{ {
var control = new TControl(); var control = new TControl();
@ -75,7 +75,14 @@ namespace Avalonia.Diagnostics.Views
ConverterParameter = propertyType ConverterParameter = propertyType
}).DisposeWith(_cleanup); }).DisposeWith(_cleanup);
control.IsEnabled = !Property.IsReadonly; if (readonlyProperty != null)
{
control[readonlyProperty] = Property.IsReadonly;
}
else
{
control.IsEnabled = !Property.IsReadonly;
}
return control; return control;
} }
@ -93,7 +100,8 @@ namespace Avalonia.Diagnostics.Views
n.Increment = 1; n.Increment = 1;
n.NumberFormat = new NumberFormatInfo { NumberDecimalDigits = 0 }; n.NumberFormat = new NumberFormatInfo { NumberDecimalDigits = 0 };
n.ParsingNumberStyle = NumberStyles.Integer; n.ParsingNumberStyle = NumberStyles.Integer;
}); },
readonlyProperty: NumericUpDown.IsReadOnlyProperty);
if (propertyType == typeof(Color)) if (propertyType == typeof(Color))
{ {
@ -117,7 +125,8 @@ namespace Avalonia.Diagnostics.Views
Spacing = 2, Spacing = 2,
Children = { el, tbl }, Children = { el, tbl },
Background = Brushes.Transparent, Background = Brushes.Transparent,
Cursor = new Cursor(StandardCursorType.Hand) Cursor = new Cursor(StandardCursorType.Hand),
IsEnabled = !Property.IsReadonly
}; };
var cv = new ColorView(); var cv = new ColorView();
@ -221,12 +230,13 @@ namespace Avalonia.Diagnostics.Views
t => t =>
{ {
t.Watermark = "(null)"; t.Watermark = "(null)";
}); },
readonlyProperty: TextBox.IsReadOnlyProperty);
tb.IsEnabled &= propertyType != typeof(object) && tb.IsReadOnly |= propertyType == typeof(object) ||
StringConversionHelper.CanConvertFromString(propertyType); !StringConversionHelper.CanConvertFromString(propertyType);
if (tb.IsEnabled) if (!tb.IsReadOnly)
{ {
tb.GetObservable(TextBox.TextProperty).Subscribe(t => tb.GetObservable(TextBox.TextProperty).Subscribe(t =>
{ {
@ -311,7 +321,7 @@ namespace Avalonia.Diagnostics.Views
converter.GetType() == typeof(CollectionConverter)) converter.GetType() == typeof(CollectionConverter))
return o.ToString(); return o.ToString();
return converter.ConvertToString(o); return converter.ConvertToInvariantString(o);
} }
public static object? FromString(string str, Type type) public static object? FromString(string str, Type type)

1
src/Avalonia.Themes.Simple/Controls/TextBox.xaml

@ -92,6 +92,7 @@
<Setter Property="CaretBrush" Value="{DynamicResource ThemeForegroundBrush}" /> <Setter Property="CaretBrush" Value="{DynamicResource ThemeForegroundBrush}" />
<Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}" /> <Setter Property="Background" Value="{DynamicResource ThemeBackgroundBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}" /> <Setter Property="BorderBrush" Value="{DynamicResource ThemeBorderMidBrush}" />
<Setter Property="Foreground" Value="{DynamicResource ThemeForegroundBrush}" />
<Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}" /> <Setter Property="BorderThickness" Value="{DynamicResource ThemeBorderThickness}" />
<Setter Property="SelectionBrush" Value="{DynamicResource HighlightBrush}" /> <Setter Property="SelectionBrush" Value="{DynamicResource HighlightBrush}" />
<Setter Property="SelectionForegroundBrush" Value="{DynamicResource HighlightForegroundBrush}" /> <Setter Property="SelectionForegroundBrush" Value="{DynamicResource HighlightForegroundBrush}" />

Loading…
Cancel
Save