mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
New database setting page
(Database) Settings available from Main menu
This commit is contained in:
@@ -133,6 +133,9 @@
|
|||||||
<Compile Include="Pages\SettingsPageFrames\SettingsDatabasePage.xaml.cs">
|
<Compile Include="Pages\SettingsPageFrames\SettingsDatabasePage.xaml.cs">
|
||||||
<DependentUpon>SettingsDatabasePage.xaml</DependentUpon>
|
<DependentUpon>SettingsDatabasePage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<Compile Include="Pages\SettingsPageFrames\SettingsNewDatabasePage.xaml.cs">
|
||||||
|
<DependentUpon>SettingsNewDatabasePage.xaml</DependentUpon>
|
||||||
|
</Compile>
|
||||||
<Compile Include="Pages\SettingsPageFrames\SettingsSecurityPage.xaml.cs">
|
<Compile Include="Pages\SettingsPageFrames\SettingsSecurityPage.xaml.cs">
|
||||||
<DependentUpon>SettingsSecurityPage.xaml</DependentUpon>
|
<DependentUpon>SettingsSecurityPage.xaml</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
@@ -195,6 +198,7 @@
|
|||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="ViewModels\EntryVm.cs" />
|
<Compile Include="ViewModels\EntryVm.cs" />
|
||||||
<Compile Include="ViewModels\GroupVm.cs" />
|
<Compile Include="ViewModels\GroupVm.cs" />
|
||||||
|
<Compile Include="ViewModels\Items\SettingsNewVm.cs" />
|
||||||
<Compile Include="ViewModels\SettingsVm.cs" />
|
<Compile Include="ViewModels\SettingsVm.cs" />
|
||||||
<Compile Include="ViewModels\MainVm.cs" />
|
<Compile Include="ViewModels\MainVm.cs" />
|
||||||
<Compile Include="ViewModels\NewVm.cs" />
|
<Compile Include="ViewModels\NewVm.cs" />
|
||||||
@@ -268,6 +272,10 @@
|
|||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
</Page>
|
</Page>
|
||||||
|
<Page Include="Pages\SettingsPageFrames\SettingsNewDatabasePage.xaml">
|
||||||
|
<SubType>Designer</SubType>
|
||||||
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
</Page>
|
||||||
<Page Include="Pages\SettingsPageFrames\SettingsSecurityPage.xaml">
|
<Page Include="Pages\SettingsPageFrames\SettingsSecurityPage.xaml">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
<Generator>MSBuild:Compile</Generator>
|
<Generator>MSBuild:Compile</Generator>
|
||||||
|
@@ -0,0 +1,22 @@
|
|||||||
|
<Page
|
||||||
|
x:Class="ModernKeePass.Pages.SettingsPageFrames.SettingsNewDatabasePage"
|
||||||
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
|
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||||
|
mc:Ignorable="d">
|
||||||
|
|
||||||
|
<Page.Resources>
|
||||||
|
<CollectionViewSource x:Name="KeyDerivations" Source="{Binding KeyDerivations}" />
|
||||||
|
</Page.Resources>
|
||||||
|
<Page.DataContext>
|
||||||
|
<viewModels:SettingsNewVm />
|
||||||
|
</Page.DataContext>
|
||||||
|
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
|
<TextBlock x:Uid="SettingsNewDatabaseDesc" FontSize="14" />
|
||||||
|
<ToggleSwitch x:Uid="SettingsNewDatabaseSample" IsOn="{Binding IsCreateSample, Mode=TwoWay}" />
|
||||||
|
<TextBlock x:Uid="SettingsNewDatabaseKdf" FontSize="14" />
|
||||||
|
<ComboBox ItemsSource="{Binding Source={StaticResource KeyDerivations}}" SelectedItem="{Binding KeyDerivationName, Mode=TwoWay}" />
|
||||||
|
</StackPanel>
|
||||||
|
</Page>
|
@@ -0,0 +1,15 @@
|
|||||||
|
// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238
|
||||||
|
|
||||||
|
namespace ModernKeePass.Pages.SettingsPageFrames
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Une page vide peut être utilisée seule ou constituer une page de destination au sein d'un frame.
|
||||||
|
/// </summary>
|
||||||
|
public sealed partial class SettingsNewDatabasePage
|
||||||
|
{
|
||||||
|
public SettingsNewDatabasePage()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -249,6 +249,21 @@
|
|||||||
<data name="SettingsDatabaseRecycleBin.OnContent" xml:space="preserve">
|
<data name="SettingsDatabaseRecycleBin.OnContent" xml:space="preserve">
|
||||||
<value>Enabled</value>
|
<value>Enabled</value>
|
||||||
</data>
|
</data>
|
||||||
|
<data name="SettingsNewDatabaseDesc.Text" xml:space="preserve">
|
||||||
|
<value>Here, you can change some default options when creating a database.</value>
|
||||||
|
</data>
|
||||||
|
<data name="SettingsNewDatabaseKdf.Text" xml:space="preserve">
|
||||||
|
<value>Default Key Derivation algorithm</value>
|
||||||
|
</data>
|
||||||
|
<data name="SettingsNewDatabaseSample.Header" xml:space="preserve">
|
||||||
|
<value>Create sample data</value>
|
||||||
|
</data>
|
||||||
|
<data name="SettingsNewDatabaseSample.OffContent" xml:space="preserve">
|
||||||
|
<value>No</value>
|
||||||
|
</data>
|
||||||
|
<data name="SettingsNewDatabaseSample.OnContent" xml:space="preserve">
|
||||||
|
<value>Yes</value>
|
||||||
|
</data>
|
||||||
<data name="SettingsSecurityDesc1.Text" xml:space="preserve">
|
<data name="SettingsSecurityDesc1.Text" xml:space="preserve">
|
||||||
<value>Here, you may change your database password, key file, or both. Just click on on</value>
|
<value>Here, you may change your database password, key file, or both. Just click on on</value>
|
||||||
</data>
|
</data>
|
||||||
|
@@ -34,7 +34,7 @@ namespace ModernKeePass.ViewModels
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsSelected
|
public bool IsSelected
|
||||||
{
|
{
|
||||||
get { return _database.RecycleBinEnabled && _database.RecycleBin?.Id == Id; }
|
get { return _database != null && _database.RecycleBinEnabled && _database.RecycleBin?.Id == Id; }
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
if (value && _pwGroup != null) _database.RecycleBin = this;
|
if (value && _pwGroup != null) _database.RecycleBin = this;
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using Windows.Storage;
|
|
||||||
using Windows.UI.Xaml;
|
using Windows.UI.Xaml;
|
||||||
using ModernKeePass.Common;
|
using ModernKeePass.Common;
|
||||||
using ModernKeePass.Interfaces;
|
using ModernKeePass.Interfaces;
|
||||||
@@ -15,7 +14,6 @@ namespace ModernKeePass.ViewModels
|
|||||||
public class SettingsDatabaseVm: NotifyPropertyChangedBase, IHasSelectableObject
|
public class SettingsDatabaseVm: NotifyPropertyChangedBase, IHasSelectableObject
|
||||||
{
|
{
|
||||||
private readonly IDatabase _database;
|
private readonly IDatabase _database;
|
||||||
private readonly ApplicationDataContainer _localSettings = ApplicationData.Current.LocalSettings;
|
|
||||||
private GroupVm _selectedItem;
|
private GroupVm _selectedItem;
|
||||||
|
|
||||||
public bool HasRecycleBin
|
public bool HasRecycleBin
|
||||||
@@ -96,18 +94,5 @@ namespace ModernKeePass.ViewModels
|
|||||||
_database = database;
|
_database = database;
|
||||||
Groups = _database.RootGroup.Groups;
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
47
ModernKeePass/ViewModels/Items/SettingsNewVm.cs
Normal file
47
ModernKeePass/ViewModels/Items/SettingsNewVm.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -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
|
IsSelected = (database == null || database.Status == (int) DatabaseHelper.DatabaseStatus.Closed) && mru.Entries.Count > 0, IsEnabled = mru.Entries.Count > 0
|
||||||
},
|
},
|
||||||
new MainMenuItemVm
|
new MainMenuItemVm
|
||||||
|
{
|
||||||
|
Title = "Settings" , PageType = typeof(SettingsPage), Destination = referenceFrame, SymbolIcon = Symbol.Setting
|
||||||
|
},
|
||||||
|
new MainMenuItemVm
|
||||||
{
|
{
|
||||||
Title = "About" , PageType = typeof(AboutPage), Destination = destinationFrame, SymbolIcon = Symbol.Help
|
Title = "About" , PageType = typeof(AboutPage), Destination = destinationFrame, SymbolIcon = Symbol.Help
|
||||||
}
|
}
|
||||||
|
@@ -1,9 +1,11 @@
|
|||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using Windows.UI.Xaml;
|
||||||
using Windows.UI.Xaml.Controls;
|
using Windows.UI.Xaml.Controls;
|
||||||
using ModernKeePass.Common;
|
using ModernKeePass.Common;
|
||||||
using ModernKeePass.Interfaces;
|
using ModernKeePass.Interfaces;
|
||||||
using ModernKeePass.Pages;
|
using ModernKeePass.Pages;
|
||||||
|
using ModernKeePass.Pages.SettingsPageFrames;
|
||||||
|
|
||||||
namespace ModernKeePass.ViewModels
|
namespace ModernKeePass.ViewModels
|
||||||
{
|
{
|
||||||
@@ -11,7 +13,6 @@ namespace ModernKeePass.ViewModels
|
|||||||
{
|
{
|
||||||
private ListMenuItemVm _selectedItem;
|
private ListMenuItemVm _selectedItem;
|
||||||
|
|
||||||
//public ObservableCollection<ListMenuItemVm> MenuItems { get; set; }
|
|
||||||
private IOrderedEnumerable<IGrouping<string, ListMenuItemVm>> _menuItems;
|
private IOrderedEnumerable<IGrouping<string, ListMenuItemVm>> _menuItems;
|
||||||
|
|
||||||
public 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>
|
var menuItems = new ObservableCollection<ListMenuItemVm>
|
||||||
{
|
{
|
||||||
new ListMenuItemVm { Title = "General", Group = "Database", SymbolIcon = Symbol.Setting, PageType = typeof(SettingsDatabasePage), IsSelected = true },
|
new ListMenuItemVm { Title = "New", Group = "Application", SymbolIcon = Symbol.Add, PageType = typeof(SettingsNewDatabasePage) }
|
||||||
new ListMenuItemVm { Title = "Security", Group = "Database", SymbolIcon = Symbol.Permissions, PageType = typeof(SettingsSecurityPage) },
|
|
||||||
//new ListMenuItemVm { Title = "General", SymbolIcon = Symbol.Edit, PageType = typeof(SettingsGeneralPage) }
|
|
||||||
};
|
};
|
||||||
|
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);
|
SelectedItem = menuItems.FirstOrDefault(m => m.IsSelected);
|
||||||
|
|
||||||
MenuItems = from item in menuItems group item by item.Group into grp orderby grp.Key select grp;
|
MenuItems = from item in menuItems group item by item.Group into grp orderby grp.Key select grp;
|
||||||
|
@@ -25,7 +25,7 @@ namespace ModernKeePassApp.Test
|
|||||||
var mainVm = new MainVm(null, null, database);
|
var mainVm = new MainVm(null, null, database);
|
||||||
Assert.AreEqual(1, mainVm.MainMenuItems.Count());
|
Assert.AreEqual(1, mainVm.MainMenuItems.Count());
|
||||||
var firstGroup = mainVm.MainMenuItems.FirstOrDefault();
|
var firstGroup = mainVm.MainMenuItems.FirstOrDefault();
|
||||||
Assert.AreEqual(5, firstGroup.Count());
|
Assert.AreEqual(6, firstGroup.Count());
|
||||||
|
|
||||||
database.Status = 1;
|
database.Status = 1;
|
||||||
mainVm = new MainVm(null, null, database);
|
mainVm = new MainVm(null, null, database);
|
||||||
@@ -94,7 +94,7 @@ namespace ModernKeePassApp.Test
|
|||||||
var settingsVm = new SettingsVm();
|
var settingsVm = new SettingsVm();
|
||||||
Assert.AreEqual(1, settingsVm.MenuItems.Count());
|
Assert.AreEqual(1, settingsVm.MenuItems.Count());
|
||||||
var firstGroup = settingsVm.MenuItems.FirstOrDefault();
|
var firstGroup = settingsVm.MenuItems.FirstOrDefault();
|
||||||
Assert.AreEqual(2, firstGroup.Count());
|
Assert.AreEqual(1, firstGroup.Count());
|
||||||
Assert.IsNotNull(settingsVm.SelectedItem);
|
Assert.IsNotNull(settingsVm.SelectedItem);
|
||||||
var selectedItem = (ListMenuItemVm) settingsVm.SelectedItem;
|
var selectedItem = (ListMenuItemVm) settingsVm.SelectedItem;
|
||||||
Assert.AreEqual("General", selectedItem.Title);
|
Assert.AreEqual("General", selectedItem.Title);
|
||||||
|
Reference in New Issue
Block a user