2017-10-30 18:34:38 +01:00
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.Linq;
|
2017-11-28 16:57:16 -05:00
|
|
|
|
using Windows.UI.Xaml;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
using ModernKeePass.Common;
|
|
|
|
|
using ModernKeePass.Interfaces;
|
|
|
|
|
using ModernKeePass.Pages;
|
2017-11-28 16:57:16 -05:00
|
|
|
|
using ModernKeePass.Pages.SettingsPageFrames;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
|
|
|
|
|
namespace ModernKeePass.ViewModels
|
|
|
|
|
{
|
2017-11-27 15:26:36 +01:00
|
|
|
|
public class SettingsVm : NotifyPropertyChangedBase, IHasSelectableObject
|
2017-10-30 18:34:38 +01:00
|
|
|
|
{
|
|
|
|
|
private ListMenuItemVm _selectedItem;
|
2017-11-28 16:57:16 -05:00
|
|
|
|
|
2017-11-27 15:26:36 +01:00
|
|
|
|
private IOrderedEnumerable<IGrouping<string, ListMenuItemVm>> _menuItems;
|
|
|
|
|
|
|
|
|
|
public IOrderedEnumerable<IGrouping<string, ListMenuItemVm>> MenuItems
|
|
|
|
|
{
|
|
|
|
|
get { return _menuItems; }
|
|
|
|
|
set { SetProperty(ref _menuItems, value); }
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-30 18:34:38 +01:00
|
|
|
|
public ISelectableModel SelectedItem
|
|
|
|
|
{
|
|
|
|
|
get { return _selectedItem; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (_selectedItem == value) return;
|
|
|
|
|
if (_selectedItem != null)
|
|
|
|
|
{
|
|
|
|
|
_selectedItem.IsSelected = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetProperty(ref _selectedItem, (ListMenuItemVm)value);
|
|
|
|
|
|
|
|
|
|
if (_selectedItem != null)
|
|
|
|
|
{
|
|
|
|
|
_selectedItem.IsSelected = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-28 16:57:16 -05:00
|
|
|
|
public SettingsVm() : this((Application.Current as App)?.Database) { }
|
|
|
|
|
|
|
|
|
|
public SettingsVm(IDatabase database)
|
2017-10-30 18:34:38 +01:00
|
|
|
|
{
|
2017-11-27 15:26:36 +01:00
|
|
|
|
var menuItems = new ObservableCollection<ListMenuItemVm>
|
2017-10-30 18:34:38 +01:00
|
|
|
|
{
|
2017-11-29 19:13:38 +01:00
|
|
|
|
new ListMenuItemVm
|
|
|
|
|
{
|
|
|
|
|
Title = "New",
|
|
|
|
|
Group = "Application",
|
|
|
|
|
SymbolIcon = Symbol.Add,
|
|
|
|
|
PageType = typeof(SettingsNewDatabasePage),
|
|
|
|
|
IsSelected = true
|
2017-12-01 09:31:59 +01:00
|
|
|
|
},
|
|
|
|
|
new ListMenuItemVm
|
2017-11-28 16:57:16 -05:00
|
|
|
|
{
|
|
|
|
|
Title = "General",
|
|
|
|
|
Group = "Database",
|
|
|
|
|
SymbolIcon = Symbol.Setting,
|
2017-12-01 09:31:59 +01:00
|
|
|
|
PageType = typeof(SettingsDatabasePage),
|
|
|
|
|
IsEnabled = database?.Status == 2
|
|
|
|
|
},
|
|
|
|
|
new ListMenuItemVm
|
2017-11-28 16:57:16 -05:00
|
|
|
|
{
|
|
|
|
|
Title = "Security",
|
|
|
|
|
Group = "Database",
|
|
|
|
|
SymbolIcon = Symbol.Permissions,
|
2017-12-01 09:31:59 +01:00
|
|
|
|
PageType = typeof(SettingsSecurityPage),
|
|
|
|
|
IsEnabled = database?.Status == 2
|
|
|
|
|
}
|
|
|
|
|
};
|
2017-11-27 15:26:36 +01:00
|
|
|
|
SelectedItem = menuItems.FirstOrDefault(m => m.IsSelected);
|
|
|
|
|
|
|
|
|
|
MenuItems = from item in menuItems group item by item.Group into grp orderby grp.Key select grp;
|
2017-10-30 18:34:38 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|