Skip to content

Commit

Permalink
Add key store property to automatically hide/show key entry label if …
Browse files Browse the repository at this point in the history
…supported
  • Loading branch information
Maxhy committed Feb 12, 2024
1 parent 14157f1 commit 8b3839d
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 17 deletions.
4 changes: 3 additions & 1 deletion KeyManager.Library.KeyStore.NXP_SAM/SAMKeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ public SAMKeyStoreProperties GetSAMProperties()
return p ?? throw new KeyStoreException("Missing SAM key store properties.");
}

public override string Name => "NXP SAM AV2";
public override string Name => "NXP SAM AV2/AV3";

public override bool CanCreateKeyEntries => false;

public override bool CanDeleteKeyEntries => false;

public override bool CanDefineKeyEntryLabel => false;

public override IEnumerable<KeyEntryClass> SupportedClasses
{
get => new KeyEntryClass[] { KeyEntryClass.Symmetric };
Expand Down
36 changes: 21 additions & 15 deletions KeyManager.Library.UI/Domain/KeyEntriesControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public KeyEntriesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue, Ke
CreateKeyEntryCommand = new AsyncRelayCommand(
async () =>
{
var model = new KeyEntryDialogViewModel(KeyEntryClass);
model.SetKeyEntry(KeyStore?.GetDefaultKeyEntry(KeyEntryClass));
var model = CreateKeyEntryDialogViewModel();
var dialog = new KeyEntryDialog
{
DataContext = model
Expand All @@ -38,11 +37,8 @@ public KeyEntriesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue, Ke
GenerateKeyEntryCommand = new AsyncRelayCommand(
async () =>
{
var model = new KeyEntryDialogViewModel(KeyEntryClass)
{
ShowKeyMaterials = false
};
model.SetKeyEntry(KeyStore?.GetDefaultKeyEntry(KeyEntryClass));
var model = CreateKeyEntryDialogViewModel();
model.ShowKeyMaterials = false;
var dialog = new KeyEntryDialog
{
DataContext = model
Expand All @@ -53,8 +49,7 @@ public KeyEntriesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue, Ke
EditDefaultKeyEntryCommand = new AsyncRelayCommand(
async () =>
{
var model = new KeyEntryDialogViewModel(KeyEntryClass);
model.SetKeyEntry(KeyStore?.GetDefaultKeyEntry(KeyEntryClass, false));
var model = CreateKeyEntryDialogViewModel(false);
var dialog = new KeyEntryDialog
{
DataContext = model
Expand All @@ -72,12 +67,10 @@ public KeyEntriesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue, Ke
{
if (KeyStore != null && identifier?.KeyEntryId != null)
{
var model = new KeyEntryDialogViewModel(KeyEntryClass)
{
CanChangeFactory = false,
AllowSubmit = KeyStore.CanUpdateKeyEntries,
SubmitButtonText = Properties.Resources.Update
};
var model = CreateKeyEntryDialogViewModel();
model.CanChangeFactory = false;
model.AllowSubmit = KeyStore.CanUpdateKeyEntries;
model.SubmitButtonText = Properties.Resources.Update;
model.SetKeyEntry(await KeyStore.Get(identifier.KeyEntryId, KeyEntryClass));
var dialog = new KeyEntryDialog
{
Expand Down Expand Up @@ -186,6 +179,19 @@ protected void OnDefaultKeyEntryUpdated()
DefaultKeyEntryUpdated?.Invoke(this, new EventArgs());
}

protected KeyEntryDialogViewModel CreateKeyEntryDialogViewModel()
{
return CreateKeyEntryDialogViewModel(true);
}

protected KeyEntryDialogViewModel CreateKeyEntryDialogViewModel(bool keClone)
{
var model = new KeyEntryDialogViewModel(KeyEntryClass);
model.SetKeyEntry(KeyStore?.GetDefaultKeyEntry(KeyEntryClass, keClone));
model.ShowKeyEntryLabel = (KeyStore?.CanDefineKeyEntryLabel).GetValueOrDefault(true);
return model;
}

public ObservableCollection<SelectableKeyEntryId> Identifiers { get; }

public ObservableCollection<WizardFactory> WizardFactories { get; }
Expand Down
7 changes: 7 additions & 0 deletions KeyManager.Library.UI/Domain/KeyEntryDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public KeyEntryDialogViewModel(KeyEntryClass keClass)

private bool _canChangeFactory = true;
private bool _showKeyMaterials = true;
private bool _showKeyEntryLabel = true;
private bool _allowSubmit = true;
private string _submitButtonText;
private KeyEntry? _keyEntry;
Expand Down Expand Up @@ -100,6 +101,12 @@ public bool ShowKeyMaterials
set => SetProperty(ref _showKeyMaterials, value);
}

public bool ShowKeyEntryLabel
{
get => _showKeyEntryLabel;
set => SetProperty(ref _showKeyEntryLabel, value);
}

public bool AllowSubmit
{
get => _allowSubmit;
Expand Down
3 changes: 2 additions & 1 deletion KeyManager.Library.UI/KeyEntryDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@
<TextBox Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" TextWrapping="Wrap" Text="{Binding KeyEntry.Identifier.Label}" Margin="6"
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.KeyEntryLabelHelper}"
materialDesign:HintAssist.Hint="{x:Static properties:Resources.KeyEntryLabel}"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"/>
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
Visibility="{Binding ShowKeyEntryLabel, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Grid>
</TabItem>
<TabItem Header="{x:Static properties:Resources.KeyVersion}" IsEnabled="{Binding KeyEntry, Converter={StaticResource NullToBooleanConverter}}">
Expand Down
5 changes: 5 additions & 0 deletions KeyManager.Library/KeyStore/KeyStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ protected KeyStore()
/// </summary>
public virtual bool CanReorderKeyEntries => false;

/// <summary>
/// True if key entries can have a custom label, false otherwise.
/// </summary>
public virtual bool CanDefineKeyEntryLabel => true;

/// <summary>
/// Get the supported key entry classes.
/// </summary>
Expand Down

0 comments on commit 8b3839d

Please sign in to comment.