-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e0e273d
commit a31e2a5
Showing
6 changed files
with
167 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<UserControl xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:avalonia="clr-namespace:Projektanker.Icons.Avalonia;assembly=Projektanker.Icons.Avalonia" | ||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" | ||
x:Class="ScriptRunner.GUI.Views.PasswordBox"> | ||
<Grid> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="*"></ColumnDefinition> | ||
<ColumnDefinition Width="Auto"></ColumnDefinition> | ||
</Grid.ColumnDefinitions> | ||
<TextBox Grid.Column="0" PasswordChar="*" x:Name="PasswordTextBox"></TextBox> | ||
<Button avalonia:Attached.Icon="fas fa-lock" Margin="5,0" ToolTip.Tip="Pick password from vault" Grid.Column="1" Width="50" Click="PickFromVault" VerticalAlignment="Stretch" VerticalContentAlignment="Center" HorizontalContentAlignment="Center"></Button> | ||
</Grid> | ||
</UserControl> |
57 changes: 57 additions & 0 deletions
57
src/ScriptRunner/ScriptRunner.GUI/Views/PasswordBox.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Markup.Xaml; | ||
using Avalonia.Threading; | ||
using Avalonia.VisualTree; | ||
|
||
namespace ScriptRunner.GUI.Views | ||
{ | ||
public partial class PasswordBox : UserControl | ||
{ | ||
public PasswordBox() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void InitializeComponent() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
private async void PickFromVault(object? sender, RoutedEventArgs e) | ||
{ | ||
var pickerDialog = new VaultPicker(); | ||
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) | ||
{ | ||
var sourceWindow = (sender as IControl)?.GetVisualRoot() as Window ?? desktop.MainWindow; | ||
var selectedPassword = await pickerDialog.ShowDialog<string?>(sourceWindow); | ||
if (selectedPassword != null) | ||
{ | ||
Dispatcher.UIThread.Post(() => | ||
{ | ||
Password = selectedPassword; | ||
}); | ||
|
||
} | ||
} | ||
} | ||
|
||
public static readonly DirectProperty<PasswordBox, string?> PasswordProperty = AvaloniaProperty.RegisterDirect<PasswordBox, string?> | ||
( | ||
name: nameof(Password), | ||
getter: picker => picker.FindControl<TextBox>("PasswordTextBox").Text, | ||
setter: (picker, s) => picker.FindControl<TextBox>("PasswordTextBox").Text = s | ||
); | ||
|
||
|
||
public string? Password | ||
{ | ||
get => GetValue(PasswordProperty); | ||
set => SetValue(PasswordProperty, value); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Window xmlns="https://github.com/avaloniaui" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
mc:Ignorable="d" Width="400" | ||
SizeToContent="WidthAndHeight" | ||
x:Class="ScriptRunner.GUI.Views.VaultPicker" | ||
WindowStartupLocation="CenterOwner" | ||
Title="Pick secret"> | ||
<StackPanel Margin="40"> | ||
<ComboBox Name="SecretsCombo" Items="{Binding}" HorizontalAlignment="Center" Margin="10,0,0,20" Width="250"> | ||
<ComboBox.ItemTemplate> | ||
<DataTemplate> | ||
<TextBlock Text="{Binding Name}" FontFamily="{Binding}" /> | ||
</DataTemplate> | ||
</ComboBox.ItemTemplate> | ||
</ComboBox> | ||
<Button HorizontalAlignment="Center" Click="Accept">Use selected secret</Button> | ||
</StackPanel> | ||
</Window> |
28 changes: 28 additions & 0 deletions
28
src/ScriptRunner/ScriptRunner.GUI/Views/VaultPicker.axaml.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Interactivity; | ||
using Avalonia.Markup.Xaml; | ||
using ScriptRunner.GUI.ViewModels; | ||
|
||
namespace ScriptRunner.GUI.Views | ||
{ | ||
public partial class VaultPicker : Window | ||
{ | ||
public VaultPicker() | ||
{ | ||
|
||
DataContext = VaultProvider.ReadFromVault(); | ||
InitializeComponent(); | ||
#if DEBUG | ||
this.AttachDevTools(); | ||
#endif | ||
} | ||
|
||
|
||
|
||
private void Accept(object? sender, RoutedEventArgs e) | ||
{ | ||
Close((SecretsCombo.SelectedItem as VaultEntry)?.Secret); | ||
} | ||
} | ||
} |