diff --git a/.vs/ModernKeePass/v14/.suo b/.vs/ModernKeePass/v14/.suo
index 799715a..e3b2368 100644
Binary files a/.vs/ModernKeePass/v14/.suo and b/.vs/ModernKeePass/v14/.suo differ
diff --git a/ModernKeePass/MainPage.xaml b/ModernKeePass/MainPage.xaml
index bd209e2..bc4d1f4 100644
--- a/ModernKeePass/MainPage.xaml
+++ b/ModernKeePass/MainPage.xaml
@@ -1,14 +1,41 @@
+ xmlns:ViewModels="using:ModernKeePass.ViewModels"
+ x:Class="ModernKeePass.MainPage"
+ mc:Ignorable="d"
+ Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" >
+
+
+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/ModernKeePass/MainPage.xaml.cs b/ModernKeePass/MainPage.xaml.cs
index 06eb43f..d7d2302 100644
--- a/ModernKeePass/MainPage.xaml.cs
+++ b/ModernKeePass/MainPage.xaml.cs
@@ -31,15 +31,19 @@ namespace ModernKeePass
if (file != null)
{
// Application now has read/write access to the picked file
- textBlock.Text = "Opened database: " + file.Name;
- var database = new DatabaseVm();
- database.Open(file, "test");
- Frame.Navigate(typeof(GroupDetailPage), database.RootGroup);
+ DataContext = new DatabaseVm(file);
}
else
{
- textBlock.Text = "Operation cancelled.";
}
}
+
+ private void openBbutton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
+ {
+ var database = DataContext as DatabaseVm;
+ database.Open();
+ if (database.IsOpen)
+ Frame.Navigate(typeof(GroupDetailPage), database.RootGroup);
+ }
}
}
diff --git a/ModernKeePass/Pages/GroupDetailPage.xaml b/ModernKeePass/Pages/GroupDetailPage.xaml
index 23a1618..eec0fb8 100644
--- a/ModernKeePass/Pages/GroupDetailPage.xaml
+++ b/ModernKeePass/Pages/GroupDetailPage.xaml
@@ -26,20 +26,21 @@
+ ItemsSource="{Binding Source={StaticResource groupsViewSource}}"
+ IsSwipeEnabled="false"
+ SelectionChanged="itemGridView_SelectionChanged"
+ SelectedIndex="-1" >
@@ -54,15 +55,14 @@
+
-
-
-
+
diff --git a/ModernKeePass/Pages/GroupDetailPage.xaml.cs b/ModernKeePass/Pages/GroupDetailPage.xaml.cs
index 353c6fa..c086112 100644
--- a/ModernKeePass/Pages/GroupDetailPage.xaml.cs
+++ b/ModernKeePass/Pages/GroupDetailPage.xaml.cs
@@ -47,8 +47,6 @@ namespace ModernKeePass.Pages
/// session. The state will be null the first time a page is visited.
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
- // TODO: Assign a bindable group to this.DefaultViewModel["Group"]
- // TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"]
}
#region NavigationHelper registration
@@ -69,6 +67,7 @@ namespace ModernKeePass.Pages
if (e.Parameter is GroupVm)
{
DataContext = e.Parameter as GroupVm;
+ groupGridView.SelectedIndex = -1;
}
}
@@ -78,5 +77,11 @@ namespace ModernKeePass.Pages
}
#endregion
+
+ private void itemGridView_SelectionChanged(object sender, SelectionChangedEventArgs e)
+ {
+ var gridView = sender as GridView;
+ Frame.Navigate(typeof(GroupDetailPage), gridView.SelectedItem as GroupVm);
+ }
}
}
diff --git a/ModernKeePass/ViewModels/DatabaseVm.cs b/ModernKeePass/ViewModels/DatabaseVm.cs
index 6ec1e75..d5ec026 100644
--- a/ModernKeePass/ViewModels/DatabaseVm.cs
+++ b/ModernKeePass/ViewModels/DatabaseVm.cs
@@ -5,33 +5,65 @@ using ModernKeePassLib;
using ModernKeePassLib.Keys;
using ModernKeePassLib.Serialization;
using ModernKeePassLib.Interfaces;
+using Windows.UI.Xaml;
+using System;
namespace ModernKeePass.ViewModels
{
public class DatabaseVm : INotifyPropertyChanged
{
- private PwDatabase _database = new PwDatabase();
+ private PwDatabase database = new PwDatabase();
+ private StorageFile databaseFile;
+ public string Password { get; set; }
+ public bool IsOpen { get; set; }
+ public Visibility Visibility { get; private set; }
+ public string ErrorMessage { get; set; }
public string Name { get; set; }
public GroupVm RootGroup { get; set; }
- public event PropertyChangedEventHandler PropertyChanged;
- public async void Open(StorageFile databaseFile, string password)
+ public DatabaseVm()
+ {
+ Visibility = Visibility.Collapsed;
+ }
+ public DatabaseVm(StorageFile databaseFile)
+ {
+ this.databaseFile = databaseFile;
+ Visibility = Visibility.Visible;
+ }
+ public async void Open()
{
var key = new CompositeKey();
- key.AddUserKey(new KcpPassword(password));
try
{
- await _database.Open(IOConnectionInfo.FromFile(databaseFile), key, new NullStatusLogger());
- if (!_database.IsOpen) return;
+ key.AddUserKey(new KcpPassword(Password));
+ await database.Open(IOConnectionInfo.FromFile(databaseFile), key, new NullStatusLogger());
+ IsOpen = database.IsOpen;
Name = databaseFile.DisplayName;
- RootGroup = new GroupVm (_database.RootGroup);
+ RootGroup = new GroupVm (database.RootGroup);
+ }
+ catch (ArgumentNullException)
+ {
+ ErrorMessage = "Password cannot be empty";
+ NotifyPropertyChanged("ErrorMessage");
+ }
+ catch (InvalidCompositeKeyException)
+ {
+ ErrorMessage = "Wrong password";
+ NotifyPropertyChanged("ErrorMessage");
}
finally
{
- _database.Close();
+ // TODO: move this when implementing write mode
+ database.Close();
}
}
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ public void NotifyPropertyChanged(string propertyName)
+ {
+ PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
+ }
}
}
diff --git a/ModernKeePass/ViewModels/GroupVm.cs b/ModernKeePass/ViewModels/GroupVm.cs
index 4ca44ed..06a534e 100644
--- a/ModernKeePass/ViewModels/GroupVm.cs
+++ b/ModernKeePass/ViewModels/GroupVm.cs
@@ -17,6 +17,13 @@ namespace ModernKeePass.ViewModels
return $"{Entries?.Count} entries.";
}
}
+ public string GroupCount
+ {
+ get
+ {
+ return $"{Groups?.Count} groups.";
+ }
+ }
public GroupVm()
{
@@ -39,6 +46,5 @@ namespace ModernKeePass.ViewModels
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
-
}
}