|
|
|
@ -246,25 +246,6 @@ namespace Avalonia.Controls |
|
|
|
/// </typeparam>
|
|
|
|
public delegate string AutoCompleteSelector<T>(string search, T item); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Specifies how the selected autocomplete result should be treated.
|
|
|
|
/// </summary>
|
|
|
|
public enum AutoCompleteMode |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Specifies that the text will be replaced
|
|
|
|
/// with the selected autocomplete result.
|
|
|
|
/// </summary>
|
|
|
|
Replace = 0, |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Specifies that a custom selector is used. This mode is used when
|
|
|
|
/// the <see cref="P:Avalonia.Controls.AutoCompleteBox.TextSelector"/>
|
|
|
|
/// property is set.
|
|
|
|
/// </summary>
|
|
|
|
Custom = 1 |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Represents a control that provides a text box for user input and a
|
|
|
|
/// drop-down that contains possible matches based on the input in the text
|
|
|
|
@ -402,7 +383,7 @@ namespace Avalonia.Controls |
|
|
|
private AutoCompleteFilterPredicate<object> _itemFilter; |
|
|
|
private AutoCompleteFilterPredicate<string> _textFilter = AutoCompleteSearch.GetFilter(AutoCompleteFilterMode.StartsWith); |
|
|
|
|
|
|
|
private AutoCompleteSelector<string> _textSelector = AutoCompleteSelection.GetSelector(AutoCompleteMode.Replace); |
|
|
|
private AutoCompleteSelector<string> _textSelector; |
|
|
|
|
|
|
|
public static readonly RoutedEvent<SelectionChangedEventArgs> SelectionChangedEvent = |
|
|
|
RoutedEvent.Register<SelectionChangedEventArgs>(nameof(SelectionChanged), RoutingStrategies.Bubble, typeof(AutoCompleteBox)); |
|
|
|
@ -541,17 +522,6 @@ namespace Avalonia.Controls |
|
|
|
defaultValue: AutoCompleteFilterMode.StartsWith, |
|
|
|
validate: IsValidFilterMode); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets the identifier for the
|
|
|
|
/// <see cref="P:Avalonia.Controls.AutoCompleteBox.AutoCompleteMode" />
|
|
|
|
/// dependency property.
|
|
|
|
/// </summary>
|
|
|
|
public static readonly StyledProperty<AutoCompleteMode> AutoCompleteModeProperty = |
|
|
|
AvaloniaProperty.Register<AutoCompleteBox, AutoCompleteMode>( |
|
|
|
nameof(AutoCompleteMode), |
|
|
|
defaultValue: AutoCompleteMode.Replace, |
|
|
|
validate: IsValidAutoCompleteMode); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Identifies the
|
|
|
|
/// <see cref="P:Avalonia.Controls.AutoCompleteBox.ItemFilter" />
|
|
|
|
@ -593,8 +563,7 @@ namespace Avalonia.Controls |
|
|
|
AvaloniaProperty.RegisterDirect<AutoCompleteBox, AutoCompleteSelector<string>>( |
|
|
|
nameof(TextSelector), |
|
|
|
o => o.TextSelector, |
|
|
|
(o, v) => o.TextSelector = v, |
|
|
|
unsetValue: AutoCompleteSelection.GetSelector(AutoCompleteMode.Replace)); |
|
|
|
(o, v) => o.TextSelector = v); |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Identifies the
|
|
|
|
@ -646,18 +615,6 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private static bool IsValidAutoCompleteMode(AutoCompleteMode mode) |
|
|
|
{ |
|
|
|
switch (mode) |
|
|
|
{ |
|
|
|
case AutoCompleteMode.Replace: |
|
|
|
case AutoCompleteMode.Custom: |
|
|
|
return true; |
|
|
|
default: |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Handle the change of the IsEnabled property.
|
|
|
|
/// </summary>
|
|
|
|
@ -808,19 +765,6 @@ namespace Avalonia.Controls |
|
|
|
TextFilter = AutoCompleteSearch.GetFilter(mode); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// AutoCompleteModeProperty property changed handler.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="e">Event arguments.</param>
|
|
|
|
private void OnAutoCompleteModePropertyChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
|
{ |
|
|
|
AutoCompleteMode mode = (AutoCompleteMode)e.NewValue; |
|
|
|
|
|
|
|
// Sets the text selector for the new value
|
|
|
|
if (mode != AutoCompleteMode.Custom) |
|
|
|
TextSelector = AutoCompleteSelection.GetSelector(mode); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// ItemFilterProperty property changed handler.
|
|
|
|
/// </summary>
|
|
|
|
@ -841,25 +785,6 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// TextSelectorProperty property changed handler.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="e">Event arguments.</param>
|
|
|
|
private void OnTextSelectorPropertyChanged(AvaloniaPropertyChangedEventArgs e) |
|
|
|
{ |
|
|
|
AutoCompleteSelector<string> value = e.NewValue as AutoCompleteSelector<string>; |
|
|
|
|
|
|
|
// If null, revert to the "Replace" predicate
|
|
|
|
if (value == null) |
|
|
|
{ |
|
|
|
AutoCompleteMode = AutoCompleteMode.Replace; |
|
|
|
} |
|
|
|
else if (value.Method.DeclaringType != typeof(AutoCompleteSelection)) |
|
|
|
{ |
|
|
|
AutoCompleteMode = AutoCompleteMode.Custom; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// ItemsSourceProperty property changed handler.
|
|
|
|
/// </summary>
|
|
|
|
@ -905,8 +830,6 @@ namespace Avalonia.Controls |
|
|
|
SearchTextProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnSearchTextPropertyChanged(e)); |
|
|
|
FilterModeProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnFilterModePropertyChanged(e)); |
|
|
|
ItemFilterProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnItemFilterPropertyChanged(e)); |
|
|
|
AutoCompleteModeProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnAutoCompleteModePropertyChanged(e)); |
|
|
|
TextSelectorProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnTextSelectorPropertyChanged(e)); |
|
|
|
ItemsProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnItemsPropertyChanged(e)); |
|
|
|
IsEnabledProperty.Changed.AddClassHandler<AutoCompleteBox>((x,e) => x.OnControlIsEnabledChanged(e)); |
|
|
|
} |
|
|
|
@ -1129,31 +1052,6 @@ namespace Avalonia.Controls |
|
|
|
set { SetValue(FilterModeProperty, value); } |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Gets or sets how the text in the text box will be modified
|
|
|
|
/// with the selected autocomplete item.
|
|
|
|
/// </summary>
|
|
|
|
/// <value>
|
|
|
|
/// One of the <see cref="T:Avalonia.Controls.AutoCompleteMode" />
|
|
|
|
/// values. The default is
|
|
|
|
/// <see cref="F:Avalonia.Controls.AutoCompleteMode.Replace" />.</value>
|
|
|
|
/// <exception cref="T:System.ArgumentException">
|
|
|
|
/// The specified value is not a valid
|
|
|
|
/// <see cref="T:Avalonia.Controls.AutoCompleteMode" />.
|
|
|
|
/// </exception>
|
|
|
|
/// <remarks>
|
|
|
|
/// Use the AutoCompleteMode property to specify the way the text will
|
|
|
|
/// be modified with the selected autocomplete item. For example, text
|
|
|
|
/// can be modified in a predefined or custom way. The autocomplete
|
|
|
|
/// mode is automatically set to Custom if you set the TextSelector
|
|
|
|
/// property.
|
|
|
|
/// </remarks>
|
|
|
|
public AutoCompleteMode AutoCompleteMode |
|
|
|
{ |
|
|
|
get { return GetValue(AutoCompleteModeProperty); } |
|
|
|
set { SetValue(AutoCompleteModeProperty, value); } |
|
|
|
} |
|
|
|
|
|
|
|
public string Watermark |
|
|
|
{ |
|
|
|
get { return GetValue(WatermarkProperty); } |
|
|
|
@ -2490,7 +2388,8 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
text = TextSelector(SearchText, FormatValue(newItem, true)); |
|
|
|
string formattedValue = FormatValue(newItem, true); |
|
|
|
text = TextSelector == null ? formattedValue : TextSelector(SearchText, formattedValue); |
|
|
|
} |
|
|
|
|
|
|
|
// Update the Text property and the TextBox values
|
|
|
|
@ -2749,45 +2648,6 @@ namespace Avalonia.Controls |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A predefined set of selector functions for the known, built-in
|
|
|
|
/// AutoCompleteMode enumeration values.
|
|
|
|
/// </summary>
|
|
|
|
private static class AutoCompleteSelection |
|
|
|
{ |
|
|
|
/// <summary>
|
|
|
|
/// Index function that retrieves the selector for the provided
|
|
|
|
/// AutoCompleteMode.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="completeMode">The built-in autocomplete mode.</param>
|
|
|
|
/// <returns>Returns the string-based selector function.</returns>
|
|
|
|
public static AutoCompleteSelector<string> GetSelector(AutoCompleteMode completeMode) |
|
|
|
{ |
|
|
|
switch (completeMode) |
|
|
|
{ |
|
|
|
case AutoCompleteMode.Replace: |
|
|
|
return Replace; |
|
|
|
case AutoCompleteMode.Custom: |
|
|
|
default: |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Implements AutoCompleteMode.Replace.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="text">The AutoCompleteBox prefix text.</param>
|
|
|
|
/// <param name="value">The item's string value.</param>
|
|
|
|
/// <returns>
|
|
|
|
/// Return the <paramref name="value"/> and ignores the
|
|
|
|
/// <paramref name="text"/>.
|
|
|
|
/// </returns>
|
|
|
|
private static string Replace(string text, string value) |
|
|
|
{ |
|
|
|
return value ?? String.Empty; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// A framework element that permits a binding to be evaluated in a new data
|
|
|
|
/// context leaf node.
|
|
|
|
|