mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Build hierarchy instead of using Automapper
Add entities before removing them
This commit is contained in:
@@ -44,7 +44,7 @@ namespace ModernKeePass.Actions
|
||||
public object Execute(object sender, object parameter)
|
||||
{
|
||||
var resource = new ResourcesService();
|
||||
var type = Entity is GroupVm ? "Group" : "Entry";
|
||||
var type = Entity is GroupDetailVm ? "Group" : "Entry";
|
||||
var isRecycleOnDelete = _mediator.Send(new GetDatabaseQuery()).GetAwaiter().GetResult().IsRecycleBinEnabled;
|
||||
|
||||
var message = isRecycleOnDelete
|
||||
|
@@ -22,7 +22,7 @@ using ModernKeePass.Interfaces;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class EntryVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
|
||||
public class EntryDetailVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
|
||||
{
|
||||
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
|
||||
public bool HasExpired => HasExpirationDate && ExpiryDate < DateTime.Now;
|
||||
@@ -68,11 +68,7 @@ namespace ModernKeePass.ViewModels
|
||||
public string UserName
|
||||
{
|
||||
get { return _entry.Username; }
|
||||
set
|
||||
{
|
||||
_mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = nameof(UserName), FieldValue = value }).Wait();
|
||||
_entry.Username = value;
|
||||
}
|
||||
set { _entry.Username = value; }
|
||||
}
|
||||
|
||||
public string Password
|
||||
@@ -225,11 +221,11 @@ namespace ModernKeePass.ViewModels
|
||||
private double _passwordLength = 25;
|
||||
private bool _isVisible = true;
|
||||
|
||||
public EntryVm() { }
|
||||
public EntryDetailVm() { }
|
||||
|
||||
internal EntryVm(Application.Entry.Models.EntryVm entry, bool isNewEntry = false) : this(entry, App.Mediator, isNewEntry) { }
|
||||
internal EntryDetailVm(Application.Entry.Models.EntryVm entry, bool isNewEntry = false) : this(entry, App.Mediator, isNewEntry) { }
|
||||
|
||||
public EntryVm(Application.Entry.Models.EntryVm entry, IMediator mediator, bool isNewEntry = false)
|
||||
public EntryDetailVm(Application.Entry.Models.EntryVm entry, IMediator mediator, bool isNewEntry = false)
|
||||
{
|
||||
_entry = entry;
|
||||
_mediator = mediator;
|
||||
@@ -263,19 +259,18 @@ namespace ModernKeePass.ViewModels
|
||||
public async Task MarkForDelete(string recycleBinTitle)
|
||||
{
|
||||
if (_database.IsRecycleBinEnabled && _database.RecycleBin == null)
|
||||
await _mediator.Send(new CreateGroupCommand { ParentGroup = _database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
|
||||
await Move(_database.IsRecycleBinEnabled && _entry.ParentGroup == _database.RecycleBin ? _database.RecycleBin : null);
|
||||
_database.RecycleBin = await _mediator.Send(new CreateGroupCommand { ParentGroup = _database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
|
||||
await Move(_database.IsRecycleBinEnabled && _entry.ParentGroup != _database.RecycleBin ? _database.RecycleBin : null);
|
||||
}
|
||||
|
||||
public async Task Move(Application.Group.Models.GroupVm destination)
|
||||
{
|
||||
await _mediator.Send(new AddEntryCommand { ParentGroup = destination, Entry = _entry });
|
||||
await _mediator.Send(new RemoveEntryCommand { ParentGroup = _entry.ParentGroup, Entry = _entry });
|
||||
if (destination == null)
|
||||
{
|
||||
await _mediator.Send(new DeleteEntryCommand { Entry = _entry });
|
||||
return;
|
||||
}
|
||||
await _mediator.Send(new AddEntryCommand { ParentGroup = destination, Entry = _entry });
|
||||
}
|
||||
|
||||
public async Task CommitDelete()
|
||||
@@ -287,5 +282,10 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
return _entry;
|
||||
}
|
||||
|
||||
public async Task SetFieldValue(string fieldName, object value)
|
||||
{
|
||||
await _mediator.Send(new SetFieldValueCommand { EntryId = Id, FieldName = fieldName, FieldValue = value });
|
||||
}
|
||||
}
|
||||
}
|
@@ -26,7 +26,7 @@ using ModernKeePass.Interfaces;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class GroupVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
|
||||
public class GroupDetailVm : NotifyPropertyChangedBase, IVmEntity, ISelectableModel
|
||||
{
|
||||
public ObservableCollection<Application.Entry.Models.EntryVm> Entries => new ObservableCollection<Application.Entry.Models.EntryVm>(_group.Entries);
|
||||
|
||||
@@ -47,7 +47,6 @@ namespace ModernKeePass.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsNotRoot => _database.RootGroup != _group;
|
||||
|
||||
public bool ShowRestore => IsNotRoot && _database.RecycleBin != _group;
|
||||
@@ -117,12 +116,12 @@ namespace ModernKeePass.ViewModels
|
||||
private Application.Entry.Models.EntryVm _reorderedEntry;
|
||||
private bool _isMenuClosed = true;
|
||||
|
||||
public GroupVm() {}
|
||||
public GroupDetailVm() {}
|
||||
|
||||
internal GroupVm(Application.Group.Models.GroupVm group) : this(group, App.Mediator)
|
||||
internal GroupDetailVm(Application.Group.Models.GroupVm group) : this(group, App.Mediator)
|
||||
{ }
|
||||
|
||||
public GroupVm(Application.Group.Models.GroupVm group, IMediator mediator, bool isEditMode = false)
|
||||
public GroupDetailVm(Application.Group.Models.GroupVm group, IMediator mediator, bool isEditMode = false)
|
||||
{
|
||||
_group = group;
|
||||
_mediator = mediator;
|
||||
@@ -151,7 +150,7 @@ namespace ModernKeePass.ViewModels
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
if (_reorderedEntry == null)
|
||||
{
|
||||
var entry = ((EntryVm) e.NewItems[0]).GetEntry();
|
||||
var entry = ((EntryDetailVm) e.NewItems[0]).GetEntry();
|
||||
await _mediator.Send(new AddEntryCommand {Entry = entry, ParentGroup = _group});
|
||||
}
|
||||
else
|
||||
@@ -175,20 +174,19 @@ namespace ModernKeePass.ViewModels
|
||||
public async Task MarkForDelete(string recycleBinTitle)
|
||||
{
|
||||
if (_database.IsRecycleBinEnabled && _database.RecycleBin == null)
|
||||
await _mediator.Send(new CreateGroupCommand {ParentGroup = _database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
|
||||
_database.RecycleBin = await _mediator.Send(new CreateGroupCommand {ParentGroup = _database.RootGroup, IsRecycleBin = true, Name = recycleBinTitle});
|
||||
await Move(_database.IsRecycleBinEnabled && !IsSelected ? _database.RecycleBin : null);
|
||||
((RelayCommand)UndoDeleteCommand).RaiseCanExecuteChanged();
|
||||
}
|
||||
|
||||
public async Task Move(Application.Group.Models.GroupVm destination)
|
||||
{
|
||||
await _mediator.Send(new AddGroupCommand {ParentGroup = destination, Group = _group});
|
||||
await _mediator.Send(new RemoveGroupCommand {ParentGroup = _group.ParentGroup, Group = _group});
|
||||
if (destination == null)
|
||||
{
|
||||
await _mediator.Send(new DeleteGroupCommand { Group = _group });
|
||||
return;
|
||||
}
|
||||
await _mediator.Send(new AddGroupCommand {ParentGroup = destination, Group = _group});
|
||||
}
|
||||
|
||||
public async Task CommitDelete()
|
@@ -23,7 +23,7 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
private readonly IMediator _mediator;
|
||||
private readonly DatabaseVm _database;
|
||||
private GroupVm _selectedItem;
|
||||
private GroupDetailVm _selectedItem;
|
||||
|
||||
public bool HasRecycleBin
|
||||
{
|
||||
@@ -104,7 +104,7 @@ namespace ModernKeePass.ViewModels
|
||||
_selectedItem.IsSelected = false;
|
||||
}
|
||||
|
||||
SetProperty(ref _selectedItem, (GroupVm)value);
|
||||
SetProperty(ref _selectedItem, (GroupDetailVm)value);
|
||||
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
|
@@ -372,7 +372,7 @@
|
||||
</Style>
|
||||
</Page.Resources>
|
||||
<Page.DataContext>
|
||||
<viewModels:EntryVm />
|
||||
<viewModels:EntryDetailVm />
|
||||
</Page.DataContext>
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<Grid.ChildrenTransitions>
|
||||
@@ -410,7 +410,7 @@
|
||||
</Style>
|
||||
</StackPanel.Resources>
|
||||
<TextBlock x:Uid="EntryLogin" />
|
||||
<local:TextBoxWithButton x:Uid="LoginTextBox" Text="{Binding UserName, Mode=TwoWay}" Style="{StaticResource EntryTextBoxWithButtonStyle}" ButtonSymbol="" IsEnabled="{Binding IsSelected}">
|
||||
<local:TextBoxWithButton x:Uid="LoginTextBox" Text="{Binding UserName, Mode=TwoWay}" LostFocus="Username_OnLostFocus" Style="{StaticResource EntryTextBoxWithButtonStyle}" ButtonSymbol="" IsEnabled="{Binding IsSelected}">
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="ButtonClick">
|
||||
<actions:ClipboardAction Text="{Binding UserName}" />
|
||||
|
@@ -14,7 +14,7 @@ namespace ModernKeePass.Views
|
||||
/// </summary>
|
||||
public sealed partial class EntryDetailPage
|
||||
{
|
||||
public EntryVm Model => (EntryVm) DataContext;
|
||||
public EntryDetailVm Model => (EntryDetailVm) DataContext;
|
||||
|
||||
/// <summary>
|
||||
/// NavigationHelper est utilisé sur chaque page pour faciliter la navigation et
|
||||
@@ -45,7 +45,7 @@ namespace ModernKeePass.Views
|
||||
/*if (!(e.Parameter is EntryVm)) return;
|
||||
DataContext = (EntryVm)e.Parameter;*/
|
||||
var args = e.Parameter as Application.Entry.Models.EntryVm;
|
||||
if (args != null) DataContext = new EntryVm(args);
|
||||
if (args != null) DataContext = new EntryDetailVm(args);
|
||||
}
|
||||
|
||||
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||
@@ -75,5 +75,10 @@ namespace ModernKeePass.Views
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private async void Username_OnLostFocus(object sender, RoutedEventArgs e)
|
||||
{
|
||||
await Model.SetFieldValue(nameof(Model.UserName), ((TextBox) sender).Text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -19,7 +19,7 @@
|
||||
<converters:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter"/>
|
||||
</Page.Resources>
|
||||
<Page.DataContext>
|
||||
<viewModels:GroupVm />
|
||||
<viewModels:GroupDetailVm />
|
||||
</Page.DataContext>
|
||||
<Grid>
|
||||
<Grid.Resources>
|
||||
|
@@ -25,7 +25,7 @@ namespace ModernKeePass.Views
|
||||
/// process lifetime management
|
||||
/// </summary>
|
||||
public NavigationHelper NavigationHelper { get; }
|
||||
public GroupVm Model => (GroupVm)DataContext;
|
||||
public GroupDetailVm Model => (GroupDetailVm)DataContext;
|
||||
|
||||
public GroupDetailPage()
|
||||
{
|
||||
@@ -50,12 +50,12 @@ namespace ModernKeePass.Views
|
||||
|
||||
var args = e.Parameter as PasswordEventArgs;
|
||||
if (args != null)
|
||||
DataContext = new GroupVm(args.RootGroup);
|
||||
DataContext = new GroupDetailVm(args.RootGroup);
|
||||
else
|
||||
{
|
||||
var vm = e.Parameter as Application.Group.Models.GroupVm;
|
||||
if (vm != null)
|
||||
DataContext = new GroupVm(vm);
|
||||
DataContext = new GroupDetailVm(vm);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -224,8 +224,8 @@
|
||||
<DependentUpon>SaveDatabasePage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ViewModels\EntryVm.cs" />
|
||||
<Compile Include="ViewModels\GroupVm.cs" />
|
||||
<Compile Include="ViewModels\EntryDetailVm.cs" />
|
||||
<Compile Include="ViewModels\GroupDetailVm.cs" />
|
||||
<Compile Include="ViewModels\Items\SettingsNewVm.cs" />
|
||||
<Compile Include="ViewModels\SettingsVm.cs" />
|
||||
<Compile Include="ViewModels\MainVm.cs" />
|
||||
|
Reference in New Issue
Block a user