2017-10-11 18:43:27 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Windows.Storage.Pickers;
|
|
|
|
|
using Windows.UI.Xaml;
|
2018-09-10 11:13:44 +02:00
|
|
|
|
using Windows.UI.Xaml.Controls;
|
|
|
|
|
using Windows.UI.Xaml.Navigation;
|
2018-09-07 18:16:40 +02:00
|
|
|
|
using ModernKeePass.Events;
|
2018-09-10 11:13:44 +02:00
|
|
|
|
using ModernKeePass.ImportFormats;
|
2018-09-07 18:16:40 +02:00
|
|
|
|
using ModernKeePass.Services;
|
2017-10-11 18:43:27 +02:00
|
|
|
|
using ModernKeePass.ViewModels;
|
|
|
|
|
|
|
|
|
|
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
|
|
|
|
|
2017-12-08 19:38:33 +01:00
|
|
|
|
namespace ModernKeePass.Views
|
2017-10-11 18:43:27 +02:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// An empty page that can be used on its own or navigated to within a Frame.
|
|
|
|
|
/// </summary>
|
2017-10-12 17:45:37 +02:00
|
|
|
|
public sealed partial class NewDatabasePage
|
2017-10-11 18:43:27 +02:00
|
|
|
|
{
|
2018-09-10 11:13:44 +02:00
|
|
|
|
private Frame _mainFrame;
|
|
|
|
|
|
2017-10-16 16:16:58 +02:00
|
|
|
|
public NewVm Model => (NewVm)DataContext;
|
2017-10-12 18:37:49 +02:00
|
|
|
|
|
2017-10-11 18:43:27 +02:00
|
|
|
|
public NewDatabasePage()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
2018-09-10 11:13:44 +02:00
|
|
|
|
|
|
|
|
|
protected override void OnNavigatedTo(NavigationEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnNavigatedTo(e);
|
|
|
|
|
_mainFrame = e.Parameter as Frame;
|
|
|
|
|
}
|
2017-10-11 18:43:27 +02:00
|
|
|
|
|
2018-09-10 17:29:52 +02:00
|
|
|
|
private async void CreateDatabaseButton_OnClick(object sender, RoutedEventArgs e)
|
2017-10-11 18:43:27 +02:00
|
|
|
|
{
|
|
|
|
|
var savePicker = new FileSavePicker
|
|
|
|
|
{
|
|
|
|
|
SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
|
|
|
|
|
SuggestedFileName = "New Database"
|
|
|
|
|
};
|
|
|
|
|
savePicker.FileTypeChoices.Add("KeePass 2.x database", new List<string> { ".kdbx" });
|
|
|
|
|
|
|
|
|
|
var file = await savePicker.PickSaveFileAsync();
|
|
|
|
|
if (file == null) return;
|
2017-10-12 18:37:49 +02:00
|
|
|
|
Model.OpenFile(file);
|
2017-10-11 18:43:27 +02:00
|
|
|
|
}
|
2018-09-07 18:16:40 +02:00
|
|
|
|
|
2018-09-10 17:29:52 +02:00
|
|
|
|
private void ImportFormatComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
var resources = new ResourcesService();
|
|
|
|
|
var comboBox = sender as ComboBox;
|
|
|
|
|
switch (comboBox?.SelectedIndex)
|
|
|
|
|
{
|
|
|
|
|
case 0:
|
|
|
|
|
Model.ImportFormat = new CsvImportFormat();
|
|
|
|
|
Model.ImportFileExtensionFilter = ".csv";
|
|
|
|
|
Model.ImportFormatHelp = resources.GetResourceValue("NewImportFormatHelpCSV");
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Model.ImportFormat = new NullImportFormat();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-07 18:16:40 +02:00
|
|
|
|
private async void ImportFileButton_OnClick(object sender, RoutedEventArgs e)
|
|
|
|
|
{
|
2020-03-30 19:43:04 +02:00
|
|
|
|
var picker = new FileOpenPicker
|
|
|
|
|
{
|
|
|
|
|
ViewMode = PickerViewMode.List,
|
|
|
|
|
SuggestedStartLocation = PickerLocationId.DocumentsLibrary
|
|
|
|
|
};
|
2018-09-10 17:29:52 +02:00
|
|
|
|
if (!string.IsNullOrEmpty(Model.ImportFileExtensionFilter))
|
|
|
|
|
picker.FileTypeFilter.Add(Model.ImportFileExtensionFilter);
|
2018-09-07 18:16:40 +02:00
|
|
|
|
|
|
|
|
|
// Application now has read/write access to the picked file
|
|
|
|
|
Model.ImportFile = await picker.PickSingleFileAsync();
|
2018-09-10 17:29:52 +02:00
|
|
|
|
if (Model.ImportFile != null) ImportFileLink.Content = Model.ImportFile.Name;
|
2018-09-07 18:16:40 +02:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-30 19:43:04 +02:00
|
|
|
|
private async void CompositeKeyUserControl_OnValidationChecked(object sender, PasswordEventArgs e)
|
2018-09-07 18:16:40 +02:00
|
|
|
|
{
|
2020-03-30 19:43:04 +02:00
|
|
|
|
var rootGroup = await Model.PopulateInitialData();
|
|
|
|
|
_mainFrame.Navigate(typeof(GroupDetailPage), rootGroup);
|
2018-09-10 11:13:44 +02:00
|
|
|
|
}
|
2017-10-11 18:43:27 +02:00
|
|
|
|
}
|
|
|
|
|
}
|