Skip to content

Commit

Permalink
CertSelectCommand 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
rkttu committed Dec 20, 2023
1 parent a9a4386 commit 7752890
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 38 deletions.
9 changes: 6 additions & 3 deletions src/TableCloth/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ private IServiceProvider ConfigureServices()
services.AddSingleton<LaunchSandboxCommand>();
services.AddSingleton<CreateShortcutCommand>();
services.AddSingleton<CopyCommandLineCommand>();
services.AddSingleton<CertSelectCommand>();
services.AddSingleton<AppRestartCommand>();
services.AddSingleton<AboutThisAppCommand>();
services.AddSingleton<MainWindowLoadedCommand>();
Expand All @@ -143,7 +144,7 @@ private IServiceProvider ConfigureServices()
services.AddTransient<CertSelectWindowViewModel>();
services.AddTransient<CertSelectWindow>();

services.AddSingleton<MainWindowViewModel>(provider =>
services.AddTransient<MainWindowViewModel>(provider =>
{
return new MainWindowViewModel(
appUserInterface: provider.GetRequiredService<AppUserInterface>(),
Expand All @@ -153,7 +154,8 @@ private IServiceProvider ConfigureServices()
launchSandboxCommand: provider.GetRequiredService<LaunchSandboxCommand>(),
createShortcutCommand: provider.GetRequiredService<CreateShortcutCommand>(),
appRestartCommand: provider.GetRequiredService<AppRestartCommand>(),
aboutThisAppCommand: provider.GetRequiredService<AboutThisAppCommand>());
aboutThisAppCommand: provider.GetRequiredService<AboutThisAppCommand>(),
certSelectCommand: provider.GetRequiredService<CertSelectCommand>());
});
services.AddSingleton<MainWindow>();

Expand All @@ -178,7 +180,8 @@ private IServiceProvider ConfigureServices()
appRestartManager: provider.GetRequiredService<AppRestartManager>(),
launchSandboxCommand: provider.GetRequiredService<LaunchSandboxCommand>(),
createShortcutCommand: provider.GetRequiredService<CreateShortcutCommand>(),
copyCommandLineCommand: provider.GetRequiredService<CopyCommandLineCommand>());
copyCommandLineCommand: provider.GetRequiredService<CopyCommandLineCommand>(),
certSelectCommand: provider.GetRequiredService<CertSelectCommand>());
});
services.AddTransient<DetailPage>();

Expand Down
37 changes: 37 additions & 0 deletions src/TableCloth/Commands/CertSelectCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using TableCloth.Components;
using TableCloth.Contracts;

namespace TableCloth.Commands
{
public sealed class CertSelectCommand : CommandBase
{
public CertSelectCommand(
AppUserInterface appUserInterface)
{
_appUserInterface = appUserInterface;
}

private readonly AppUserInterface _appUserInterface;

public AppUserInterface AppUserInterface
=> _appUserInterface;

public override void Execute(object? parameter)
{
var viewModel = parameter as ICertSelect;

if (viewModel == null)
throw new ArgumentException(nameof(parameter));

var certSelectWindow = _appUserInterface.CreateWindow<CertSelectWindow>();
var response = certSelectWindow.ShowDialog();

if (!response.HasValue || !response.Value)
return;

if (certSelectWindow.ViewModel.SelectedCertPair != null)
viewModel.SelectedCertFile = certSelectWindow.ViewModel.SelectedCertPair;
}
}
}
9 changes: 9 additions & 0 deletions src/TableCloth/Contracts/ICertSelect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using TableCloth.Models.Configuration;

