Skip to content

Commit

Permalink
Merge pull request WalletWasabi#12486 from wieslawsoltes/vdg/XmlnsDef…
Browse files Browse the repository at this point in the history
…inition

[VDG] Add XmlnsDefinition for WalletWasabi.Fluent.Controls namespace and fix CurrencyEntryBox paste and copying with PasswordChar
  • Loading branch information
RolandUI authored Feb 20, 2024
2 parents da5c450 + 6b61909 commit 6524696
Show file tree
Hide file tree
Showing 141 changed files with 1,080 additions and 990 deletions.
7 changes: 3 additions & 4 deletions WalletWasabi.Fluent/Controls/AdorningContentControl.axaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:WalletWasabi.Fluent.Controls">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.PreviewWith>
<controls:AdorningContentControl />
<AdorningContentControl />
</Design.PreviewWith>

<ControlTheme x:Key="{x:Type controls:AdorningContentControl}" TargetType="controls:AdorningContentControl">
<ControlTheme x:Key="{x:Type AdorningContentControl}" TargetType="AdorningContentControl">
<!-- Set Defaults -->
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
Expand Down
3 changes: 1 addition & 2 deletions WalletWasabi.Fluent/Controls/AmountControl.axaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:WalletWasabi.Fluent.Controls"
xmlns:converters="clr-namespace:WalletWasabi.Fluent.Converters">

<ControlTheme x:Key="{x:Type controls:AmountControl}" TargetType="controls:AmountControl">
<ControlTheme x:Key="{x:Type AmountControl}" TargetType="AmountControl">

<Setter Property="Template">
<ControlTemplate>
Expand Down
7 changes: 3 additions & 4 deletions WalletWasabi.Fluent/Controls/AnimatedButton.axaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="using:Avalonia.Xaml.Interactivity"
xmlns:ia="using:Avalonia.Xaml.Interactions.Core"
xmlns:c="clr-namespace:WalletWasabi.Fluent.Controls">
xmlns:ia="using:Avalonia.Xaml.Interactions.Core">

<Design.PreviewWith>
<c:AnimatedButton />
<AnimatedButton />
</Design.PreviewWith>

<ControlTheme x:Key="{x:Type c:AnimatedButton}" TargetType="c:AnimatedButton">
<ControlTheme x:Key="{x:Type AnimatedButton}" TargetType="AnimatedButton">

<Setter Property="Template">
<ControlTemplate>
Expand Down
9 changes: 4 additions & 5 deletions WalletWasabi.Fluent/Controls/ClipboardCopyButton.axaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="using:WalletWasabi.Fluent.Controls">
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Design.PreviewWith>
<c:ClipboardCopyButton Height="100" Width="200" />
<ClipboardCopyButton Height="100" Width="200" />
</Design.PreviewWith>

<ControlTheme x:Key="{x:Type c:ClipboardCopyButton}" TargetType="c:ClipboardCopyButton">
<ControlTheme x:Key="{x:Type ClipboardCopyButton}" TargetType="ClipboardCopyButton">

<Setter Property="Template">
<ControlTemplate>
<c:AnimatedButton x:Name="CopyButton" Command="{TemplateBinding CopyCommand}"
<AnimatedButton x:Name="CopyButton" Command="{TemplateBinding CopyCommand}"
NormalIcon="{StaticResource copy_regular}"
ClickIcon="{StaticResource copy_confirmed}"
InitialOpacity="0.6" />
Expand Down
11 changes: 5 additions & 6 deletions WalletWasabi.Fluent/Controls/ContentArea.axaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:c="using:WalletWasabi.Fluent.Controls"
xmlns:behaviors="using:WalletWasabi.Fluent.Behaviors"
xmlns:i="using:Avalonia.Xaml.Interactivity">
<Design.PreviewWith>
<Panel Background="{DynamicResource RegionColor}">
<c:ContentArea Width="500" Height="300"
<ContentArea Width="500" Height="300"
IsBusy="False"
Title="Add a Wallet"
EnableBack="True"
EnableCancel="True" CancelContent="Cancel" FocusCancel="False"
EnableNext="True" NextContent="Continue" FocusNext="True"
Caption="Type in your Wallet's name and select an option below:">
This is the content.
</c:ContentArea>
</ContentArea>
</Panel>
</Design.PreviewWith>

<ControlTheme x:Key="{x:Type c:ContentArea}" TargetType="c:ContentArea">
<ControlTheme x:Key="{x:Type ContentArea}" TargetType="ContentArea">

<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
Expand All @@ -26,7 +25,7 @@
<ControlTemplate>
<Panel>
<Panel IsHitTestVisible="False" Background="{TemplateBinding Background}" />
<c:ProgressRing Name="LoadingRing" IsIndeterminate="True" IsVisible="{TemplateBinding IsBusy}" />
<ProgressRing Name="LoadingRing" IsIndeterminate="True" IsVisible="{TemplateBinding IsBusy}" />
<DockPanel Name="MainDockPanel" IsVisible="{Binding !#LoadingRing.IsVisible}">

<Panel DockPanel.Dock="Bottom" x:Name="PART_ButtonArea">
Expand Down Expand Up @@ -122,7 +121,7 @@
<Setter Property="TextElement.FontSize" Value="{DynamicResource FontSizeH3}" />
</Style>

