Skip to content

Commit

Permalink
Remove use of CommandGroup/CommandReference
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxhy committed Sep 28, 2023
1 parent 23509c7 commit 29aaa0d
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,12 +246,12 @@ private void SAMLockUnlock()
}
else if (cmd is SAMAV2ISO7816Commands samav2cmd)
{
samav2cmd.lockUnlock(key,SAMUnlockAction, SAMUnlockKeyId, SAMUnlockKeyId, SAMUnlockKey.Version);
samav2cmd.lockUnlock(key, SAMUnlockAction, SAMUnlockKeyId, SAMUnlockKeyId, SAMUnlockKey.Version);
}
}
catch (Exception ex)
{
log.Error("Activate Mifare SAM failed.", ex);
log.Error("Lock/Unlock SAM failed.", ex);
if (SnackbarMessageQueue != null)
SnackbarHelper.EnqueueError(SnackbarMessageQueue, ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public override Window CreateWizardWindow()
{
var masterke = CreateKeyEntry("0", "SAM Master Key");
masterke.SAMProperties!.LockUnlock = true;
masterke.SAMProperties.AuthenticateHost = false;
entries.Add(masterke);
}
if (model.ChangeSAMUnlockKey)
Expand Down
2 changes: 2 additions & 0 deletions KeyManager.Library.UI/Domain/FolderBrowserDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CommunityToolkit.Mvvm.Input;
using Leosac.KeyManager.Library.Plugin.UI.Domain;
using Leosac.WpfApp.Domain;
using MaterialDesignThemes.Wpf;
using System.Collections.ObjectModel;
using System.IO;

Expand All @@ -27,6 +28,7 @@ public FolderBrowserDialogViewModel()
CreateFolderCommand = new RelayCommand<string>(
newFolder =>
{
DialogHost.CloseDialogCommand.Execute(null, null);
if (SelectedDirectory != null && !string.IsNullOrEmpty(newFolder))
{
var newFolderFullpath = Path.Combine(SelectedDirectory.FullName, newFolder);
Expand Down
3 changes: 2 additions & 1 deletion KeyManager.Library.UI/Domain/KeyEntryDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using CommunityToolkit.Mvvm.Input;
using Leosac.KeyManager.Library.KeyStore;
using Leosac.KeyManager.Library.Plugin;
using MaterialDesignThemes.Wpf;
using System.Collections.ObjectModel;

namespace Leosac.KeyManager.Library.UI.Domain
Expand Down Expand Up @@ -41,7 +42,7 @@ public KeyEntryDialogViewModel()
BeforeSubmitCommand = new RelayCommand(
() =>
{
DialogHost.CloseDialogCommand.Execute(null, null);
}, CanSubmit);
}

Expand Down
2 changes: 2 additions & 0 deletions KeyManager.Library.UI/Domain/LinkDialogViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@ public LinkDialogViewModel()
RunLinkCommand = new AsyncRelayCommand(
() =>
{
MaterialDesignThemes.Wpf.DrawerHost.OpenDrawerCommand.Execute(null, null);
AllowImport = false;
return RunLink();
});

RunLinkForImportCommand = new AsyncRelayCommand(
() =>
{
MaterialDesignThemes.Wpf.DrawerHost.OpenDrawerCommand.Execute(null, null);
AllowImport = true;
return RunLink();
});
Expand Down
11 changes: 2 additions & 9 deletions KeyManager.Library.UI/FolderBrowserDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,8 @@
materialDesign:HintAssist.Hint="{x:Static properties:Resources.NewFolderName}"
Style="{StaticResource MaterialDesignFloatingHintTextBox}"/>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Margin="8">
<Button Margin="3" CommandParameter="{Binding NewFolderName}" Content="{x:Static properties:Resources.OK}" IsDefault="True" Style="{StaticResource MaterialDesignFlatButton}">
<Button.Command>
<wpfappdomain:CommandGroup>
<wpfappdomain:CommandReference Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" />
<wpfappdomain:CommandReference Command="{Binding CreateFolderCommand}"/>
</wpfappdomain:CommandGroup>
</Button.Command>
</Button>
<Button Margin="3" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Content="{x:Static properties:Resources.Cancel}" IsCancel="True" Style="{StaticResource MaterialDesignFlatButton}" />
<Button Margin="3" CommandParameter="{Binding NewFolderName}" Content="{x:Static properties:Resources.OK}" IsDefault="True" Style="{StaticResource MaterialDesignFlatButton}" Command="{Binding CreateFolderCommand}" />
<Button Margin="3" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Content="{x:Static properties:Resources.Cancel}" IsCancel="True" Style="{StaticResource MaterialDesignFlatButton}" />
</StackPanel>
</StackPanel>
</materialDesign:DialogHost.DialogContent>
Expand Down
11 changes: 3 additions & 8 deletions KeyManager.Library.UI/KeyEntryDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,9 @@
</StackPanel>
</Grid>
<WrapPanel DockPanel.Dock="Bottom" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,5,5,5">
<Button Width="100" IsDefault="True" Content="{x:Static properties:Resources.OK}" CommandParameter="{Binding KeyEntry}" IsEnabled="{Binding KeyEntry.HasErrors, Mode=OneWay, Converter={StaticResource InvertBooleanConverter}}">
<Button.Command>
<wpfappdomain:CommandGroup>
<wpfappdomain:CommandReference Command="{Binding BeforeSubmitCommand}"/>
<wpfappdomain:CommandReference Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" />
</wpfappdomain:CommandGroup>
</Button.Command>
</Button>
<Button Width="100" IsDefault="True" Content="{x:Static properties:Resources.OK}"
CommandParameter="{Binding KeyEntry}" Command="{Binding BeforeSubmitCommand}"
IsEnabled="{Binding KeyEntry.HasErrors, Mode=OneWay, Converter={StaticResource InvertBooleanConverter}}" />
<Button Width="100" IsCancel="True" Content="{x:Static properties:Resources.Cancel}" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Margin="15,0,0,0"/>
</WrapPanel>
<TabControl>
Expand Down
11 changes: 3 additions & 8 deletions KeyManager.Library.UI/KeyEntryLinkDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,9 @@
<TextBlock DockPanel.Dock="Top" Text="{x:Static properties:Resources.KeyEntryLink}" FontSize="18" Margin="5" />
<TextBlock DockPanel.Dock="Top" Text="{x:Static properties:Resources.KeyEntryLinkHelper}" Margin="5" />
<WrapPanel DockPanel.Dock="Bottom" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="5,20,5,5">
<Button Width="100" Content="{x:Static properties:Resources.Test}" Style="{StaticResource MaterialDesignRaisedLightButton}" CommandParameter="{x:Static Dock.Bottom}" Margin="5">
<Button.Command>
<wpfappdomain:CommandGroup>
<wpfappdomain:CommandReference Command="{x:Static materialDesign:DrawerHost.OpenDrawerCommand}" />
<wpfappdomain:CommandReference Command="{Binding RunLinkCommand}"/>
</wpfappdomain:CommandGroup>
</Button.Command>
</Button>
<Button Width="100" Content="{x:Static properties:Resources.Test}" Style="{StaticResource MaterialDesignRaisedLightButton}"
CommandParameter="{x:Static Dock.Bottom}"
Command="{Binding RunLinkCommand}" Margin="5" />
<Button Width="100" IsDefault="True" Content="{x:Static properties:Resources.Close}" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" CommandParameter="{Binding Link}" Margin="5" />
</WrapPanel>
<Grid>
Expand Down
20 changes: 4 additions & 16 deletions KeyManager.Library.UI/KeyLinkDialog.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,11 @@
Margin="6">
<Button Width="120" Content="{x:Static properties:Resources.ImportNow}"
Style="{StaticResource MaterialDesignOutlinedLightButton}"
CommandParameter="{x:Static Dock.Bottom}">
<Button.Command>
<wpfappdomain:CommandGroup>
<wpfappdomain:CommandReference Command="{x:Static materialDesign:DrawerHost.OpenDrawerCommand}" />
<wpfappdomain:CommandReference Command="{Binding RunLinkForImportCommand}"/>
</wpfappdomain:CommandGroup>
</Button.Command>
</Button>
CommandParameter="{x:Static Dock.Bottom}" Command="{Binding RunLinkForImportCommand}" />
</materialDesign:Badged>
<Button Width="100" Content="{x:Static properties:Resources.Test}" Style="{StaticResource MaterialDesignRaisedLightButton}" CommandParameter="{x:Static Dock.Bottom}" Margin="6">
<Button.Command>
<wpfappdomain:CommandGroup>
<wpfappdomain:CommandReference Command="{x:Static materialDesign:DrawerHost.OpenDrawerCommand}" />
<wpfappdomain:CommandReference Command="{Binding RunLinkCommand}"/>
</wpfappdomain:CommandGroup>
</Button.Command>
</Button>
<Button Width="100" Content="{x:Static properties:Resources.Test}" Style="{StaticResource MaterialDesignRaisedLightButton}"
CommandParameter="{x:Static Dock.Bottom}"
Command="{Binding RunLinkCommand}" Margin="6" />
<Button Width="100" IsDefault="True" Content="{x:Static properties:Resources.Close}" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" CommandParameter="{Binding Link}" Margin="6" />
</WrapPanel>
<Grid>
Expand Down
1 change: 1 addition & 0 deletions KeyManager/Domain/EditKeyStoreControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public EditKeyStoreControlViewModel(ISnackbarMessageQueue snackbarMessageQueue)
SaveFavoriteCommand = new RelayCommand(
() =>
{
Flipper.FlipCommand.Execute(null, null);
var favorites = Favorites.GetSingletonInstance();
if (favorites != null)
{
Expand Down
24 changes: 20 additions & 4 deletions KeyManager/Domain/FavoritesControlViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ public FavoritesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue)
{
RefreshFavorites();
});
OpenFavoriteCommand = new AsyncRelayCommand<Favorite>(
async fav =>
{
DialogHost.CloseDialogCommand.Execute(null, null);
if (KeyStoreCommand != null)
{
await KeyStoreCommand.ExecuteAsync(fav);
}
});
CreateFavoriteCommand = new AsyncRelayCommand(
async () =>
{
Expand All @@ -44,9 +53,14 @@ public FavoritesControlViewModel(ISnackbarMessageQueue snackbarMessageQueue)
RemoveFavoriteCommand = new RelayCommand<Favorite>(
fav =>
{
Favorites?.KeyStores.Remove(fav);
Favorites?.SaveToFile();
log.Info(String.Format("Favorite `{0}` removed.", fav.Name));
if (fav != null)
{
DialogHost.CloseDialogCommand.Execute(null, null);
Favorites?.KeyStores.Remove(fav);
Favorites?.SaveToFile();
log.Info(String.Format("Favorite `{0}` removed.", fav.Name));
}
});
EditFavoriteCommand = new AsyncRelayCommand<Favorite>(
async fav =>
Expand Down Expand Up @@ -76,6 +90,8 @@ public void RefreshFavorites()
public AsyncRelayCommand? CreateFavoriteCommand { get; set; }
public RelayCommand<Favorite>? RemoveFavoriteCommand { get; set; }
public AsyncRelayCommand<Favorite>? EditFavoriteCommand { get; }
public AsyncRelayCommand<object>? KeyStoreCommand { get; set; }
public AsyncRelayCommand<Favorite>? OpenFavoriteCommand { get; }

public AsyncRelayCommand<object>? KeyStoreCommand { private get; set; }
}
}
9 changes: 1 addition & 8 deletions KeyManager/EditKeyStoreControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,7 @@
</materialDesign:Flipper.FrontContent>
<materialDesign:Flipper.BackContent>
<DockPanel LastChildFill="True" Margin="16,8,8,8">
<Button DockPanel.Dock="Bottom" Margin="5" Content="OK" Style="{StaticResource MaterialDesignFlatButton}">
<Button.Command>
<wpfappdomain:CommandGroup>
<wpfappdomain:CommandReference Command="{x:Static materialDesign:Flipper.FlipCommand}" />
<wpfappdomain:CommandReference Command="{Binding SaveFavoriteCommand}" />
</wpfappdomain:CommandGroup>
</Button.Command>
</Button>
<Button DockPanel.Dock="Bottom" Margin="5" Content="OK" Style="{StaticResource MaterialDesignFlatButton}" Command="{Binding SaveFavoriteCommand}" />
<TextBox Text="{Binding Favorite.Name, Mode=TwoWay}"
materialDesign:HintAssist.HelperText="{x:Static properties:Resources.FavoriteNameHelper}"
materialDesign:HintAssist.Hint="{x:Static properties:Resources.FavoriteName}"/>
Expand Down
19 changes: 2 additions & 17 deletions KeyManager/FavoritesControl.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,7 @@
MaxLength="{Binding Properties.SecretMaxLength, Mode=OneWay}"
Visibility="{Binding Properties.StoreSecret, Converter={StaticResource ReverseBoolToVisibleConverter}}"/>
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<Button Margin="0,8,8,0" CommandParameter="{Binding}" Content="{x:Static properties:Resources.OK}" IsDefault="True" Style="{StaticResource MaterialDesignFlatButton}">
<Button.Command>
<wpfappdomain:CommandGroup>
<wpfappdomain:CommandReference Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" />
<wpfappdomain:CommandReference Command="{Binding DataContext.KeyStoreCommand, ElementName=userControl}" />
</wpfappdomain:CommandGroup>
</Button.Command>
</Button>
<Button Margin="0,8,8,0" CommandParameter="{Binding}" Command="{Binding DataContext.OpenFavoriteCommand, ElementName=userControl}" Content="{x:Static properties:Resources.OK}" IsDefault="True" Style="{StaticResource MaterialDesignFlatButton}" />
<Button Margin="0,8,8,0" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Content="{x:Static properties:Resources.Cancel}" IsCancel="True" Style="{StaticResource MaterialDesignFlatButton}" />
</StackPanel>
</StackPanel>
Expand All @@ -81,15 +74,7 @@
<TextBlock Text="{x:Static properties:Resources.DeleteFavoriteConfirmation}" />

<StackPanel HorizontalAlignment="Right" Orientation="Horizontal">
<Button Margin="0,8,8,0" CommandParameter="{Binding}" Content="{x:Static properties:Resources.Confirm}" IsDefault="True" Style="{StaticResource MaterialDesignFlatButton}">
<Button.Command>
<wpfappdomain:CommandGroup>
<wpfappdomain:CommandReference Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" />
<wpfappdomain:CommandReference Command="{Binding DataContext.RemoveFavoriteCommand, ElementName=userControl}"/>
</wpfappdomain:CommandGroup>
</Button.Command>
</Button>

<Button Margin="0,8,8,0" CommandParameter="{Binding}" Command="{Binding DataContext.RemoveFavoriteCommand, ElementName=userControl}" Content="{x:Static properties:Resources.Confirm}" IsDefault="True" Style="{StaticResource MaterialDesignFlatButton}" />
<Button Margin="0,8,8,0" Command="{x:Static materialDesign:DialogHost.CloseDialogCommand}" Content="{x:Static properties:Resources.Cancel}" IsCancel="True" Style="{StaticResource MaterialDesignFlatButton}" />
</StackPanel>
</StackPanel>
Expand Down

0 comments on commit 29aaa0d

Please sign in to comment.