namespace TableCloth.Contracts
{
public interface ICertSelect
{
X509CertPair? SelectedCertFile { get; set; }
}
}
6 changes: 5 additions & 1 deletion src/TableCloth/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,11 @@
</Grid.RowDefinitions>
<WrapPanel Grid.Row="0" VerticalAlignment="Center" Orientation="Horizontal">
<CheckBox VerticalAlignment="Center" Content="{StaticResource MainWindow_MapNpkiCertButtonText}" IsChecked="{Binding Path='MapNpkiCert'}" />
<Button x:Name="BrowseButton" VerticalAlignment="Center" Margin="10 0 0 0" Content="{StaticResource MainWindow_BrowseButtonText}" Click="BrowseButton_Click" IsEnabled="{Binding Path='MapNpkiCert'}" />
<Button x:Name="BrowseButton" VerticalAlignment="Center" Margin="10 0 0 0" Content="{StaticResource MainWindow_BrowseButtonText}" Command="{Binding CertSelectCommand}" IsEnabled="{Binding Path='MapNpkiCert'}">
<Button.CommandParameter>
<Binding Path="DataContext" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type Window}}" />
</Button.CommandParameter>
</Button>
</WrapPanel>
<Label Grid.Row="1" VerticalAlignment="Stretch" Margin="0 5 0 0" Content="{Binding Path='SelectedCertFile'}" IsEnabled="{Binding Path='MapNpkiCert'}">
</Label>
Expand Down
15 changes: 0 additions & 15 deletions src/TableCloth/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,6 @@ public MainWindow(MainWindowViewModel viewModel)
public MainWindowViewModel ViewModel
=> (MainWindowViewModel)DataContext;

private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
var certSelectWindow = ViewModel.AppUserInterface.CreateWindow<CertSelectWindow>(window =>
{
window.Owner = this;
});
var response = certSelectWindow.ShowDialog();

if (!response.HasValue || !response.Value)
return;

if (certSelectWindow.ViewModel.SelectedCertPair != null)
ViewModel.SelectedCertFile = certSelectWindow.ViewModel.SelectedCertPair;
}

