Browse Source

Merge branch 'master' into osx_middleClick

pull/6484/head
Dan Walmsley 5 years ago
committed by GitHub
parent
commit
63dd7b54ad
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      native/Avalonia.Native/src/OSX/window.mm
  2. 6
      src/Avalonia.Base/Collections/AvaloniaList.cs
  3. 7
      src/Avalonia.Controls.DataGrid/Collections/DataGridGroupDescription.cs
  4. 13
      src/Avalonia.Controls.DataGrid/Utils/CellEditBinding.cs
  5. 16
      src/Avalonia.Controls/AutoCompleteBox.cs
  6. 73
      src/Avalonia.Controls/TextBox.cs
  7. 5
      src/Avalonia.Input/AccessKeyHandler.cs
  8. 10
      tests/Avalonia.Controls.UnitTests/AutoCompleteBoxTests.cs

8
native/Avalonia.Native/src/OSX/window.mm

@ -641,6 +641,7 @@ private:
[Window setCanBecomeKeyAndMain]; [Window setCanBecomeKeyAndMain];
[Window disableCursorRects]; [Window disableCursorRects];
[Window setTabbingMode:NSWindowTabbingModeDisallowed]; [Window setTabbingMode:NSWindowTabbingModeDisallowed];
[Window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
} }
void HideOrShowTrafficLights () void HideOrShowTrafficLights ()
@ -1091,14 +1092,7 @@ private:
{ {
_fullScreenActive = true; _fullScreenActive = true;
[Window setHasShadow:YES];
[Window setTitleVisibility:NSWindowTitleVisible];
[Window setTitlebarAppearsTransparent:NO];
[Window setTitle:_lastTitle]; [Window setTitle:_lastTitle];
Window.styleMask = Window.styleMask | NSWindowStyleMaskTitled | NSWindowStyleMaskResizable;
Window.styleMask = Window.styleMask & ~NSWindowStyleMaskFullSizeContentView;
[Window toggleFullScreen:nullptr]; [Window toggleFullScreen:nullptr];
} }

6
src/Avalonia.Base/Collections/AvaloniaList.cs

@ -280,8 +280,8 @@ namespace Avalonia.Collections
/// <summary> /// <summary>
/// Gets a range of items from the collection. /// Gets a range of items from the collection.
/// </summary> /// </summary>
/// <param name="index">The first index to remove.</param> /// <param name="index">The zero-based <see cref="AvaloniaList{T}"/> index at which the range starts.</param>
/// <param name="count">The number of items to remove.</param> /// <param name="count">The number of elements in the range.</param>
public IEnumerable<T> GetRange(int index, int count) public IEnumerable<T> GetRange(int index, int count)
{ {
return _inner.GetRange(index, count); return _inner.GetRange(index, count);
@ -455,7 +455,7 @@ namespace Avalonia.Collections
} }
/// <summary> /// <summary>
/// Ensures that the capacity of the list is at least <see cref="capacity"/>. /// Ensures that the capacity of the list is at least <see cref="Capacity"/>.
/// </summary> /// </summary>
/// <param name="capacity">The capacity.</param> /// <param name="capacity">The capacity.</param>
public void EnsureCapacity(int capacity) public void EnsureCapacity(int capacity)

7
src/Avalonia.Controls.DataGrid/Collections/DataGridGroupDescription.cs

@ -83,8 +83,9 @@ namespace Avalonia.Collections
if (key == null) if (key == null)
key = item; key = item;
if (_valueConverter != null) var valueConverter = ValueConverter;
key = _valueConverter.Convert(key, typeof(object), level, culture); if (valueConverter != null)
key = valueConverter.Convert(key, typeof(object), level, culture);
return key; return key;
} }
@ -99,6 +100,8 @@ namespace Avalonia.Collections
} }
public override string PropertyName => _propertyPath; public override string PropertyName => _propertyPath;
public IValueConverter ValueConverter { get => _valueConverter; set => _valueConverter = value; }
private Type GetPropertyType(object o) private Type GetPropertyType(object o)
{ {
return o.GetType().GetNestedPropertyType(_propertyPath); return o.GetType().GetNestedPropertyType(_propertyPath);

13
src/Avalonia.Controls.DataGrid/Utils/CellEditBinding.cs

@ -1,10 +1,8 @@
using Avalonia.Data; using Avalonia.Data;
using Avalonia.Reactive; using Avalonia.Reactive;
using System; using System;
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reactive.Subjects; using System.Reactive.Subjects;
using System.Text;
namespace Avalonia.Controls.Utils namespace Avalonia.Controls.Utils
{ {
@ -67,11 +65,14 @@ namespace Avalonia.Controls.Utils
private void SetSourceValue(object value) private void SetSourceValue(object value)
{ {
_settingSourceValue = true; if (!_settingSourceValue)
{
_settingSourceValue = true;
_sourceSubject.OnNext(value); _sourceSubject.OnNext(value);
_settingSourceValue = false; _settingSourceValue = false;
}
} }
private void SetControlValue(object value) private void SetControlValue(object value)
{ {
@ -157,4 +158,4 @@ namespace Avalonia.Controls.Utils
} }
} }
} }
} }

16
src/Avalonia.Controls/AutoCompleteBox.cs

