Skip to content

Commit 8b3839d

Browse files
committed
Add key store property to automatically hide/show key entry label if supported
1 parent 14157f1 commit 8b3839d

File tree

5 files changed

+38
-17
lines changed

5 files changed

+38
-17
lines changed

KeyManager.Library.KeyStore.NXP_SAM/SAMKeyStore.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,14 @@ public SAMKeyStoreProperties GetSAMProperties()
2323
return p ?? throw new KeyStoreException("Missing SAM key store properties.");
2424
}
2525

26-
public override string Name => "NXP SAM AV2";
26+
public override string Name => "NXP SAM AV2/AV3";
2727

2828
public override bool CanCreateKeyEntries => false;
2929

3030
public override bool CanDeleteKeyEntries => false;
3131

32+
public override bool CanDefineKeyEntryLabel => false;
33+
3234
public override IEnumerable<KeyEntryClass> SupportedClasses
3335
{
3436
get => new KeyEntryClass[] { KeyEntryClass.Symmetric };

KeyManager.Library.UI/Domain/KeyEntriesControlViewModel.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ public KeyEntriesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue, Ke
2626
CreateKeyEntryCommand = new AsyncRelayCommand(
2727
async () =>
2828
{
29-
var model = new KeyEntryDialogViewModel(KeyEntryClass);
30-
model.SetKeyEntry(KeyStore?.GetDefaultKeyEntry(KeyEntryClass));
29+
var model = CreateKeyEntryDialogViewModel();
3130
var dialog = new KeyEntryDialog
3231
{
3332
DataContext = model
@@ -38,11 +37,8 @@ public KeyEntriesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue, Ke
3837
GenerateKeyEntryCommand = new AsyncRelayCommand(
3938
async () =>
4039
{
41-
var model = new KeyEntryDialogViewModel(KeyEntryClass)
42-
{
43-
ShowKeyMaterials = false
44-
};
45-
model.SetKeyEntry(KeyStore?.GetDefaultKeyEntry(KeyEntryClass));
40+
var model = CreateKeyEntryDialogViewModel();
41+
model.ShowKeyMaterials = false;
4642
var dialog = new KeyEntryDialog
4743
{
4844
DataContext = model
@@ -53,8 +49,7 @@ public KeyEntriesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue, Ke
5349
EditDefaultKeyEntryCommand = new AsyncRelayCommand(
5450
async () =>
5551
{
56-
var model = new KeyEntryDialogViewModel(KeyEntryClass);
57-
model.SetKeyEntry(KeyStore?.GetDefaultKeyEntry(KeyEntryClass, false));
52+
var model = CreateKeyEntryDialogViewModel(false);
5853
var dialog = new KeyEntryDialog
5954
{
6055
DataContext = model
@@ -72,12 +67,10 @@ public KeyEntriesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue, Ke
7267
{
7368
if (KeyStore != null && identifier?.KeyEntryId != null)
7469
{
75-
var model = new KeyEntryDialogViewModel(KeyEntryClass)
76-
{
77-
CanChangeFactory = false,
78-
AllowSubmit = KeyStore.CanUpdateKeyEntries,
79-
SubmitButtonText = Properties.Resources.Update
80-
};
70+
var model = CreateKeyEntryDialogViewModel();
71+
model.CanChangeFactory = false;
72+
model.AllowSubmit = KeyStore.CanUpdateKeyEntries;
73+
model.SubmitButtonText = Properties.Resources.Update;
8174
model.SetKeyEntry(await KeyStore.Get(identifier.KeyEntryId, KeyEntryClass));
8275
var dialog = new KeyEntryDialog
8376
{
@@ -186,6 +179,19 @@ protected void OnDefaultKeyEntryUpdated()
186179
DefaultKeyEntryUpdated?.Invoke(this, new EventArgs());
187180
}
188181

182+
protected KeyEntryDialogViewModel CreateKeyEntryDialogViewModel()
183+
{
184+
return CreateKeyEntryDialogViewModel(true);
185+
}
186+
187+
protected KeyEntryDialogViewModel CreateKeyEntryDialogViewModel(bool keClone)
188+
{
189+
var model = new KeyEntryDialogViewModel(KeyEntryClass);
190+
model.SetKeyEntry(KeyStore?.GetDefaultKeyEntry(KeyEntryClass, keClone));
191+
model.ShowKeyEntryLabel = (KeyStore?.CanDefineKeyEntryLabel).GetValueOrDefault(true);
192+
return model;
193+
}
194+
189195
public ObservableCollection<SelectableKeyEntryId> Identifiers { get; }
190196

191197
public ObservableCollection<WizardFactory> WizardFactories { get; }

KeyManager.Library.UI/Domain/KeyEntryDialogViewModel.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public KeyEntryDialogViewModel(KeyEntryClass keClass)
5050

5151
private bool _canChangeFactory = true;
5252
private bool _showKeyMaterials = true;
53+
private bool _showKeyEntryLabel = true;
5354
private bool _allowSubmit = true;
5455
private string _submitButtonText;
5556
private KeyEntry? _keyEntry;
@@ -100,6 +101,12 @@ public bool ShowKeyMaterials
100101
set => SetProperty(ref _showKeyMaterials, value);
101102
}
102103

104+
public bool ShowKeyEntryLabel
105+
{
106+
get => _showKeyEntryLabel;
107+
set => SetProperty(ref _showKeyEntryLabel, value);
108+
}
109+
103110
public bool AllowSubmit
104111
{
105112
get => _allowSubmit;

KeyManager.Library.UI/KeyEntryDialog.xaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@
9595
<TextBox Grid.Row="3" HorizontalAlignment="Stretch" VerticalAlignment="Center" TextWrapping="Wrap" Text="{Binding KeyEntry.Identifier.Label}" Margin="6"
9696
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.KeyEntryLabelHelper}"
9797
materialDesign:HintAssist.Hint="{x:Static properties:Resources.KeyEntryLabel}"
98-
Style="{StaticResource MaterialDesignFloatingHintTextBox}"/>
98+
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
99+
Visibility="{Binding ShowKeyEntryLabel, Converter={StaticResource BooleanToVisibilityConverter}}"/>
99100
</Grid>
100101
</TabItem>
101102
<TabItem Header="{x:Static properties:Resources.KeyVersion}" IsEnabled="{Binding KeyEntry, Converter={StaticResource NullToBooleanConverter}}">

KeyManager.Library/KeyStore/KeyStore.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ protected KeyStore()
4747
/// </summary>
4848
public virtual bool CanReorderKeyEntries => false;
4949

50+
/// <summary>
51+
/// True if key entries can have a custom label, false otherwise.
52+
/// </summary>
53+
public virtual bool CanDefineKeyEntryLabel => true;
54+
5055
/// <summary>
5156
/// Get the supported key entry classes.
5257
/// </summary>

0 commit comments

Comments
 (0)