mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Better Entry URL go to button
Migrated code from code behind pages to view models Auto select Recents if there are any recent items WIP auto focus on password box when opening database
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
using System;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Interfaces;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class MainMenuItemVm: IIsEnabled
|
||||
public class MainMenuItemVm: NotifyPropertyChangedBase, IIsEnabled
|
||||
{
|
||||
private string _title;
|
||||
private bool _isSelected;
|
||||
|
||||
public string Title
|
||||
{
|
||||
@@ -21,6 +23,12 @@ namespace ModernKeePass.ViewModels
|
||||
public Symbol SymbolIcon { get; set; }
|
||||
public bool IsEnabled => PageType != null;
|
||||
|
||||
public bool IsSelected
|
||||
{
|
||||
get { return _isSelected; }
|
||||
set { SetProperty(ref _isSelected, value); }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return Title;
|
||||
|
@@ -1,6 +1,4 @@
|
||||
using System.ComponentModel;
|
||||
using Windows.UI.Xaml;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
|
@@ -1,16 +1,73 @@
|
||||
using System.Linq;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Pages;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class MainVm : NotifyPropertyChangedBase
|
||||
{
|
||||
private IOrderedEnumerable<IGrouping<int, MainMenuItemVm>> _mainMenuItems;
|
||||
private MainMenuItemVm _selectedItem;
|
||||
|
||||
public IOrderedEnumerable<IGrouping<int, MainMenuItemVm>> MainMenuItems
|
||||
{
|
||||
get { return _mainMenuItems; }
|
||||
set { SetProperty(ref _mainMenuItems, value); }
|
||||
}
|
||||
|
||||
public MainMenuItemVm SelectedItem
|
||||
{
|
||||
get { return _selectedItem; }
|
||||
set
|
||||
{
|
||||
if (_selectedItem == value) return;
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
_selectedItem.IsSelected = false;
|
||||
}
|
||||
|
||||
SetProperty(ref _selectedItem, value);
|
||||
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
_selectedItem.IsSelected = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public MainVm() {}
|
||||
|
||||
public MainVm(Frame referenceFrame, Frame destinationFrame)
|
||||
{
|
||||
var app = (App)Application.Current;
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
|
||||
var mainMenuItems = new ObservableCollection<MainMenuItemVm>
|
||||
{
|
||||
new MainMenuItemVm {Title = "Open", PageType = typeof(OpenDatabasePage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Page2},
|
||||
new MainMenuItemVm {Title = "New" /*, PageType = typeof(NewDatabasePage)*/, Destination = destinationFrame, SymbolIcon = Symbol.Add},
|
||||
new MainMenuItemVm {Title = "Save" , PageType = typeof(SaveDatabasePage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Save},
|
||||
new MainMenuItemVm {Title = "Recent" , PageType = typeof(RecentDatabasesPage), Destination = destinationFrame, Parameter = referenceFrame, SymbolIcon = Symbol.Copy,
|
||||
IsSelected = (app.Database == null || !app.Database.IsOpen) && mru.Entries.Count > 0}
|
||||
};
|
||||
// Auto-select the Recent Items menu item if the conditions are met
|
||||
SelectedItem = mainMenuItems.FirstOrDefault(m => m.IsSelected);
|
||||
if (app.Database != null && app.Database.IsOpen)
|
||||
mainMenuItems.Add(new MainMenuItemVm
|
||||
{
|
||||
Title = app.Database.Name,
|
||||
PageType = typeof(GroupDetailPage),
|
||||
Destination = referenceFrame,
|
||||
Parameter = app.Database.RootGroup,
|
||||
Group = 1,
|
||||
SymbolIcon = Symbol.ProtectedDocument
|
||||
});
|
||||
|
||||
MainMenuItems = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,4 +1,6 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using Windows.Storage.AccessCache;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
@@ -8,6 +10,16 @@ namespace ModernKeePass.ViewModels
|
||||
private RecentItemVm _selectedItem;
|
||||
private ObservableCollection<RecentItemVm> _recentItems;
|
||||
|
||||
public RecentVm()
|
||||
{
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
RecentItems = new ObservableCollection<RecentItemVm>(
|
||||
from entry in mru.Entries
|
||||
select new RecentItemVm { Name = entry.Metadata, Token = entry.Token });
|
||||
if (RecentItems.Count > 0)
|
||||
SelectedItem = RecentItems[0];
|
||||
}
|
||||
|
||||
public ObservableCollection<RecentItemVm> RecentItems
|
||||
{
|
||||
get { return _recentItems; }
|
||||
|
Reference in New Issue
Block a user