@ -2094,7 +2094,21 @@ namespace Avalonia.Controls
bool inResults = !(stringFiltering || objectFiltering); bool inResults = !(stringFiltering || objectFiltering);
if (!inResults) if (!inResults)
{ {
inResults = stringFiltering ? TextFilter(text, FormatValue(item)) : ItemFilter(text, item); if (stringFiltering)
{
inResults = TextFilter(text, FormatValue(item));
}
else
{
if (ItemFilter is null)
{
throw new Exception("ItemFilter property can not be null when FilterMode has value AutoCompleteFilterMode.Custom");
}
else
{
inResults = ItemFilter(text, item);
}
}
} }
if (view_count > view_index && inResults && _view[view_index] == item) if (view_count > view_index && inResults && _view[view_index] == item)

73
src/Avalonia.Controls/TextBox.cs

@ -145,6 +145,18 @@ namespace Avalonia.Controls
(o, v) => o.UndoLimit = v, (o, v) => o.UndoLimit = v,
unsetValue: -1); unsetValue: -1);
public static readonly RoutedEvent<RoutedEventArgs> CopyingToClipboardEvent =
RoutedEvent.Register<TextBox, RoutedEventArgs>(
"CopyingToClipboard", RoutingStrategies.Bubble);
public static readonly RoutedEvent<RoutedEventArgs> CuttingToClipboardEvent =
RoutedEvent.Register<TextBox, RoutedEventArgs>(
"CuttingToClipboard", RoutingStrategies.Bubble);
public static readonly RoutedEvent<RoutedEventArgs> PastingFromClipboardEvent =
RoutedEvent.Register<TextBox, RoutedEventArgs>(
"PastingFromClipboard", RoutingStrategies.Bubble);
readonly struct UndoRedoState : IEquatable<UndoRedoState> readonly struct UndoRedoState : IEquatable<UndoRedoState>
{ {
public string Text { get; } public string Text { get; }
@ -500,6 +512,24 @@ namespace Avalonia.Controls
} }
} }
public event EventHandler<RoutedEventArgs> CopyingToClipboard
{
add => AddHandler(CopyingToClipboardEvent, value);
remove => RemoveHandler(CopyingToClipboardEvent, value);
}
public event EventHandler<RoutedEventArgs> CuttingToClipboard
{
add => AddHandler(CuttingToClipboardEvent, value);
remove => RemoveHandler(CuttingToClipboardEvent, value);
}
public event EventHandler<RoutedEventArgs> PastingFromClipboard
{
add => AddHandler(PastingFromClipboardEvent, value);
remove => RemoveHandler(PastingFromClipboardEvent, value);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e) protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{ {
_presenter = e.NameScope.Get<TextPresenter>("PART_TextPresenter"); _presenter = e.NameScope.Get<TextPresenter>("PART_TextPresenter");
@ -638,27 +668,54 @@ namespace Avalonia.Controls
public async void Cut() public async void Cut()
{ {
var text = GetSelection(); var text = GetSelection();
if (text is null) return; if (string.IsNullOrEmpty(text))
{
return;
}
SnapshotUndoRedo(); var eventArgs = new RoutedEventArgs(CuttingToClipboardEvent);
Copy(); RaiseEvent(eventArgs);
DeleteSelection(); if (!eventArgs.Handled)
{
SnapshotUndoRedo();
await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard)))
.SetTextAsync(text);
DeleteSelection();
}
} }
public async void Copy() public async void Copy()
{ {
var text = GetSelection(); var text = GetSelection();
if (text is null) return; if (string.IsNullOrEmpty(text))
{
return;
}
await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))) var eventArgs = new RoutedEventArgs(CopyingToClipboardEvent);
.SetTextAsync(text); RaiseEvent(eventArgs);
if (!eventArgs.Handled)
{
await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard)))
.SetTextAsync(text);
}
} }
public async void Paste() public async void Paste()
{ {
var eventArgs = new RoutedEventArgs(PastingFromClipboardEvent);
RaiseEvent(eventArgs);
if (eventArgs.Handled)
{
return;
}
var text = await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))).GetTextAsync(); var text = await ((IClipboard)AvaloniaLocator.Current.GetService(typeof(IClipboard))).GetTextAsync();
if (text is null) return; if (string.IsNullOrEmpty(text))
{
return;
}
SnapshotUndoRedo(); SnapshotUndoRedo();
HandleTextInput(text); HandleTextInput(text);

5
src/Avalonia.Input/AccessKeyHandler.cs

@ -157,10 +157,9 @@ namespace Avalonia.Input
_restoreFocusElement?.Focus(); _restoreFocusElement?.Focus();
_restoreFocusElement = null; _restoreFocusElement = null;
e.Handled = true;
} }
// We always handle the Alt key.
e.Handled = true;
} }
else if (_altIsDown) else if (_altIsDown)
{ {

10
tests/Avalonia.Controls.UnitTests/AutoCompleteBoxTests.cs

@ -105,6 +105,16 @@ namespace Avalonia.Controls.UnitTests
}); });
} }
[Fact]
public void Custom_FilterMode_Without_ItemFilter_Setting_Throws_Exception()
{
RunTest((control, textbox) =>
{
control.FilterMode = AutoCompleteFilterMode.Custom;
Assert.Throws<Exception>(() => { control.Text = "a"; });
});
}
[Fact] [Fact]
public void Text_Completion_Via_Text_Property() public void Text_Completion_Via_Text_Property()
{ {

Loading…
Cancel
Save