Refactor AddOrSelectDocument method.
MODIFY
WalletWasabi.Gui/Shell/Commands/HelpCommands.cs
WalletWasabi.Gui/Shell/Commands/HelpCommands.cs
@@ -23,7 +23,7 @@ namespace WalletWasabi.Gui.Shell.Commands
commandIconService.GetCompletionKindImage("About"),
ReactiveCommand.Create(() =>
{
- IoC.Get<IShell>().AddOrSelectDocument<AboutViewModel>(new AboutViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new AboutViewModel());
}));
CustomerSupportCommand = new CommandDefinition(
@@ -31,7 +31,7 @@ namespace WalletWasabi.Gui.Shell.Commands
commandIconService.GetCompletionKindImage("CustomerSupport"),
ReactiveCommand.Create(() =>
{
- IoC.Get<IShell>().AddOrSelectDocument<CustomerSupportViewModel>(new CustomerSupportViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new CustomerSupportViewModel());
}));
ReportBugCommand = new CommandDefinition(
@@ -39,7 +39,7 @@ namespace WalletWasabi.Gui.Shell.Commands
commandIconService.GetCompletionKindImage("ReportBug"),
ReactiveCommand.Create(() =>
{
- IoC.Get<IShell>().AddOrSelectDocument<ReportBugViewModel>(new ReportBugViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new ReportBugViewModel());
}));
PrivacyPolicyCommand = new CommandDefinition(
@@ -47,7 +47,7 @@ namespace WalletWasabi.Gui.Shell.Commands
commandIconService.GetCompletionKindImage("PrivacyPolicy"),
ReactiveCommand.Create(() =>
{
- IoC.Get<IShell>().AddOrSelectDocument<PrivacyPolicyViewModel>(new PrivacyPolicyViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new PrivacyPolicyViewModel());
}));
TermsAndConditionsCommand = new CommandDefinition(
@@ -55,7 +55,7 @@ namespace WalletWasabi.Gui.Shell.Commands
commandIconService.GetCompletionKindImage("TermsAndConditions"),
ReactiveCommand.Create(() =>
{
- IoC.Get<IShell>().AddOrSelectDocument<TermsAndConditionsViewModel>(new TermsAndConditionsViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new TermsAndConditionsViewModel());
}));
LegalIssuesCommand = new CommandDefinition(
@@ -63,7 +63,7 @@ namespace WalletWasabi.Gui.Shell.Commands
commandIconService.GetCompletionKindImage("LegalIssues"),
ReactiveCommand.Create(() =>
{
- IoC.Get<IShell>().AddOrSelectDocument<LegalIssuesViewModel>(new LegalIssuesViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new LegalIssuesViewModel());
}));
DevToolsCommand = new CommandDefinition(

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/GenerateWalletViewModel.cs
@@ -97,17 +97,17 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
public void OnTermsClicked()
{
- IoC.Get<IShell>().AddOrSelectDocument<TermsAndConditionsViewModel>(new TermsAndConditionsViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new TermsAndConditionsViewModel());
}
public void OnPrivacyClicked()
{
- IoC.Get<IShell>().AddOrSelectDocument<PrivacyPolicyViewModel>(new PrivacyPolicyViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new PrivacyPolicyViewModel());
}
public void OnLegalClicked()
{
- IoC.Get<IShell>().AddOrSelectDocument<LegalIssuesViewModel>(new LegalIssuesViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new LegalIssuesViewModel());
}
public override void OnCategorySelected()

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/RecoverWalletViewModel.cs
@@ -98,17 +98,17 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
public void OnTermsClicked()
{
- IoC.Get<IShell>().AddOrSelectDocument<TermsAndConditionsViewModel>(new TermsAndConditionsViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new TermsAndConditionsViewModel());
}
public void OnPrivacyClicked()
{
- IoC.Get<IShell>().AddOrSelectDocument<PrivacyPolicyViewModel>(new PrivacyPolicyViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new PrivacyPolicyViewModel());
}
public void OnLegalClicked()
{
- IoC.Get<IShell>().AddOrSelectDocument<LegalIssuesViewModel>(new LegalIssuesViewModel());
+ IoC.Get<IShell>().AddOrSelectDocument(() => new LegalIssuesViewModel());
}
public override void OnCategorySelected()

MODIFY
WalletWasabi.Gui/Utils.cs
WalletWasabi.Gui/Utils.cs
@@ -23,7 +23,7 @@ namespace WalletWasabi.Gui
throw new NotSupportedException("This is impossible.");
}
- public static void AddOrSelectDocument<T>(this IShell me, IDocumentTabViewModel document)
+ public static void AddOrSelectDocument<T>(this IShell me, Func<T> factory) where T : IDocumentTabViewModel
{
IDocumentTabViewModel doc = me.Documents.FirstOrDefault(x => x is T);
if (doc != default)
@@ -32,7 +32,7 @@ namespace WalletWasabi.Gui
}
else
{
- me.AddDocument(document);
+ me.AddDocument(factory());
}
}

Refactor AddOrSelectDocument method.