private void SiteList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var listBox = (ListBox)e.Source;
Expand Down
6 changes: 5 additions & 1 deletion src/TableCloth/Pages/DetailPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@
</Grid.RowDefinitions>
<WrapPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center" Orientation="Horizontal">
<CheckBox VerticalAlignment="Center" Content="{StaticResource DetailPage_MapNpkiCertButtonText}" IsChecked="{Binding Path='MapNpkiCert'}" />
<Button x:Name="BrowseButton" VerticalAlignment="Center" Margin="10 0 0 0" Content="{StaticResource DetailPage_BrowseButtonText}" Click="BrowseButton_Click" IsEnabled="{Binding Path='MapNpkiCert'}" />
<Button x:Name="BrowseButton" VerticalAlignment="Center" Margin="10 0 0 0" Content="{StaticResource DetailPage_BrowseButtonText}" Command="{Binding CertSelectCommand}" IsEnabled="{Binding Path='MapNpkiCert'}">
<Button.CommandParameter>
<Binding Path="DataContext" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type Page}}" />
</Button.CommandParameter>
</Button>
</WrapPanel>
<Label Grid.Row="1" Grid.Column="1" VerticalAlignment="Stretch" Margin="0 5 0 0" Content="{Binding Path='SelectedCertFile'}" IsEnabled="{Binding Path='MapNpkiCert'}">
</Label>
Expand Down
15 changes: 1 addition & 14 deletions src/TableCloth/Pages/DetailPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,20 +159,7 @@ private void ViewModel_PropertyChanged(object? sender, PropertyChangedEventArgs

private void GoBackButton_Click(object sender, RoutedEventArgs e)
{
if (NavigationService.CanGoBack)
NavigationService.GoBack();
}

private void BrowseButton_Click(object sender, RoutedEventArgs e)
{
var certSelectWindow = ViewModel.AppUserInterface.CreateWindow<CertSelectWindow>();
var response = certSelectWindow.ShowDialog();

if (!response.HasValue || !response.Value)
return;

if (certSelectWindow.ViewModel.SelectedCertPair != null)
ViewModel.SelectedCertFile = certSelectWindow.ViewModel.SelectedCertPair;
ViewModel.NavigationService.GoBack();
}

private void Hyperlink_Click(object sender, RoutedEventArgs e)
Expand Down
10 changes: 8 additions & 2 deletions src/TableCloth/ViewModels/DetailPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace TableCloth.ViewModels
{
public sealed class DetailPageViewModel : ViewModelBase, IPageExtraArgument
public sealed class DetailPageViewModel : ViewModelBase, IPageExtraArgument, ICertSelect
{
[Obsolete("This constructor should be used only in design time context.")]
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
Expand All @@ -28,7 +28,8 @@ public DetailPageViewModel(
AppRestartManager appRestartManager,
LaunchSandboxCommand launchSandboxCommand,
CreateShortcutCommand createShortcutCommand,
CopyCommandLineCommand copyCommandLineCommand)
CopyCommandLineCommand copyCommandLineCommand,
CertSelectCommand certSelectCommand)
{
_appUserInterface = appUserInterface;
_navigationService = navigationService;
Expand All @@ -39,6 +40,7 @@ public DetailPageViewModel(
_launchSandboxCommand = launchSandboxCommand;
_createShortcutCommand = createShortcutCommand;
_copyCommandLineCommand = copyCommandLineCommand;
_certSelectCommand = certSelectCommand;
}

private readonly AppUserInterface _appUserInterface;
Expand All @@ -50,6 +52,7 @@ public DetailPageViewModel(
private readonly LaunchSandboxCommand _launchSandboxCommand;
private readonly CreateShortcutCommand _createShortcutCommand;
private readonly CopyCommandLineCommand _copyCommandLineCommand;
private readonly CertSelectCommand _certSelectCommand;

private CatalogInternetService? _selectedService;
private bool _mapNpkiCert;
Expand Down Expand Up @@ -100,6 +103,9 @@ public CreateShortcutCommand CreateShortcutCommand
public CopyCommandLineCommand CopyCommandLineCommand
=> _copyCommandLineCommand;

public CertSelectCommand CertSelectCommand
=> _certSelectCommand;

public string? Id
=> _selectedService?.Id;

Expand Down
11 changes: 9 additions & 2 deletions src/TableCloth/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
using System.Windows.Data;
using TableCloth.Commands;
using TableCloth.Components;
using TableCloth.Contracts;
using TableCloth.Models.Catalog;
using TableCloth.Models.Configuration;

namespace TableCloth.ViewModels
{
public class MainWindowViewModel : ViewModelBase
public class MainWindowViewModel : ViewModelBase, ICertSelect
{
[Obsolete("This constructor should be used only in design time context.")]
#pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
Expand All @@ -24,7 +25,8 @@ public MainWindowViewModel(
LaunchSandboxCommand launchSandboxCommand,
CreateShortcutCommand createShortcutCommand,
AppRestartCommand appRestartCommand,
AboutThisAppCommand aboutThisAppCommand)
AboutThisAppCommand aboutThisAppCommand,
CertSelectCommand certSelectCommand)
{
_appUserInterface = appUserInterface;
_catalogDeserializer = catalogDeserializer;
Expand All @@ -34,6 +36,7 @@ public MainWindowViewModel(
_createShortcutCommand = createShortcutCommand;
_appRestartCommand = appRestartCommand;
_aboutThisAppCommand = aboutThisAppCommand;
_certSelectCommand = certSelectCommand;

try
{
Expand Down Expand Up @@ -67,6 +70,7 @@ public MainWindowViewModel(
private readonly CreateShortcutCommand _createShortcutCommand;
private readonly AppRestartCommand _appRestartCommand;
private readonly AboutThisAppCommand _aboutThisAppCommand;
private readonly CertSelectCommand _certSelectCommand;

private string _filterText = string.Empty;
private bool _mapNpkiCert;
Expand Down Expand Up @@ -107,6 +111,9 @@ public AppRestartCommand AppRestartCommand
public AboutThisAppCommand AboutThisAppCommand
=> _aboutThisAppCommand;

public CertSelectCommand CertSelectCommand
=> _certSelectCommand;

public string FilterText
{
get => _filterText;
Expand Down

0 comments on commit 7752890

Please sign in to comment.