();
+ if (clipboard == null)
+ {
+ statusBar.PublishNotification(new PlainNotification(NotificationType.Error, "Cannot copy to clipboard"));
+ return;
+ }
await clipboard.SetTextAsync(text);
statusBar.PublishNotification(new PlainNotification(NotificationType.Info, $"Copied '{text}' to the clipboard"));
}
diff --git a/WDE.Common.Avalonia/Controls/FastTreeView.cs b/WDE.Common.Avalonia/Controls/FastTreeView.cs
index 14ace3dc6..2c7857db8 100644
--- a/WDE.Common.Avalonia/Controls/FastTreeView.cs
+++ b/WDE.Common.Avalonia/Controls/FastTreeView.cs
@@ -1,11 +1,14 @@
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
+using System.Globalization;
using Avalonia;
using Avalonia.Controls;
+using Avalonia.Controls.Documents;
using Avalonia.Data;
using Avalonia.Input;
using Avalonia.Media;
+using Avalonia.Threading;
using Avalonia.VisualTree;
using WDE.Common.Avalonia.Utils;
using WDE.Common.Utils;
@@ -16,11 +19,12 @@ public abstract class FastTreeView : Control where P : IParentType where C
{
protected static SolidColorBrush HoverRowBackground = new SolidColorBrush(Color.FromRgb(87, 124, 219));
protected static SolidColorBrush SelectedRowBackground = new SolidColorBrush(Color.FromRgb(87, 124, 219));
+ #pragma warning disable AVP1002
public static readonly StyledProperty?> ItemsProperty = AvaloniaProperty.Register, FlatTreeList?>(nameof(Items));
public static readonly StyledProperty IsFilteredProperty = AvaloniaProperty.Register, bool>(nameof(IsFiltered));
public static readonly StyledProperty RequestRenderProperty = AvaloniaProperty.Register, bool>(nameof(RequestRender));
public static readonly StyledProperty SelectedNodeProperty = AvaloniaProperty.Register, INodeType?>(nameof(SelectedNode), defaultBindingMode: BindingMode.TwoWay);
-
+ #pragma warning restore AVP1002
public const float RowHeight = 24;
public const float Indent = 24;
@@ -56,9 +60,12 @@ private void ItemsChanged(AvaloniaPropertyChangedEventArgs args)
private void OldOnCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
{
- InvalidateMeasure();
- InvalidateArrange();
- InvalidateVisual();
+ Dispatcher.UIThread.Post(() =>
+ {
+ InvalidateMeasure();
+ InvalidateArrange();
+ InvalidateVisual();
+ });
}
protected object? mouseOverRow;
@@ -114,12 +121,12 @@ protected override void OnPointerPressed(PointerPressedEventArgs e)
{
if (currentPoint.Position.X <= Indent * parent.NestLevel || e.ClickCount == 2)
parent.IsExpanded = !parent.IsExpanded;
- SelectedNode = parent;
+ SetCurrentValue(SelectedNodeProperty, parent);
InvalidateVisual();
}
else if (obj is C child)
{
- SelectedNode = child;
+ SetCurrentValue(SelectedNodeProperty, child);
InvalidateVisual();
}
}
@@ -183,7 +190,7 @@ protected override void OnKeyDown(KeyEventArgs e)
var currentIndex = items.IndexOf(SelectedNode);
int nextIndex = GetNextIndex(items, currentIndex, moveDownUp);
if (nextIndex != -1)
- SelectedNode = items[nextIndex];
+ SetCurrentValue(SelectedNodeProperty, items[nextIndex]);
e.Handled = true;
}
@@ -210,9 +217,9 @@ protected override void OnPointerMoved(PointerEventArgs e)
MouseOverRow = GetRowAtPosition(point.Y);
}
- protected override void OnPointerLeave(PointerEventArgs e)
+ protected override void OnPointerExited(PointerEventArgs e)
{
- base.OnPointerLeave(e);
+ base.OnPointerExited(e);
MouseOverRow = null;
}
@@ -291,13 +298,16 @@ public override void Render(DrawingContext context)
if (ScrollViewer is not { } scrollViewer)
{
- context.DrawText(Brushes.Red, default,
- new FormattedText("FastTreeView must be wrapped in ScrollViewer!",
- Typeface.Default,
- 14,
- TextAlignment.Left,
- TextWrapping.Wrap,
- Bounds.Size));
+ var ft = new FormattedText("FastTreeView must be wrapped in ScrollViewer!",
+ CultureInfo.CurrentCulture,
+ FlowDirection.LeftToRight,
+ Typeface.Default,
+ 14,
+ Brushes.Red)
+ {
+ MaxTextWidth = Bounds.Width
+ };
+ context.DrawText(ft, default);
return;
}
@@ -310,8 +320,8 @@ public override void Render(DrawingContext context)
context.FillRectangle(Brushes.Transparent, new Rect(scrollViewer.Offset.X, scrollViewer.Offset.Y, scrollViewer.Viewport.Width, scrollViewer.Viewport.Height));
var items = Items;
- var font = new Typeface(TextBlock.GetFontFamily(this));
- var foreground = TextBlock.GetForeground(this);
+ var font = new Typeface(TextElement.GetFontFamily(this));
+ var foreground = TextElement.GetForeground(this);
var pen = new Pen(foreground, 2);
var hasFilter = IsFiltered;
@@ -332,7 +342,7 @@ public override void Render(DrawingContext context)
{
var rowRect = new Rect(0, y, actualWidth, RowHeight);
- DrawRow(font, pen, foreground, context, row, rowRect);
+ DrawRow(font, pen, foreground ?? Brushes.Red, context, row, rowRect);
}
y += RowHeight;
diff --git a/WDE.Common.Avalonia/Controls/FixedContextMenu.cs b/WDE.Common.Avalonia/Controls/FixedContextMenu.cs
index 208f6bfc3..7d0f67f2e 100644
--- a/WDE.Common.Avalonia/Controls/FixedContextMenu.cs
+++ b/WDE.Common.Avalonia/Controls/FixedContextMenu.cs
@@ -11,9 +11,9 @@ namespace WDE.Common.Avalonia.Controls;
/// Avalonia has a bug: a Context menu will always keep a reference to the previous focused control, even if the menu is closed.
/// which creates massive leaks.
///
-public class FixedContextMenu : ContextMenu, IStyleable
+public class FixedContextMenu : ContextMenu
{
- Type IStyleable.StyleKey => typeof(ContextMenu);
+ protected override Type StyleKeyOverride => typeof(ContextMenu);
private static FieldInfo? previousFocusField;
diff --git a/WDE.Common.Avalonia/Controls/FixedTextBox.cs b/WDE.Common.Avalonia/Controls/FixedTextBox.cs
index 871fea226..b721d69a6 100644
--- a/WDE.Common.Avalonia/Controls/FixedTextBox.cs
+++ b/WDE.Common.Avalonia/Controls/FixedTextBox.cs
@@ -10,9 +10,9 @@
namespace WDE.Common.Avalonia.Controls
{
// normal TextBox has bug when AcceptsReturn is false
- public class FixedTextBox : TextBox, IStyleable
+ public class FixedTextBox : TextBox
{
- Type IStyleable.StyleKey => typeof(TextBox);
+ protected override Type StyleKeyOverride => typeof(TextBox);
protected override void OnTextInput(TextInputEventArgs e)
{
@@ -25,8 +25,7 @@ protected override void OnTextInput(TextInputEventArgs e)
protected override void OnKeyDown(KeyEventArgs e)
{
- var keymap = AvaloniaLocator.Current.GetRequiredService();
- if (keymap.Paste.Any(g => g.Matches(e)))
+ if (KeyGestures.Paste.Matches(e))
{
CustomPaste();
e.Handled = true;
@@ -46,4 +45,4 @@ public virtual void CustomPaste()
Paste();
}
}
-}
\ No newline at end of file
+}
diff --git a/WDE.Common.Avalonia/Controls/FlagComboBox.cs b/WDE.Common.Avalonia/Controls/FlagComboBox.cs
index b7db272e5..17cdd597b 100644
--- a/WDE.Common.Avalonia/Controls/FlagComboBox.cs
+++ b/WDE.Common.Avalonia/Controls/FlagComboBox.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
+using System.Reactive.Linq;
using System.Runtime.CompilerServices;
using Avalonia;
using Avalonia.Collections;
@@ -22,7 +23,7 @@
namespace WDE.Common.Avalonia.Controls
{
- public class FlagComboBox : CompletionComboBox, IStyleable
+ public class FlagComboBox : CompletionComboBox
{
private AvaloniaList