Skip to content

Commit

Permalink
Added copy ui
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexMi-Ha committed Jun 23, 2024
1 parent 5874021 commit bca3a34
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
19 changes: 15 additions & 4 deletions PWManager.Avalonia/Controls/AccountsControl.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,25 @@

<SplitView x:Name="splitPane" PanePlacement="Right" DisplayMode="Inline" IsPaneOpen="false">
<SplitView.Pane>
<!-- <StackPanel FlowDirection="RightToLeft" Orientation="Horizontal" Background="green" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
</StackPanel> -->
<Border Background="{DynamicResource SystemBaseLowColor}" Padding="10 0">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Vertical" Spacing="5">
<DockPanel>
<Button Command="{Binding CloseSidePanel}" DockPanel.Dock="Left" Content="&#xf013e;" Classes="iconfont" FontSize="25"/>
</DockPanel>
<TextBlock Text="{Binding CurrentlyOpenedAccount.AccountName}" />
<StackPanel Orientation="Vertical" Margin="10 0">
<TextBlock Text="{Binding CurrentlyOpenedAccount.AccountName}" Foreground="{DynamicResource SystemControlBackgroundAccentBrush}" FontSize="16"/>

<TextBlock Text="Loginname" Opacity="0.6" FontSize="12" Margin="0 10 0 2" />
<StackPanel Orientation="Horizontal" Spacing="10">
<TextBlock MaxWidth="150" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding CurrentlyOpenedAccount.LoginName}" TextTrimming="CharacterEllipsis"/>
<Button Command="{Binding CopyActiveLoginName}" Classes="iconfont" Content="&#xf018f;" FontSize="16" VerticalAlignment="Center"/>
</StackPanel>
<TextBlock Text="Password" Opacity="0.6" FontSize="12" Margin="0 10 0 2" />
<StackPanel Orientation="Horizontal" Spacing="10">
<TextBlock MaxWidth="150" HorizontalAlignment="Left" VerticalAlignment="Center" Text="{Binding CurrentlyOpenedAccount.HiddenPassword}"/>
<Button Command="{Binding CopyActivePassword}" Classes="iconfont" Content="&#xf018f;" FontSize="16" VerticalAlignment="Center"/>
</StackPanel>
</StackPanel>
</StackPanel>
</Border>
</SplitView.Pane>
Expand Down
24 changes: 24 additions & 0 deletions PWManager.Avalonia/Controls/AccountsControl.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Threading.Tasks;

namespace PWManager.Avalonia.Controls;

Expand All @@ -13,6 +14,8 @@ public partial class AccountsControl : CustomControl {

public AccountDisplayModel? CurrentlyOpenedAccount {get;set;}

private TopLevel _window = null!;

public AccountsControl() {
InitializeComponent();
this.DataContext = this;
Expand All @@ -26,8 +29,15 @@ public AccountsControl() {
});

OnPropertyChanged(nameof(Accounts));

this.Initialized += OnInit;
}

private void OnInit(object? sender, EventArgs e) {
Console.WriteLine("Here");
_window = TopLevel.GetTopLevel(this) ?? throw new ApplicationException("Window not found");
Console.WriteLine("Here!");
}

private void UpdateSize(object? sender, SizeChangedEventArgs e) {
// splitPane.OpenPaneLength = Max
Expand All @@ -46,4 +56,18 @@ public void CloseSidePanel() {

OnPropertyChanged(nameof(CurrentlyOpenedAccount));
}

public async Task CopyActiveLoginName() {
if(_window.Clipboard is null || CurrentlyOpenedAccount is null) {
return;
}
await _window.Clipboard.SetTextAsync(CurrentlyOpenedAccount.LoginName);
}

public async Task CopyActivePassword() {
if(_window.Clipboard is null || CurrentlyOpenedAccount is null) {
return;
}
await _window.Clipboard.SetTextAsync(CurrentlyOpenedAccount.Password);
}
}
2 changes: 2 additions & 0 deletions PWManager.Avalonia/Models/AccountDisplayModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ public class AccountDisplayModel {

public string Password {get;set;}

public string HiddenPassword {get => new('*', Password.Length);}

}

0 comments on commit bca3a34

Please sign in to comment.