Skip to content

Commit

Permalink
Use StorageProvider to set directories
Browse files Browse the repository at this point in the history
  • Loading branch information
Coding-Enthusiast committed May 8, 2024
1 parent bd5c487 commit 326c906
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
1 change: 1 addition & 0 deletions Src/Denovo/App.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public override void OnFrameworkInitializationCompleted()
DataContext = vm
};
vm.Clipboard = desktop.MainWindow.Clipboard;
vm.StorageProvider = desktop.MainWindow.StorageProvider;
}

base.OnFrameworkInitializationCompleted();
Expand Down
20 changes: 11 additions & 9 deletions Src/Denovo/ViewModels/ConfigurationViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
// file LICENCE or http://www.opensource.org/licenses/mit-license.php.

using Autarkysoft.Bitcoin;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.ApplicationLifetimes;
using Avalonia.Platform.Storage;
using Denovo.Models;
using Denovo.MVVM;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;

namespace Denovo.ViewModels
{
Expand Down Expand Up @@ -77,16 +76,19 @@ public bool HasPendingChanges
}

public bool IsChanged { get; private set; }

public IStorageProvider StorageProvider { get; set; }

public async void SetBlockchainDir()
{
var open = new OpenFolderDialog();
var lf = (IClassicDesktopStyleApplicationLifetime)Application.Current.ApplicationLifetime;
string dir = await open.ShowAsync(lf.MainWindow);
if (!string.IsNullOrEmpty(dir))
FolderPickerOpenOptions opts = new()
{
AllowMultiple = false,
Title = "Blockchain directory"
};
IReadOnlyList<IStorageFolder> dir = await StorageProvider.OpenFolderPickerAsync(opts);
if (dir != null && dir.Count > 0)
{
Config.BlockchainPath = dir;
Config.BlockchainPath= dir.ElementAt(0).Path.LocalPath;
}
}

Expand Down
9 changes: 7 additions & 2 deletions Src/Denovo/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Autarkysoft.Bitcoin.P2PNetwork;
using Autarkysoft.Bitcoin.P2PNetwork.Messages;
using Avalonia.Input.Platform;
using Avalonia.Platform.Storage;
using Denovo.Models;
using Denovo.MVVM;
using Denovo.Services;
Expand Down Expand Up @@ -56,6 +57,7 @@ public MainWindowViewModel(NetworkType network)
public NodePool AllNodes { get; set; }

public IClipboard Clipboard { get; set; }
public IStorageProvider StorageProvider { get; set; }
public IWindowManager WinMan { get; set; }
public IDenovoFileManager FileMan { get; set; }
public bool IsInitialized { get; }
Expand Down Expand Up @@ -112,7 +114,10 @@ public async void OpenConfig()
config = new Configuration(Network) { IsDefault = true };
}

ConfigurationViewModel vm = new(config);
ConfigurationViewModel vm = new(config)
{
StorageProvider = StorageProvider
};
await WinMan.ShowDialog(vm);

if (vm.IsChanged)
Expand Down Expand Up @@ -214,7 +219,7 @@ public string Result
public bool CanDisconnect() => SelectedNode != null;
public void Disconnect()
{
if (!(SelectedNode is null))
if (SelectedNode is not null)
{
AllNodes.Remove(SelectedNode);
}
Expand Down

0 comments on commit 326c906

Please sign in to comment.