New database setting page

(Database) Settings available from Main menu
This commit is contained in:
bg45
2017-11-28 16:57:16 -05:00
parent 7b39fe79c8
commit 227bc30dde
10 changed files with 140 additions and 24 deletions

View File

@@ -34,7 +34,7 @@ namespace ModernKeePass.ViewModels
/// </summary>
public bool IsSelected
{
get { return _database.RecycleBinEnabled && _database.RecycleBin?.Id == Id; }
get { return _database != null && _database.RecycleBinEnabled && _database.RecycleBin?.Id == Id; }
set
{
if (value && _pwGroup != null) _database.RecycleBin = this;

View File

@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Windows.Storage;
using Windows.UI.Xaml;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
@@ -15,7 +14,6 @@ namespace ModernKeePass.ViewModels
public class SettingsDatabaseVm: NotifyPropertyChangedBase, IHasSelectableObject
{
private readonly IDatabase _database;
private readonly ApplicationDataContainer _localSettings = ApplicationData.Current.LocalSettings;
private GroupVm _selectedItem;
public bool HasRecycleBin
@@ -96,18 +94,5 @@ namespace ModernKeePass.ViewModels
_database = database;
Groups = _database.RootGroup.Groups;
}
// TODO: Move to another setting class (or a static class)
private T GetSetting<T>(string property)
{
try
{
return (T) Convert.ChangeType(_localSettings.Values[property], typeof(T));
}
catch (InvalidCastException)
{
return default(T);
}
}
}
}

View File

@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Windows.Storage;
using ModernKeePassLib.Cryptography.KeyDerivation;
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); }
}
public IEnumerable<string> KeyDerivations => KdfPool.Engines.Select(e => e.Name);
public string KeyDerivationName
{
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);
}
}
}

View File

@@ -73,6 +73,10 @@ namespace ModernKeePass.ViewModels
IsSelected = (database == null || database.Status == (int) DatabaseHelper.DatabaseStatus.Closed) && mru.Entries.Count > 0, IsEnabled = mru.Entries.Count > 0
},
new MainMenuItemVm
{
Title = "Settings" , PageType = typeof(SettingsPage), Destination = referenceFrame, SymbolIcon = Symbol.Setting
},
new MainMenuItemVm
{
Title = "About" , PageType = typeof(AboutPage), Destination = destinationFrame, SymbolIcon = Symbol.Help
}

View File

@@ -1,17 +1,18 @@
using System.Collections.ObjectModel;
using System.Linq;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Pages;
using ModernKeePass.Pages.SettingsPageFrames;
namespace ModernKeePass.ViewModels
{
public class SettingsVm : NotifyPropertyChangedBase, IHasSelectableObject
{
private ListMenuItemVm _selectedItem;
//public ObservableCollection<ListMenuItemVm> MenuItems { get; set; }
private IOrderedEnumerable<IGrouping<string, ListMenuItemVm>> _menuItems;
public IOrderedEnumerable<IGrouping<string, ListMenuItemVm>> MenuItems
@@ -40,14 +41,33 @@ namespace ModernKeePass.ViewModels
}
}
public SettingsVm()
public SettingsVm() : this((Application.Current as App)?.Database) { }
public SettingsVm(IDatabase database)
{
var menuItems = new ObservableCollection<ListMenuItemVm>
{
new ListMenuItemVm { Title = "General", Group = "Database", SymbolIcon = Symbol.Setting, PageType = typeof(SettingsDatabasePage), IsSelected = true },
new ListMenuItemVm { Title = "Security", Group = "Database", SymbolIcon = Symbol.Permissions, PageType = typeof(SettingsSecurityPage) },
//new ListMenuItemVm { Title = "General", SymbolIcon = Symbol.Edit, PageType = typeof(SettingsGeneralPage) }
new ListMenuItemVm { Title = "New", Group = "Application", SymbolIcon = Symbol.Add, PageType = typeof(SettingsNewDatabasePage) }
};
if (database?.Status == 2)
{
menuItems.Add(new ListMenuItemVm
{
Title = "General",
Group = "Database",
SymbolIcon = Symbol.Setting,
PageType = typeof(SettingsDatabasePage),
IsSelected = true
});
menuItems.Add(new ListMenuItemVm
{
Title = "Security",
Group = "Database",
SymbolIcon = Symbol.Permissions,
PageType = typeof(SettingsSecurityPage)
});
}
SelectedItem = menuItems.FirstOrDefault(m => m.IsSelected);
MenuItems = from item in menuItems group item by item.Group into grp orderby grp.Key select grp;