diff --git a/ModernKeePass/Common/DatabaseHelper.cs b/ModernKeePass/Common/DatabaseHelper.cs
index ad4d0e9..8e05e15 100644
--- a/ModernKeePass/Common/DatabaseHelper.cs
+++ b/ModernKeePass/Common/DatabaseHelper.cs
@@ -22,7 +22,7 @@ namespace ModernKeePass.Common
public DatabaseHelper(StorageFile databaseFile)
{
- this._databaseFile = databaseFile;
+ _databaseFile = databaseFile;
}
public string Open(string password)
{
@@ -31,9 +31,8 @@ namespace ModernKeePass.Common
{
key.AddUserKey(new KcpPassword(password));
_pwDatabase.Open(IOConnectionInfo.FromFile(_databaseFile), key, new NullStatusLogger());
- //_pwDatabase.Open(IOConnectionInfo.FromPath(databaseFile.Path), key, new NullStatusLogger());
- if (IsOpen) RootGroup = new GroupVm(_pwDatabase.RootGroup);
+ if (IsOpen) RootGroup = new GroupVm(_pwDatabase.RootGroup, null);
}
catch (ArgumentNullException)
{
@@ -47,11 +46,6 @@ namespace ModernKeePass.Common
{
return ex.Message;
}
- /*finally
- {
- // TODO: move this when implementing write mode
- _pwDatabase.Close();
- }*/
return string.Empty;
}
diff --git a/ModernKeePass/ModernKeePass.csproj b/ModernKeePass/ModernKeePass.csproj
index 3c210fb..2176b1b 100644
--- a/ModernKeePass/ModernKeePass.csproj
+++ b/ModernKeePass/ModernKeePass.csproj
@@ -125,8 +125,8 @@
MainPage.xaml
-
-
+
+
EntryDetailPage.xaml
@@ -216,9 +216,7 @@
True
-
-
-
+
diff --git a/ModernKeePass/ModernKeePass.csproj.DotSettings b/ModernKeePass/ModernKeePass.csproj.DotSettings
index c54c126..50dd80d 100644
--- a/ModernKeePass/ModernKeePass.csproj.DotSettings
+++ b/ModernKeePass/ModernKeePass.csproj.DotSettings
@@ -1,2 +1,3 @@
- CSharp70
\ No newline at end of file
+ CSharp70
+ True
\ No newline at end of file
diff --git a/ModernKeePass/Pages/EntryDetailPage.xaml b/ModernKeePass/Pages/EntryDetailPage.xaml
index cbab525..2142368 100644
--- a/ModernKeePass/Pages/EntryDetailPage.xaml
+++ b/ModernKeePass/Pages/EntryDetailPage.xaml
@@ -48,15 +48,20 @@
+
-
-
+
+
+
+
diff --git a/ModernKeePass/Pages/EntryDetailPage.xaml.cs b/ModernKeePass/Pages/EntryDetailPage.xaml.cs
index ccc6b8b..6d89d31 100644
--- a/ModernKeePass/Pages/EntryDetailPage.xaml.cs
+++ b/ModernKeePass/Pages/EntryDetailPage.xaml.cs
@@ -83,5 +83,12 @@ namespace ModernKeePass.Pages
passwordBox.Visibility = Visibility.Visible;
passwordTextBox.Visibility = Visibility.Collapsed;
}
+
+ private void AppBarButton_Click(object sender, RoutedEventArgs e)
+ {
+ var entry = DataContext as EntryVm;
+ entry?.RemoveEntry();
+ if (Frame.CanGoBack) Frame.GoBack();
+ }
}
}
diff --git a/ModernKeePass/Pages/GroupDetailPage.xaml b/ModernKeePass/Pages/GroupDetailPage.xaml
index 764dfb9..3c74c2c 100644
--- a/ModernKeePass/Pages/GroupDetailPage.xaml
+++ b/ModernKeePass/Pages/GroupDetailPage.xaml
@@ -1,29 +1,27 @@
-
+
-
+
@@ -36,88 +34,116 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
-
+
+
-
-
+
+
+
+
diff --git a/ModernKeePass/Pages/GroupDetailPage.xaml.cs b/ModernKeePass/Pages/GroupDetailPage.xaml.cs
index c93c36a..558b782 100644
--- a/ModernKeePass/Pages/GroupDetailPage.xaml.cs
+++ b/ModernKeePass/Pages/GroupDetailPage.xaml.cs
@@ -14,20 +14,18 @@ namespace ModernKeePass.Pages
///
public sealed partial class GroupDetailPage : Page
{
- private NavigationHelper navigationHelper;
-
///
/// NavigationHelper is used on each page to aid in navigation and
/// process lifetime management
///
- public NavigationHelper NavigationHelper => navigationHelper;
+ public NavigationHelper NavigationHelper { get; }
public GroupDetailPage()
{
InitializeComponent();
- navigationHelper = new NavigationHelper(this);
- navigationHelper.LoadState += navigationHelper_LoadState;
+ NavigationHelper = new NavigationHelper(this);
+ NavigationHelper.LoadState += navigationHelper_LoadState;
}
///
@@ -58,7 +56,7 @@ namespace ModernKeePass.Pages
///
protected override void OnNavigatedTo(NavigationEventArgs e)
{
- navigationHelper.OnNavigatedTo(e);
+ NavigationHelper.OnNavigatedTo(e);
if (!(e.Parameter is GroupVm)) return;
DataContext = (GroupVm) e.Parameter;
@@ -66,22 +64,53 @@ namespace ModernKeePass.Pages
protected override void OnNavigatedFrom(NavigationEventArgs e)
{
- navigationHelper.OnNavigatedFrom(e);
+ NavigationHelper.OnNavigatedFrom(e);
}
#endregion
- private void groupsGridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ private void groups_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
- var gridView = sender as GridView;
- Frame.Navigate(typeof(GroupDetailPage), gridView?.SelectedItem as GroupVm);
+ GroupVm selectedItem = null;
+ if (sender is GridView)
+ {
+ var gridView = (GridView) sender;
+ if (gridView.SelectedIndex == 0)
+ {
+ var currentGroup = DataContext as GroupVm;
+ currentGroup?.CreateNewGroup();
+ gridView.SelectedIndex = -1;
+ // TODO: Navigate to new group?
+ return;
+ }
+ selectedItem = gridView.SelectedItem as GroupVm;
+ }
+ if (sender is ListView) selectedItem = ((ListView) sender).SelectedItem as GroupVm;
+ if (selectedItem == null) return;
+ Frame.Navigate(typeof(GroupDetailPage), selectedItem);
}
private void entriesListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var listView = sender as ListView;
+ if (listView != null && listView.SelectedIndex == -1) return;
+ if (listView.SelectedIndex == 0)
+ {
+ var currentGroup = DataContext as GroupVm;
+ currentGroup?.CreateNewEntry();
+ listView.SelectedIndex = -1;
+ // TODO: Navigate to new entry?
+ return;
+ }
Frame.Navigate(typeof(EntryDetailPage), listView?.SelectedItem as EntryVm);
}
+
+ private void AppBarButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
+ {
+ var group = DataContext as GroupVm;
+ group?.RemoveGroup();
+ if (Frame.CanGoBack) Frame.GoBack();
+ }
}
}
diff --git a/ModernKeePass/Pages/OpenDatabasePage.xaml.cs b/ModernKeePass/Pages/OpenDatabasePage.xaml.cs
index 3486b37..12c49e5 100644
--- a/ModernKeePass/Pages/OpenDatabasePage.xaml.cs
+++ b/ModernKeePass/Pages/OpenDatabasePage.xaml.cs
@@ -54,13 +54,7 @@ namespace ModernKeePass.Pages
private void AddToRecentFiles(StorageFile file)
{
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
- var mruToken = mru.Add(file, file.DisplayName);
-
- /*var localSettings = ApplicationData.Current.LocalSettings;
- if (!localSettings.Containers.ContainsKey("Recent"))
- localSettings.CreateContainer("Recent", ApplicationDataCreateDisposition.Always);
-
- localSettings.Containers["Recent"].Values[file.DisplayName] = mruToken;*/
+ mru.Add(file, file.DisplayName);
}
private void ShowPassword(StorageFile file)
diff --git a/ModernKeePass/Properties/AssemblyInfo.cs b/ModernKeePass/Properties/AssemblyInfo.cs
index d29775c..96f1f61 100644
--- a/ModernKeePass/Properties/AssemblyInfo.cs
+++ b/ModernKeePass/Properties/AssemblyInfo.cs
@@ -24,6 +24,6 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
-[assembly: AssemblyVersion("1.0.0.0")]
-[assembly: AssemblyFileVersion("1.0.0.0")]
+[assembly: AssemblyVersion("1.1.0.0")]
+[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: ComVisible(false)]
\ No newline at end of file
diff --git a/ModernKeePass/ViewModels/EntryVm.cs b/ModernKeePass/ViewModels/EntryVm.cs
index a47391d..abdca24 100644
--- a/ModernKeePass/ViewModels/EntryVm.cs
+++ b/ModernKeePass/ViewModels/EntryVm.cs
@@ -1,19 +1,25 @@
-using System.ComponentModel;
-using System.Drawing;
-using Windows.UI.Xaml.Controls;
+using Windows.UI.Xaml.Controls;
using ModernKeePass.Mappings;
using ModernKeePassLib;
using ModernKeePassLib.Security;
using Windows.UI.Xaml.Media;
using Windows.UI;
+using Windows.UI.Text;
+using Windows.UI.Xaml;
namespace ModernKeePass.ViewModels
{
public class EntryVm
{
+ public GroupVm ParentGroup { get; }
+ public PwEntry Entry => _pwEntry;
public string Title
{
- get { return GetEntryValue(PwDefs.TitleField); }
+ get
+ {
+ var title = GetEntryValue(PwDefs.TitleField);
+ return title == null ? "New entry" : title;
+ }
set { SetEntryValue(PwDefs.TitleField, value); }
}
public string UserName
@@ -37,14 +43,17 @@ namespace ModernKeePass.ViewModels
set { SetEntryValue(PwDefs.NotesField, value); }
}
- public SolidColorBrush BackgroundColor => CreateFromColor(_pwEntry.BackgroundColor, Colors.Transparent);
+ public SolidColorBrush BackgroundColor => CreateFromColor(_pwEntry?.BackgroundColor, Colors.Transparent);
- public SolidColorBrush ForegroundColor => CreateFromColor(_pwEntry.ForegroundColor, Colors.White);
+ public SolidColorBrush ForegroundColor => CreateFromColor(_pwEntry?.ForegroundColor, Colors.White);
+
+ public FontWeight FontWeight => _pwEntry == null ? FontWeights.Bold : FontWeights.Normal;
public Symbol IconSymbol
{
get
{
+ if (_pwEntry == null) return Symbol.Add;
var result = PwIconToSegoeMapping.GetSymbolFromIcon(_pwEntry.IconId);
return result == Symbol.More ? Symbol.Permissions : result;
}
@@ -53,29 +62,35 @@ namespace ModernKeePass.ViewModels
private readonly PwEntry _pwEntry;
public EntryVm() { }
- public EntryVm(PwEntry entry)
+ public EntryVm(PwEntry entry, GroupVm parent)
{
_pwEntry = entry;
+ ParentGroup = parent;
+ }
+
+ public void RemoveEntry()
+ {
+ ParentGroup.RemoveEntry(this);
}
private string GetEntryValue(string key)
{
- return _pwEntry.Strings.GetSafe(key).ReadString();
+ return _pwEntry?.Strings.GetSafe(key).ReadString();
}
private void SetEntryValue(string key, string newValue)
{
- _pwEntry.Strings.Set(key, new ProtectedString(true, newValue));
+ _pwEntry?.Strings.Set(key, new ProtectedString(true, newValue));
}
- private SolidColorBrush CreateFromColor(System.Drawing.Color color, Windows.UI.Color defaultValue)
+ private SolidColorBrush CreateFromColor(System.Drawing.Color? color, Windows.UI.Color defaultValue)
{
- if (color == System.Drawing.Color.Empty) return new SolidColorBrush(defaultValue);
+ if (!color.HasValue || color.Value == System.Drawing.Color.Empty) return new SolidColorBrush(defaultValue);
return new SolidColorBrush(Windows.UI.Color.FromArgb(
- color.A,
- color.R,
- color.G,
- color.B));
+ color.Value.A,
+ color.Value.R,
+ color.Value.G,
+ color.Value.B));
}
}
}
diff --git a/ModernKeePass/ViewModels/GroupVm.cs b/ModernKeePass/ViewModels/GroupVm.cs
index ce40844..e1005c8 100644
--- a/ModernKeePass/ViewModels/GroupVm.cs
+++ b/ModernKeePass/ViewModels/GroupVm.cs
@@ -1,6 +1,7 @@
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
+using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Mappings;
using ModernKeePassLib;
@@ -9,63 +10,76 @@ namespace ModernKeePass.ViewModels
{
public class GroupVm : INotifyPropertyChanged
{
- private PwGroup _pwGroup;
+ public GroupVm ParentGroup { get; }
+ public ObservableCollection Entries { get; set; } = new ObservableCollection();
+ public ObservableCollection Groups { get; set; } = new ObservableCollection();
+ public string Name => _pwGroup == null ? "New group" : _pwGroup.Name;
- public ObservableCollection Entries { get; set; }
- public ObservableCollection Groups { get; set; }
- public string Name { get; set; }
+ public int EntryCount => Entries.Count - 1;
- public int EntryCount => Entries.Count;
+ public int GroupCount => Groups.Count - 1;
- public int GroupCount => Groups.Count;
+ public Visibility DetailsVisibility => _pwGroup == null ? Visibility.Collapsed : Visibility.Visible;
+ public Visibility NewVisibility => _pwGroup == null ? Visibility.Visible : Visibility.Collapsed;
public Symbol IconSymbol
{
get
{
+ if (_pwGroup == null) return Symbol.Add;
var result = PwIconToSegoeMapping.GetSymbolFromIcon(_pwGroup.IconId);
return result == Symbol.More ? Symbol.Folder : result;
}
}
- public GroupVm()
- {
- Name = "GroupName";
- Entries = new ObservableCollection();
- Groups = new ObservableCollection();
- }
+ public bool IsNotRoot => ParentGroup != null;
- public GroupVm(PwGroup pwGroup)
+ private readonly PwGroup _pwGroup;
+ public GroupVm() {}
+
+ public GroupVm(PwGroup pwGroup, GroupVm parent)
{
_pwGroup = pwGroup;
- Name = pwGroup.Name;
- Entries = new ObservableCollection(pwGroup.Entries.Select(e => new EntryVm(e)));
- //Entries.Insert(0, new EntryVm { Title = " + New entry" });
- Groups = new ObservableCollection(pwGroup.Groups.Select(g => new GroupVm(g)));
+ ParentGroup = parent;
+ Entries = new ObservableCollection(pwGroup.Entries.Select(e => new EntryVm(e, this)));
+ Entries.Insert(0, new EntryVm ());
+ //Entries.Add(new EntryVm { Title = " New entry" });
+ Groups = new ObservableCollection(pwGroup.Groups.Select(g => new GroupVm(g, this)));
//Groups.Insert(0, new GroupVm { Name = " + New group" });
+ Groups.Insert(0, new GroupVm ());
}
- public void CreateNewGroup(string title)
+ public void CreateNewGroup()
{
- var pwGroup = new PwGroup(true, true, title, PwIcon.Folder);
+ var pwGroup = new PwGroup(true, true, "New group", PwIcon.Folder);
_pwGroup.AddGroup(pwGroup, true);
- Groups.Add(new GroupVm(pwGroup));
- NotifyPropertyChanged("Groups");
+ Groups.Add(new GroupVm(pwGroup, this));
}
- public void CreateNewEntry(string title)
+ public void CreateNewEntry()
{
var pwEntry = new PwEntry(true, true);
_pwGroup.AddEntry(pwEntry, true);
- Entries.Add(new EntryVm(pwEntry));
- NotifyPropertyChanged("Entries");
+ Entries.Add(new EntryVm(pwEntry, this));
+ }
+
+ public void RemoveGroup()
+ {
+ _pwGroup.ParentGroup.Groups.Remove(_pwGroup);
+ ParentGroup.Groups.Remove(this);
}
+ public void RemoveEntry(EntryVm entry)
+ {
+ _pwGroup.Entries.Remove(entry.Entry);
+ Entries.Remove(entry);
+ }
public event PropertyChangedEventHandler PropertyChanged;
public void NotifyPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
+
}
}
diff --git a/ModernKeePass/ViewModels/MainMenuItemVm.cs b/ModernKeePass/ViewModels/Items/MainMenuItemVm.cs
similarity index 100%
rename from ModernKeePass/ViewModels/MainMenuItemVm.cs
rename to ModernKeePass/ViewModels/Items/MainMenuItemVm.cs
diff --git a/ModernKeePass/ViewModels/RecentItemVm.cs b/ModernKeePass/ViewModels/Items/RecentItemVm.cs
similarity index 100%
rename from ModernKeePass/ViewModels/RecentItemVm.cs
rename to ModernKeePass/ViewModels/Items/RecentItemVm.cs