Cleanup some parts of the UI code
MODIFY
WalletWasabi.Gui/MainWindow.xaml.cs
WalletWasabi.Gui/MainWindow.xaml.cs
@@ -28,19 +28,23 @@ namespace WalletWasabi.Gui
private void OnActivated(object sender, EventArgs e)
{
Activated -= OnActivated;
- if (Directory.Exists(Global.WalletsDir) && Directory.EnumerateFiles(Global.WalletsDir).Any())
+ DisplayWalletManager();
+ }
+
+ private void DisplayWalletManager()
+ {
+ var isAnyWalletAvailable = Directory.Exists(Global.WalletsDir) && Directory.EnumerateFiles(Global.WalletsDir).Any();
+
+ var walletManagerViewModel = new WalletManagerViewModel();
+ IoC.Get<IShell>().AddDocument(walletManagerViewModel);
+
+ if (isAnyWalletAvailable)
{
- // Load
- var document = new WalletManagerViewModel();
- IoC.Get<IShell>().AddDocument(document);
- document.SelectedCategory = document.Categories.First(x => x is LoadWalletViewModel);
+ walletManagerViewModel.SelectLoadWallet();
}
else
{
- // Generate
- var document = new WalletManagerViewModel();
- IoC.Get<IShell>().AddDocument(document);
- document.SelectedCategory = document.Categories.First(x => x is GenerateWalletViewModel);
+ walletManagerViewModel.SelectGenerateWallet();
}
}
}

MODIFY
WalletWasabi.Gui/Shell/Commands/ToolCommands.cs
WalletWasabi.Gui/Shell/Commands/ToolCommands.cs
@@ -21,41 +21,16 @@ namespace WalletWasabi.Gui.Shell.Commands
private void OnWalletManager()
{
+ var isAnyWalletAvailable = Directory.Exists(Global.WalletsDir) && Directory.EnumerateFiles(Global.WalletsDir).Any();
+
+ var walletManagerViewModel = IoC.Get<IShell>().GetOrCreate<WalletManagerViewModel>();
if (Directory.Exists(Global.WalletsDir) && Directory.EnumerateFiles(Global.WalletsDir).Any())
{
- // Load
- IShell tabs = IoC.Get<IShell>();
- IDocumentTabViewModel doc = tabs.Documents.FirstOrDefault(x => x is WalletManagerViewModel);
- if (doc != default)
- {
- var document = doc as WalletManagerViewModel;
- tabs.SelectedDocument = doc;
- document.SelectedCategory = document.Categories.First(x => x is LoadWalletViewModel);
- }
- else
- {
- var document = new WalletManagerViewModel();
- tabs.AddDocument(document);
- document.SelectedCategory = document.Categories.First(x => x is LoadWalletViewModel);
- }
+ walletManagerViewModel.SelectLoadWallet();
}
else
{
- // Generate
- IShell tabs = IoC.Get<IShell>();
- IDocumentTabViewModel doc = tabs.Documents.FirstOrDefault(x => x is WalletManagerViewModel);
- if (doc != default)
- {
- var document = doc as WalletManagerViewModel;
- tabs.SelectedDocument = doc;
- document.SelectedCategory = document.Categories.First(x => x is GenerateWalletViewModel);
- }
- else
- {
- var document = new WalletManagerViewModel();
- tabs.AddDocument(document);
- document.SelectedCategory = document.Categories.First(x => x is GenerateWalletViewModel);
- }
+ walletManagerViewModel.SelectGenerateWallet();
}
}

MODIFY
WalletWasabi.Gui/Shell/Commands/WalletCommands.cs
WalletWasabi.Gui/Shell/Commands/WalletCommands.cs
@@ -24,56 +24,17 @@ namespace WalletWasabi.Gui.Shell.Commands
private void OnGenerateWallet()
{
- IShell tabs = IoC.Get<IShell>();
- IDocumentTabViewModel doc = tabs.Documents.FirstOrDefault(x => x is WalletManagerViewModel);
- if (doc != default)
- {
- var document = doc as WalletManagerViewModel;
- tabs.SelectedDocument = doc;
- document.SelectedCategory = document.Categories.First(x => x is GenerateWalletViewModel);
- }
- else
- {
- var document = new WalletManagerViewModel();
- tabs.AddDocument(document);
- document.SelectedCategory = document.Categories.First(x => x is GenerateWalletViewModel);
- }
+ IoC.Get<IShell>().GetOrCreate<WalletManagerViewModel>().SelectGenerateWallet();
}
private void OnRecoverWallet()
{
- IShell tabs = IoC.Get<IShell>();
- IDocumentTabViewModel doc = tabs.Documents.FirstOrDefault(x => x is WalletManagerViewModel);
- if (doc != default)
- {
- var document = doc as WalletManagerViewModel;
- tabs.SelectedDocument = doc;
- document.SelectedCategory = document.Categories.First(x => x is RecoverWalletViewModel);
- }
- else
- {
- var document = new WalletManagerViewModel();
- tabs.AddDocument(document);
- document.SelectedCategory = document.Categories.First(x => x is RecoverWalletViewModel);
- }
+ IoC.Get<IShell>().GetOrCreate<WalletManagerViewModel>().SelectRecoverWallet();
}
private void OnLoadWallet()
{
- IShell tabs = IoC.Get<IShell>();
- IDocumentTabViewModel doc = tabs.Documents.FirstOrDefault(x => x is WalletManagerViewModel);
- if (doc != default)
- {
- var document = doc as WalletManagerViewModel;
- tabs.SelectedDocument = doc;
- document.SelectedCategory = document.Categories.First(x => x is LoadWalletViewModel);
- }
- else
- {
- var document = new WalletManagerViewModel();
- tabs.AddDocument(document);
- document.SelectedCategory = document.Categories.First(x => x is LoadWalletViewModel);
- }
+ IoC.Get<IShell>().GetOrCreate<WalletManagerViewModel>().SelectLoadWallet();
}
[ExportCommandDefinition("File.GenerateWallet")]

MODIFY
WalletWasabi.Gui/Tabs/WalletManager/WalletManagerViewModel.cs
WalletWasabi.Gui/Tabs/WalletManager/WalletManagerViewModel.cs
@@ -47,6 +47,21 @@ namespace WalletWasabi.Gui.Tabs.WalletManager
set { this.RaiseAndSetIfChanged(ref _selectedCategory, value); }
}
+ public void SelectGenerateWallet()
+ {
+ SelectedCategory = Categories.First(x=>x is GenerateWalletViewModel);
+ }
+
+ public void SelectRecoverWallet()
+ {
+ SelectedCategory = Categories.First(x=>x is RecoverWalletViewModel);
+ }
+
+ public void SelectLoadWallet()
+ {
+ SelectedCategory = Categories.First(x=>x is LoadWalletViewModel);
+ }
+
public ViewModelBase CurrentView
{
get { return _currentView; }

MODIFY
WalletWasabi.Gui/Utils.cs
WalletWasabi.Gui/Utils.cs
@@ -35,5 +35,22 @@ namespace WalletWasabi.Gui
me.AddDocument(document);
}
}
+
+ public static T GetOrCreate<T>(this IShell me) where T : IDocumentTabViewModel, new()
+ {
+ T document = default(T);
+ IDocumentTabViewModel doc = me.Documents.FirstOrDefault(x => x is T);
+ if (doc != default)
+ {
+ document = (T)doc;
+ me.SelectedDocument = doc;
+ }
+ else
+ {
+ document = new T();
+ me.AddDocument(document);
+ }
+ return document;
+ }
}
}

Cleanup some parts of the UI code