Making modifications in an Entry creates a new History entry

This commit is contained in:
BONNEVILLE Geoffroy
2018-06-18 18:40:00 +02:00
parent 9225732c1a
commit b456e56789
2 changed files with 17 additions and 4 deletions

View File

@@ -1,7 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Globalization;
using ModernKeePass.Interfaces; using ModernKeePass.Interfaces;
using ModernKeePass.Services; using ModernKeePass.Services;
using ModernKeePassLib; using ModernKeePassLib;
@@ -148,11 +147,12 @@ namespace ModernKeePass.ViewModels
{ {
get get
{ {
var history = new List<EntryVm> {this}; var history = new Stack<EntryVm>();
foreach (var historyEntry in _pwEntry.History) foreach (var historyEntry in _pwEntry.History)
{ {
history.Add(new EntryVm(historyEntry, ParentGroup) {IsSelected = false}); history.Push(new EntryVm(historyEntry, ParentGroup) {IsSelected = false});
} }
history.Push(this);
return history; return history;
} }
@@ -164,6 +164,7 @@ namespace ModernKeePass.ViewModels
private readonly IDatabaseService _database; private readonly IDatabaseService _database;
private readonly IResourceService _resource; private readonly IResourceService _resource;
private bool _isEditMode; private bool _isEditMode;
private bool _isDirty;
private bool _isRevealPassword; private bool _isRevealPassword;
private double _passwordLength = 25; private double _passwordLength = 25;
private bool _isVisible = true; private bool _isVisible = true;
@@ -221,7 +222,13 @@ namespace ModernKeePass.ViewModels
private void SetEntryValue(string key, string newValue) private void SetEntryValue(string key, string newValue)
{ {
if (!_isDirty)
{
_pwEntry.Touch(true);
_pwEntry?.CreateBackup(null);
}
_pwEntry?.Strings.Set(key, new ProtectedString(true, newValue)); _pwEntry?.Strings.Set(key, new ProtectedString(true, newValue));
_isDirty = true;
} }
public void MarkForDelete(string recycleBinTitle) public void MarkForDelete(string recycleBinTitle)
@@ -264,10 +271,15 @@ namespace ModernKeePass.ViewModels
{ {
return _pwEntry; return _pwEntry;
} }
public void Reset()
{
_isDirty = false;
}
public override string ToString() public override string ToString()
{ {
return IsSelected ? _resource.GetResourceValue("EntryCurrent") : _pwEntry.LastModificationTime.ToString("g"); return IsSelected ? _resource.GetResourceValue("EntryCurrent") : _pwEntry.LastModificationTime.ToString("g");
} }
} }
} }

View File

@@ -50,6 +50,7 @@ namespace ModernKeePass.Views
protected override void OnNavigatedFrom(NavigationEventArgs e) protected override void OnNavigatedFrom(NavigationEventArgs e)
{ {
NavigationHelper.OnNavigatedFrom(e); NavigationHelper.OnNavigatedFrom(e);
Model.Reset();
} }
#endregion #endregion