mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Added the option to close DB without saving
Changed the way recent files are retrieved Stopped showing the DB Closed exception on suspend Reordering entries works Moved code from infra to application Cleanup
This commit is contained in:
@@ -115,7 +115,7 @@ namespace ModernKeePass.ViewModels
|
||||
private readonly ISettingsProxy _settings;
|
||||
private readonly ResourceHelper _resource;
|
||||
|
||||
public CompositeKeyVm() : this(App.Services.GetService<IMediator>(), App.Services.GetService<ISettingsProxy>()) { }
|
||||
public CompositeKeyVm() : this(App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<ISettingsProxy>()) { }
|
||||
|
||||
public CompositeKeyVm(IMediator mediator, ISettingsProxy settings)
|
||||
{
|
||||
|
@@ -219,7 +219,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public EntryDetailVm() { }
|
||||
|
||||
internal EntryDetailVm(string entryId, bool isNewEntry = false) : this(entryId, App.Services.GetService<IMediator>(), isNewEntry) { }
|
||||
internal EntryDetailVm(string entryId, bool isNewEntry = false) : this(entryId, App.Services.GetRequiredService<IMediator>(), isNewEntry) { }
|
||||
|
||||
public EntryDetailVm(string entryId, IMediator mediator, bool isNewEntry = false)
|
||||
{
|
||||
@@ -232,7 +232,7 @@ namespace ModernKeePass.ViewModels
|
||||
if (isNewEntry) GeneratePassword().GetAwaiter().GetResult();
|
||||
IsSelected = true;
|
||||
|
||||
SaveCommand = new RelayCommand(() => _mediator.Send(new SaveDatabaseCommand()));
|
||||
SaveCommand = new RelayCommand(async () => await _mediator.Send(new SaveDatabaseCommand()));
|
||||
GeneratePasswordCommand = new RelayCommand(async () => await GeneratePassword());
|
||||
UndoDeleteCommand = new RelayCommand(async () => await Move(_parent), () => _parent != null);
|
||||
}
|
||||
|
@@ -16,8 +16,7 @@ using ModernKeePass.Application.Group.Commands.AddGroup;
|
||||
using ModernKeePass.Application.Group.Commands.CreateEntry;
|
||||
using ModernKeePass.Application.Group.Commands.CreateGroup;
|
||||
using ModernKeePass.Application.Group.Commands.DeleteGroup;
|
||||
using ModernKeePass.Application.Group.Commands.InsertEntry;
|
||||
using ModernKeePass.Application.Group.Commands.RemoveEntry;
|
||||
using ModernKeePass.Application.Group.Commands.MoveEntry;
|
||||
using ModernKeePass.Application.Group.Commands.RemoveGroup;
|
||||
using ModernKeePass.Application.Group.Commands.SortEntries;
|
||||
using ModernKeePass.Application.Group.Commands.SortGroups;
|
||||
@@ -33,9 +32,9 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class GroupDetailVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
|
||||
{
|
||||
public ObservableCollection<EntryVm> Entries => new ObservableCollection<EntryVm>(_group.Entries);
|
||||
public ObservableCollection<EntryVm> Entries { get; }
|
||||
|
||||
public ObservableCollection<GroupVm> Groups => new ObservableCollection<GroupVm>(_group.SubGroups);
|
||||
public ObservableCollection<GroupVm> Groups { get; }
|
||||
|
||||
public IEnumerable<EntryVm> SubEntries
|
||||
{
|
||||
@@ -124,7 +123,7 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public GroupDetailVm() {}
|
||||
|
||||
internal GroupDetailVm(string groupId) : this(groupId, App.Services.GetService<IMediator>())
|
||||
internal GroupDetailVm(string groupId) : this(groupId, App.Services.GetRequiredService<IMediator>())
|
||||
{ }
|
||||
|
||||
public GroupDetailVm(string groupId, IMediator mediator, bool isEditMode = false)
|
||||
@@ -141,12 +140,14 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
SaveCommand = new RelayCommand(async () => await _mediator.Send(new SaveDatabaseCommand()));
|
||||
SortEntriesCommand = new RelayCommand(async () =>
|
||||
await SortEntriesAsync().ConfigureAwait(false), () => IsEditMode);
|
||||
await SortEntriesAsync(), () => IsEditMode);
|
||||
SortGroupsCommand = new RelayCommand(async () =>
|
||||
await SortGroupsAsync().ConfigureAwait(false), () => IsEditMode);
|
||||
await SortGroupsAsync(), () => IsEditMode);
|
||||
UndoDeleteCommand = new RelayCommand(async () => await Move(_parent), () => _parent != null);
|
||||
|
||||
Entries = new ObservableCollection<EntryVm>(_group.Entries);
|
||||
Entries.CollectionChanged += Entries_CollectionChanged;
|
||||
Groups = new ObservableCollection<GroupVm>(_group.SubGroups);
|
||||
}
|
||||
|
||||
private async void Entries_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
@@ -156,7 +157,6 @@ namespace ModernKeePass.ViewModels
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
var oldIndex = e.OldStartingIndex;
|
||||
_reorderedEntry = _group.Entries[oldIndex];
|
||||
await _mediator.Send(new RemoveEntryCommand {Entry = _reorderedEntry, ParentGroup = _group});
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
if (_reorderedEntry == null)
|
||||
@@ -166,7 +166,7 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
else
|
||||
{
|
||||
await _mediator.Send(new InsertEntryCommand {Entry = _reorderedEntry, ParentGroup = _group, Index = e.NewStartingIndex});
|
||||
await _mediator.Send(new MoveEntryCommand {Entry = _reorderedEntry, ParentGroup = _group, Index = e.NewStartingIndex});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@@ -38,7 +38,7 @@ namespace ModernKeePass.ViewModels
|
||||
set { SetProperty(ref _isSelected, value); }
|
||||
}
|
||||
|
||||
public RecentItemVm(FileInfo file): this(App.Services.GetService<IRecentProxy>(), file) {}
|
||||
public RecentItemVm(FileInfo file): this(App.Services.GetRequiredService<IRecentProxy>(), file) {}
|
||||
public RecentItemVm(IRecentProxy recent, FileInfo file)
|
||||
{
|
||||
_recent = recent;
|
||||
|
@@ -77,7 +77,7 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsDatabaseVm() : this(App.Services.GetService<IMediator>()) { }
|
||||
public SettingsDatabaseVm() : this(App.Services.GetRequiredService<IMediator>()) { }
|
||||
|
||||
public SettingsDatabaseVm(IMediator mediator)
|
||||
{
|
||||
|
@@ -8,7 +8,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
private readonly ISettingsProxy _settings;
|
||||
|
||||
public SettingsNewVm() : this(App.Services.GetService<ISettingsProxy>())
|
||||
public SettingsNewVm() : this(App.Services.GetRequiredService<ISettingsProxy>())
|
||||
{ }
|
||||
|
||||
public SettingsNewVm(ISettingsProxy settings)
|
||||
|
@@ -7,7 +7,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
private readonly ISettingsProxy _settings;
|
||||
|
||||
public SettingsSaveVm() : this(App.Services.GetService<ISettingsProxy>())
|
||||
public SettingsSaveVm() : this(App.Services.GetRequiredService<ISettingsProxy>())
|
||||
{ }
|
||||
|
||||
public SettingsSaveVm(ISettingsProxy settings)
|
||||
|
@@ -50,7 +50,7 @@ namespace ModernKeePass.ViewModels
|
||||
public MainVm() {}
|
||||
|
||||
internal MainVm(Frame referenceFrame, Frame destinationFrame, FileInfo databaseFile = null) : this(referenceFrame, destinationFrame,
|
||||
App.Services.GetService<IMediator>(), App.Services.GetService<IRecentProxy>(), databaseFile)
|
||||
App.Services.GetRequiredService<IMediator>(), App.Services.GetRequiredService<IRecentProxy>(), databaseFile)
|
||||
{ }
|
||||
|
||||
public MainVm(Frame referenceFrame, Frame destinationFrame, IMediator mediator, IRecentProxy recent, FileInfo databaseFile = null)
|
||||
|
@@ -32,7 +32,7 @@ namespace ModernKeePass.ViewModels
|
||||
private set { SetProperty(ref _path, value); }
|
||||
}
|
||||
|
||||
public OpenVm(): this(App.Services.GetService<IRecentProxy>()) { }
|
||||
public OpenVm(): this(App.Services.GetRequiredService<IRecentProxy>()) { }
|
||||
|
||||
public OpenVm(IRecentProxy recent)
|
||||
{
|
||||
|
@@ -1,5 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ModernKeePass.Application.Common.Interfaces;
|
||||
@@ -41,15 +42,15 @@ namespace ModernKeePass.ViewModels
|
||||
|
||||
public ICommand ClearAllCommand { get; }
|
||||
|
||||
public RecentVm() : this (App.Services.GetService<IRecentProxy>())
|
||||
public RecentVm() : this (App.Services.GetRequiredService<IRecentProxy>())
|
||||
{ }
|
||||
|
||||
public RecentVm(IRecentProxy recent)
|
||||
{
|
||||
_recent = recent;
|
||||
ClearAllCommand = new RelayCommand(ClearAll);
|
||||
|
||||
var recentItems = _recent.GetAll().GetAwaiter().GetResult().Select(r => new RecentItemVm(r));
|
||||
|
||||
var recentItems = _recent.GetAll().Select(r => new RecentItemVm(r));
|
||||
RecentItems = new ObservableCollection<RecentItemVm>(recentItems);
|
||||
if (RecentItems.Count > 0)
|
||||
SelectedItem = RecentItems[0];
|
||||
|
@@ -11,7 +11,7 @@ namespace ModernKeePass.ViewModels
|
||||
public class SaveVm
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
public SaveVm() : this(App.Services.GetService<IMediator>()) { }
|
||||
public SaveVm() : this(App.Services.GetRequiredService<IMediator>()) { }
|
||||
|
||||
public SaveVm(IMediator mediator)
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace ModernKeePass.ViewModels
|
||||
public async Task Save(bool close = true)
|
||||
{
|
||||
await _mediator.Send(new SaveDatabaseCommand());
|
||||
if (close) await _mediator.Send(new CloseDatabaseCommand());
|
||||
if (close) await Close();
|
||||
}
|
||||
|
||||
public async Task Save(StorageFile file)
|
||||
@@ -29,5 +29,10 @@ namespace ModernKeePass.ViewModels
|
||||
var token = StorageApplicationPermissions.FutureAccessList.Add(file);
|
||||
await _mediator.Send(new SaveDatabaseCommand { FilePath = token });
|
||||
}
|
||||
|
||||
public async Task Close()
|
||||
{
|
||||
await _mediator.Send(new CloseDatabaseCommand());
|
||||
}
|
||||
}
|
||||
}
|
@@ -43,7 +43,7 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public SettingsVm() : this(App.Services.GetService<IMediator>()) { }
|
||||
public SettingsVm() : this(App.Services.GetRequiredService<IMediator>()) { }
|
||||
|
||||
public SettingsVm(IMediator mediator)
|
||||
{
|
||||
|
Reference in New Issue
Block a user