Skip to content

Commit

Permalink
Add button to copy a key entry
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Mar 25, 2024
1 parent c703de9 commit 4339916
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 5 deletions.
29 changes: 29 additions & 0 deletions KeyManager.Library.UI/Domain/KeyEntriesControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,33 @@ public KeyEntriesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue, Ke
}
});

CopyKeyEntryCommand = new AsyncRelayCommand<SelectableKeyEntryId>(
async identifier =>
{
try
{
if (KeyStore != null && identifier?.KeyEntryId != null)
{
var model = CreateKeyEntryDialogViewModel();
model.SetKeyEntry(await KeyStore.Get(identifier.KeyEntryId, KeyEntryClass));
var dialog = new KeyEntryDialog
{
DataContext = model
};
await CreateKeyEntry(dialog);
}
}
catch (KeyStoreException ex)
{
SnackbarHelper.EnqueueError(_snackbarMessageQueue, ex, "Key Store Error");
}
catch (Exception ex)
{
log.Error("Unexpected error occured.", ex);
}
});

MoveUpKeyEntryCommand = new AsyncRelayCommand<SelectableKeyEntryId>(
async keyEntryId =>
{
Expand Down Expand Up @@ -305,6 +332,8 @@ private async Task<bool> EditDefaultKeyEntry(KeyEntryDialog dialog)

public AsyncRelayCommand<SelectableKeyEntryId> EditKeyEntryCommand { get; }

public AsyncRelayCommand<SelectableKeyEntryId> CopyKeyEntryCommand { get; }

private async Task UpdateKeyEntry(KeyEntryDialog dialog)
{
try
Expand Down
12 changes: 7 additions & 5 deletions KeyManager.Library.UI/KeyEntriesControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,24 @@
</StackPanel>
</StackPanel>
</materialDesign:DialogHost.DialogContent>

<Button x:Name="btnDeleteKeyEntry" Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}" Command="{x:Static materialDesign:DialogHost.OpenDialogCommand}" ToolTip="{x:Static properties:Resources.DeleteKeyEntry}" Margin="3" Visibility="{Binding DataContext.KeyStore.CanDeleteKeyEntries, ElementName=keyStoreControl, Converter={StaticResource BooleanToVisibilityConverter}}">
<materialDesign:PackIcon Kind="Delete" Height="24" Width="24" Cursor="Hand" />
</Button>
</materialDesign:DialogHost>
<materialDesign:PopupBox
PlacementMode="BottomAndAlignCentres" Margin="3"
Visibility="{Binding DataContext.KeyStore.CanReorderKeyEntries, ElementName=keyStoreControl, Converter={StaticResource BooleanToVisibilityConverter}}">
PlacementMode="BottomAndAlignCentres" Margin="3">
<materialDesign:PopupBox.ToggleContent>
<materialDesign:PackIcon Kind="DotsVertical" Height="24" Width="24" Cursor="Hand" />
</materialDesign:PopupBox.ToggleContent>
<StackPanel>
<Button Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}" Command="{Binding DataContext.MoveUpKeyEntryCommand, ElementName=keyStoreControl}" CommandParameter="{Binding}" ToolTip="{x:Static properties:Resources.MoveUp}" Margin="3">
<Button Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}" Command="{Binding DataContext.CopyKeyEntryCommand, ElementName=keyStoreControl}" CommandParameter="{Binding}" ToolTip="{x:Static properties:Resources.CopyKeyEntry}" Margin="3" Visibility="{Binding DataContext.KeyStore.CanCreateKeyEntries, ElementName=keystoreControl, Converter={StaticResource BooleanToVisibilityConverter}}">
<materialDesign:PackIcon Kind="ContentCopy" Height="24" Width="24" Cursor="Hand" />
</Button>
<Button Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}" Command="{Binding DataContext.MoveUpKeyEntryCommand, ElementName=keyStoreControl}" CommandParameter="{Binding}" ToolTip="{x:Static properties:Resources.MoveUp}" Visibility="{Binding DataContext.KeyStore.CanReorderKeyEntries, ElementName=keyStoreControl, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="3">
<materialDesign:PackIcon Kind="ArrowUp" Height="24" Width="24" Cursor="Hand" />
</Button>
<Button Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}" Command="{Binding DataContext.MoveDownKeyEntryCommand, ElementName=keyStoreControl}" CommandParameter="{Binding}" ToolTip="{x:Static properties:Resources.MoveDown}" Margin="3">
<Button Style="{StaticResource MaterialDesignFloatingActionMiniLightButton}" Command="{Binding DataContext.MoveDownKeyEntryCommand, ElementName=keyStoreControl}" CommandParameter="{Binding}" ToolTip="{x:Static properties:Resources.MoveDown}" Visibility="{Binding DataContext.KeyStore.CanReorderKeyEntries, ElementName=keyStoreControl, Converter={StaticResource BooleanToVisibilityConverter}}" Margin="3">
<materialDesign:PackIcon Kind="ArrowDown" Height="24" Width="24" Cursor="Hand" />
</Button>
</StackPanel>
Expand Down
9 changes: 9 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.fr.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@
<data name="CopyClipboard" xml:space="preserve">
<value>Copier vers le presse-papier</value>
</data>
<data name="CopyKeyEntry" xml:space="preserve">
<value>Copier l'enregistrement de clés</value>
</data>
<data name="CopyWords" xml:space="preserve">
<value>Copier les mots</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions KeyManager.Library.UI/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@
<data name="CopyClipboard" xml:space="preserve">
<value>Copy to clipboard</value>
</data>
<data name="CopyKeyEntry" xml:space="preserve">
<value>Copy the Key Entry</value>
</data>
<data name="CopyWords" xml:space="preserve">
<value>Copy words</value>
</data>
Expand Down

0 comments on commit 4339916

Please sign in to comment.