<Style Selector="^/template/ c|ProgressRing#LoadingRing">
<Style Selector="^/template/ ProgressRing#LoadingRing">
<Setter Property="Width" Value="100" />
<Setter Property="Height" Value="100" />
</Style>
Expand Down
15 changes: 7 additions & 8 deletions WalletWasabi.Fluent/Controls/CopyableItem.axaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="using:WalletWasabi.Fluent.Controls"
xmlns:converters="clr-namespace:WalletWasabi.Fluent.Converters">
<Design.PreviewWith>
<Border Width="300" Height="200">
<controls:CopyableItem HorizontalContentAlignment="Center" Background="Red">
<CopyableItem HorizontalContentAlignment="Center" Background="Red">
<Button Background="Blue">Hello everyone!</Button>
</controls:CopyableItem>
</CopyableItem>
</Border>
</Design.PreviewWith>

<ControlTheme x:Key="{x:Type controls:CopyableItem}" TargetType="controls:CopyableItem">
<ControlTheme x:Key="{x:Type CopyableItem}" TargetType="CopyableItem">

<Setter Property="ClipToBounds" Value="False" />

Expand All @@ -24,14 +23,14 @@
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
<controls:ClipboardCopyButton x:Name="CopyButton" Text="{TemplateBinding ContentToCopy}" HorizontalAlignment="Right" Margin="0 0 -24 0">
<controls:ClipboardCopyButton.IsVisible>
<ClipboardCopyButton x:Name="CopyButton" Text="{TemplateBinding ContentToCopy}" HorizontalAlignment="Right" Margin="0 0 -24 0">
<ClipboardCopyButton.IsVisible>
<MultiBinding Converter="{x:Static converters:BooleanConverters.Or}">
<Binding Path="#ContentPane.IsPointerOver" />
<Binding Path="#CopyButton.CopyCommand.IsExecuting^" />
</MultiBinding>
</controls:ClipboardCopyButton.IsVisible>
</controls:ClipboardCopyButton>
</ClipboardCopyButton.IsVisible>
</ClipboardCopyButton>
</Grid>
</Border>
</ControlTemplate>
Expand Down
150 changes: 150 additions & 0 deletions WalletWasabi.Fluent/Controls/CopyablePasswordTextBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
using System.Collections.Generic;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;

namespace WalletWasabi.Fluent.Controls;

public partial class CopyablePasswordTextBox : TextBox
{
public static readonly DirectProperty<CopyablePasswordTextBox, bool> CanCutModifiedProperty =
AvaloniaProperty.RegisterDirect<CopyablePasswordTextBox, bool>(
nameof(CanCutModified),
o => o.CanCutModified);

public static readonly DirectProperty<CopyablePasswordTextBox, bool> CanCopyModifiedProperty =
AvaloniaProperty.RegisterDirect<CopyablePasswordTextBox, bool>(
nameof(CanCopyModified),
o => o.CanCopyModified);

public static readonly DirectProperty<CopyablePasswordTextBox, bool> CanPasteModifiedProperty =
AvaloniaProperty.RegisterDirect<CopyablePasswordTextBox, bool>(
nameof(CanPasteModified),
o => o.CanPasteModified);

private bool _canCutModified;
private bool _canCopyModified;
private bool _canPasteModified;

protected override Type StyleKeyOverride => typeof(TextBox);

public bool CanCutModified
{
get => _canCutModified;
private set => SetAndRaise(CanCutModifiedProperty, ref _canCutModified, value);
}

public bool CanCopyModified
{
get => _canCopyModified;
private set => SetAndRaise(CanCopyProperty, ref _canCopyModified, value);
}

public bool CanPasteModified
{
get => _canPasteModified;
private set => SetAndRaise(CanPasteProperty, ref _canPasteModified, value);
}

private string GetSelection()
{
var text = Text;

if (string.IsNullOrEmpty(text))
{
return "";
}

var selectionStart = SelectionStart;
var selectionEnd = SelectionEnd;
var start = Math.Min(selectionStart, selectionEnd);
var end = Math.Max(selectionStart, selectionEnd);

if (start == end || (Text?.Length ?? 0) < end)
{
return "";
}

return text[start..end];
}

private void UpdateCommandStates()
{
var text = GetSelection();
var isSelectionNullOrEmpty = string.IsNullOrEmpty(text);
CanCopyModified = RevealPassword && !isSelectionNullOrEmpty;
CanCutModified = RevealPassword && !isSelectionNullOrEmpty && !IsReadOnly;
CanPasteModified = !IsReadOnly;
}

protected override void OnKeyDown(KeyEventArgs e)
{
var handled = false;
var keymap = Application.Current!.PlatformSettings!.HotkeyConfiguration;

bool Match(List<KeyGesture> gestures) => gestures.Any(g => g.Matches(e));

if (Match(keymap.Copy))
{
Copy();
handled = true;
}
else if (Match(keymap.Cut))
{
Cut();
handled = true;
}
else if (Match(keymap.Paste))
{
Paste();
handled = true;
}

if (handled)
{
e.Handled = true;
}
else
{
base.OnKeyDown(e);
}
}

protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
{
base.OnPropertyChanged(change);

if (change.Property == TextProperty)
{
UpdateCommandStates();
}
else if (change.Property == SelectionStartProperty)
{
UpdateCommandStates();
}
else if (change.Property == SelectionEndProperty)
{
UpdateCommandStates();
}
else if (change.Property == RevealPasswordProperty)
{
UpdateCommandStates();
}
}

protected override void OnGotFocus(GotFocusEventArgs e)
{
base.OnGotFocus(e);

UpdateCommandStates();
}

protected override void OnLostFocus(RoutedEventArgs e)
{
base.OnLostFocus(e);

UpdateCommandStates();
}
}
Loading

0 comments on commit 6524696

Please sign in to comment.