mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Drag drop finally works
WIP item background New Donate page stub Renamed some classes as services
This commit is contained in:
@@ -5,6 +5,7 @@ using Windows.Storage;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Services;
|
||||
using ModernKeePassLib.Cryptography;
|
||||
using ModernKeePassLib.Keys;
|
||||
using ModernKeePassLib.Serialization;
|
||||
@@ -117,19 +118,19 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
error = $"Error: {e.Message}";
|
||||
}
|
||||
switch ((DatabaseHelper.DatabaseStatus)Database.Status)
|
||||
switch ((DatabaseService.DatabaseStatus)Database.Status)
|
||||
{
|
||||
case DatabaseHelper.DatabaseStatus.Opened:
|
||||
case DatabaseService.DatabaseStatus.Opened:
|
||||
await Task.Run( () => RootGroup = Database.RootGroup);
|
||||
return true;
|
||||
case DatabaseHelper.DatabaseStatus.CompositeKeyError:
|
||||
case DatabaseService.DatabaseStatus.CompositeKeyError:
|
||||
var errorMessage = new StringBuilder("Error: wrong ");
|
||||
if (HasPassword) errorMessage.Append("password");
|
||||
if (HasPassword && HasKeyFile) errorMessage.Append(" or ");
|
||||
if (HasKeyFile) errorMessage.Append("key file");
|
||||
UpdateStatus(errorMessage.ToString(), StatusTypes.Error);
|
||||
break;
|
||||
case DatabaseHelper.DatabaseStatus.Error:
|
||||
case DatabaseService.DatabaseStatus.Error:
|
||||
UpdateStatus(error, StatusTypes.Error);
|
||||
break;
|
||||
}
|
||||
|
@@ -15,17 +15,13 @@ namespace ModernKeePass.ViewModels
|
||||
public class EntryVm : INotifyPropertyChanged, IPwEntity
|
||||
{
|
||||
public GroupVm ParentGroup { get; private set; }
|
||||
|
||||
public GroupVm PreviousGroup { get; private set; }
|
||||
|
||||
public System.Drawing.Color? BackgroundColor => _pwEntry?.BackgroundColor;
|
||||
public System.Drawing.Color? ForegroundColor => _pwEntry?.ForegroundColor;
|
||||
public bool IsRevealPasswordEnabled => !string.IsNullOrEmpty(Password);
|
||||
public bool HasExpired => HasExpirationDate && _pwEntry.ExpiryTime < DateTime.Now;
|
||||
public double PasswordComplexityIndicator => QualityEstimation.EstimatePasswordBits(Password.ToCharArray());
|
||||
public bool IsFirstItem => _pwEntry == null;
|
||||
|
||||
|
||||
public bool UpperCasePatternSelected { get; set; } = true;
|
||||
public bool LowerCasePatternSelected { get; set; } = true;
|
||||
public bool DigitsPatternSelected { get; set; } = true;
|
||||
@@ -36,6 +32,7 @@ namespace ModernKeePass.ViewModels
|
||||
public bool BracketsPatternSelected { get; set; }
|
||||
public string CustomChars { get; set; } = string.Empty;
|
||||
public PwUuid IdUuid => _pwEntry?.Uuid;
|
||||
public string Id => _pwEntry?.Uuid.ToHexString();
|
||||
|
||||
public double PasswordLength
|
||||
{
|
||||
@@ -46,6 +43,7 @@ namespace ModernKeePass.ViewModels
|
||||
NotifyPropertyChanged("PasswordLength");
|
||||
}
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
@@ -56,7 +54,6 @@ namespace ModernKeePass.ViewModels
|
||||
set { SetEntryValue(PwDefs.TitleField, value); }
|
||||
}
|
||||
|
||||
public string Id => _pwEntry?.Uuid.ToHexString();
|
||||
|
||||
public string UserName
|
||||
{
|
||||
|
@@ -9,6 +9,7 @@ using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Mappings;
|
||||
using ModernKeePass.Services;
|
||||
using ModernKeePassLib;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
@@ -85,6 +86,7 @@ namespace ModernKeePass.ViewModels
|
||||
private readonly IDatabase _database;
|
||||
private bool _isEditMode;
|
||||
private PwEntry _reorderedEntry;
|
||||
//private int _reorderedEntryIndex;
|
||||
|
||||
public GroupVm() {}
|
||||
|
||||
@@ -115,7 +117,7 @@ namespace ModernKeePass.ViewModels
|
||||
_pwGroup.Entries.RemoveAt(oldIndex);
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
if (e.OldStartingIndex == -1) _pwGroup.Entries.Add(((EntryVm)e.NewItems[0]).GetPwEntry());
|
||||
if (_reorderedEntry == null) _pwGroup.AddEntry(((EntryVm) e.NewItems[0]).GetPwEntry(), true);
|
||||
else _pwGroup.Entries.Insert((uint)e.NewStartingIndex, _reorderedEntry);
|
||||
break;
|
||||
}
|
||||
@@ -184,11 +186,13 @@ namespace ModernKeePass.ViewModels
|
||||
var comparer = new PwEntryComparer(PwDefs.TitleField, true, true);
|
||||
try
|
||||
{
|
||||
// TODO: this throws an exception
|
||||
_pwGroup.Entries.Sort(comparer);
|
||||
Entries = new ObservableCollection<EntryVm>(Entries.OrderBy(e => e.Name));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
MessageDialogService.ShowErrorDialog(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,7 @@ namespace ModernKeePass.ViewModels
|
||||
set
|
||||
{
|
||||
_database.RecycleBinEnabled = value;
|
||||
OnPropertyChanged();
|
||||
OnPropertyChanged("HasRecycleBin");
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,47 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Windows.Storage;
|
||||
using ModernKeePassLib.Cryptography.KeyDerivation;
|
||||
using System.Collections.Generic;
|
||||
using ModernKeePass.Services;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class SettingsNewVm
|
||||
{
|
||||
private readonly ApplicationDataContainer _localSettings = ApplicationData.Current.LocalSettings;
|
||||
|
||||
public bool IsCreateSample
|
||||
{
|
||||
get { return GetSetting<bool>("Sample"); }
|
||||
set { PutSetting("Sample", value); }
|
||||
get { return SettingsService.GetSetting<bool>("Sample"); }
|
||||
set { SettingsService.PutSetting("Sample", value); }
|
||||
}
|
||||
|
||||
public IEnumerable<string> KeyDerivations => KdfPool.Engines.Select(e => e.Name);
|
||||
public IEnumerable<string> FileFormats => new []{"2", "4"};
|
||||
|
||||
public string KeyDerivationName
|
||||
public string FileFormatVersion
|
||||
{
|
||||
get { return GetSetting<string>("KeyDerivation"); }
|
||||
set { PutSetting("KeyDerivation", value); }
|
||||
}
|
||||
|
||||
// TODO: Move this to a common class
|
||||
private T GetSetting<T>(string property)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (T)Convert.ChangeType(_localSettings.Values[property], typeof(T));
|
||||
}
|
||||
catch (InvalidCastException)
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
}
|
||||
|
||||
private void PutSetting<T>(string property, T value)
|
||||
{
|
||||
if (_localSettings.Values.ContainsKey(property))
|
||||
_localSettings.Values[property] = value;
|
||||
else _localSettings.Values.Add(property, value);
|
||||
get { return SettingsService.GetSetting<string>("DefaultFileFormat"); }
|
||||
set { SettingsService.PutSetting("DefaultFileFormat", value); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,7 @@ using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Pages;
|
||||
using ModernKeePass.Services;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
@@ -50,14 +51,14 @@ namespace ModernKeePass.ViewModels
|
||||
public MainVm(Frame referenceFrame, Frame destinationFrame, IDatabase database)
|
||||
{
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
var isDatabaseOpen = database != null && database.Status == (int) DatabaseHelper.DatabaseStatus.Opened;
|
||||
var isDatabaseOpen = database != null && database.Status == (int) DatabaseService.DatabaseStatus.Opened;
|
||||
|
||||
var mainMenuItems = new ObservableCollection<MainMenuItemVm>
|
||||
{
|
||||
new MainMenuItemVm
|
||||
{
|
||||
Title = "Open", PageType = typeof(OpenDatabasePage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Page2,
|
||||
IsSelected = database != null && database.Status == (int) DatabaseHelper.DatabaseStatus.Opening
|
||||
IsSelected = database != null && database.Status == (int) DatabaseService.DatabaseStatus.Opening
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
@@ -70,7 +71,7 @@ namespace ModernKeePass.ViewModels
|
||||
},
|
||||
new MainMenuItemVm {
|
||||
Title = "Recent" , PageType = typeof(RecentDatabasesPage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Copy,
|
||||
IsSelected = (database == null || database.Status == (int) DatabaseHelper.DatabaseStatus.Closed) && mru.Entries.Count > 0, IsEnabled = mru.Entries.Count > 0
|
||||
IsSelected = (database == null || database.Status == (int) DatabaseService.DatabaseStatus.Closed) && mru.Entries.Count > 0, IsEnabled = mru.Entries.Count > 0
|
||||
},
|
||||
new MainMenuItemVm
|
||||
{
|
||||
@@ -83,7 +84,7 @@ namespace ModernKeePass.ViewModels
|
||||
};
|
||||
// Auto-select the Recent Items menu item if the conditions are met
|
||||
SelectedItem = mainMenuItems.FirstOrDefault(m => m.IsSelected);
|
||||
if (database != null && database.Status == (int) DatabaseHelper.DatabaseStatus.Opened)
|
||||
if (database != null && database.Status == (int) DatabaseService.DatabaseStatus.Opened)
|
||||
mainMenuItems.Add(new MainMenuItemVm
|
||||
{
|
||||
Title = database.Name,
|
||||
|
@@ -3,12 +3,13 @@ using Windows.Storage.AccessCache;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
using ModernKeePass.Services;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class OpenVm: NotifyPropertyChangedBase
|
||||
{
|
||||
public bool ShowPasswordBox => _database?.Status == (int) DatabaseHelper.DatabaseStatus.Opening;
|
||||
public bool ShowPasswordBox => _database?.Status == (int) DatabaseService.DatabaseStatus.Opening;
|
||||
|
||||
public string Name => _database?.Name;
|
||||
|
||||
@@ -19,7 +20,7 @@ namespace ModernKeePass.ViewModels
|
||||
public OpenVm(IDatabase database)
|
||||
{
|
||||
_database = database;
|
||||
if (database == null || database.Status != (int) DatabaseHelper.DatabaseStatus.Opening) return;
|
||||
if (database == null || database.Status != (int) DatabaseService.DatabaseStatus.Opening) return;
|
||||
OpenFile(database.DatabaseFile);
|
||||
}
|
||||
|
||||
|
@@ -47,7 +47,14 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
var menuItems = new ObservableCollection<ListMenuItemVm>
|
||||
{
|
||||
new ListMenuItemVm { Title = "New", Group = "Application", SymbolIcon = Symbol.Add, PageType = typeof(SettingsNewDatabasePage) }
|
||||
new ListMenuItemVm
|
||||
{
|
||||
Title = "New",
|
||||
Group = "Application",
|
||||
SymbolIcon = Symbol.Add,
|
||||
PageType = typeof(SettingsNewDatabasePage),
|
||||
IsSelected = true
|
||||
}
|
||||
};
|
||||
if (database?.Status == 2)
|
||||
{
|
||||
@@ -56,8 +63,7 @@ namespace ModernKeePass.ViewModels
|
||||
Title = "General",
|
||||
Group = "Database",
|
||||
SymbolIcon = Symbol.Setting,
|
||||
PageType = typeof(SettingsDatabasePage),
|
||||
IsSelected = true
|
||||
PageType = typeof(SettingsDatabasePage)
|
||||
});
|
||||
menuItems.Add(new ListMenuItemVm
|
||||
{
|
||||
|
Reference in New Issue
Block a user