mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-05 00:20:16 -04:00
WIP open a database
This commit is contained in:
127
ModernKeePass/Pages/DatabaseViewPage.xaml
Normal file
127
ModernKeePass/Pages/DatabaseViewPage.xaml
Normal file
@@ -0,0 +1,127 @@
|
||||
<Page
|
||||
x:Name="pageRoot"
|
||||
x:Class="ModernKeePass.Pages.DatabaseViewPage"
|
||||
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:ModernKeePass.Pages"
|
||||
xmlns:common="using:ModernKeePass.Common"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d">
|
||||
|
||||
<Page.Resources>
|
||||
<x:String x:Key="ChevronGlyph"></x:String>
|
||||
|
||||
<!-- TODO: Delete this line if the key AppName is declared in App.xaml -->
|
||||
<x:String x:Key="AppName">My Application</x:String>
|
||||
|
||||
</Page.Resources>
|
||||
|
||||
<!--
|
||||
This grid acts as a root panel for the page.
|
||||
-->
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<Grid.ChildrenTransitions>
|
||||
<TransitionCollection>
|
||||
<EntranceThemeTransition/>
|
||||
</TransitionCollection>
|
||||
</Grid.ChildrenTransitions>
|
||||
|
||||
<Hub>
|
||||
<Hub.Header>
|
||||
<!-- Back button and page title -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="80"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Button x:Name="backButton" Margin="-1,-1,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
|
||||
Style="{StaticResource NavigationBackButtonNormalStyle}"
|
||||
VerticalAlignment="Top"
|
||||
AutomationProperties.Name="Back"
|
||||
AutomationProperties.AutomationId="BackButton"
|
||||
AutomationProperties.ItemType="Navigation Button"/>
|
||||
<TextBlock x:Name="pageTitle" Text="{StaticResource AppName}" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1"
|
||||
IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Top"/>
|
||||
</Grid>
|
||||
</Hub.Header>
|
||||
|
||||
<HubSection Width="780" Margin="0,0,80,0">
|
||||
<HubSection.Background>
|
||||
<ImageBrush Stretch="UniformToFill" />
|
||||
</HubSection.Background>
|
||||
</HubSection>
|
||||
<HubSection Width="500" Header="Section 1">
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Image Stretch="Fill" Width="420" Height="280"/>
|
||||
<TextBlock Style="{StaticResource SubheaderTextBlockStyle}" Grid.Row="1" Margin="0,10,0,0" TextWrapping="Wrap"
|
||||
Text="Lorem ipsum dolor sit nonumy sed consectetuer ising elit, sed diam"/>
|
||||
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Grid.Row="2" Margin="0,10,0,0"
|
||||
Text="Description text:"/>
|
||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Grid.Row="3"
|
||||
Text="Lorem ipsum dolor sit amet, consectetuer ising elit, sed diam nonummy nibh uismod tincidunt ut laoreet suscipit lobortis ni ut wisi quipexerci quis consequat minim veniam, quis nostrud exerci tation ullam corper. Lorem ipsum dolor sit amet, consectetuer ising elit, sed diam nonummy nibh uismod tincidunt ut laoreet suscipit lobortis ni ut wisi quipexerci quis consequat minim veniam, quis nostrud exerci tation ullam corper. "/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</HubSection>
|
||||
<HubSection Width="520" Header="Section 2">
|
||||
<DataTemplate>
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Margin="0,0,0,10"
|
||||
Text="Item Title" />
|
||||
<TextBlock Style="{StaticResource SubheaderTextBlockStyle}" Grid.Row="1"
|
||||
Text="Quisque in porta lorem dolor amet sed consectetuer ising elit, sed diam non my nibh uis mod wisi quip."/>
|
||||
<TextBlock Style="{StaticResource SubtitleTextBlockStyle}" Grid.Row="2" Margin="0,20,0,0"
|
||||
Text="Item Sub Title"/>
|
||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Grid.Row="3"
|
||||
Text="Lorem ipsum dolor sit amet, consectetuer ising elit, sed diam nonummy nibh uismod tincidunt ut laoreet suscipit lobortis ni ut wisi quipexerci quis consequat minim veniam, quis nostrud exerci tation ullam corper. Lorem ipsum dolor sit amet, consectetuer ising elit, sed diam nonummy nibh uismod tincidunt ut laoreet suscipit lobortis ni ut wisi quipexerci quis consequat minim veniam, quis nostrud exerci tation ullam corper."/>
|
||||
</Grid>
|
||||
</DataTemplate>
|
||||
</HubSection>
|
||||
|
||||
<HubSection Header="Section 3">
|
||||
<DataTemplate>
|
||||
<!-- width of 400 -->
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="130"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="130"/>
|
||||
<ColumnDefinition Width="5"/>
|
||||
<ColumnDefinition Width="130"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="270"/>
|
||||
<RowDefinition Height="95"/>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Image Grid.ColumnSpan="5" Stretch="Fill" Margin="0,0,0,10"/>
|
||||
<Image Grid.Row="1" Stretch="Fill"/>
|
||||
<Image Grid.Row="1" Grid.Column="2" Stretch="Fill"/>
|
||||
<Image Grid.Row="1" Grid.Column="4" Stretch="Fill"/>
|
||||
<TextBlock Style="{StaticResource TitleTextBlockStyle}" Grid.Row="2" Grid.ColumnSpan="5" Margin="0,15,0,0"
|
||||
Text="Description Text:"/>
|
||||
<TextBlock Style="{StaticResource BodyTextBlockStyle}" Grid.Row="3" Grid.ColumnSpan="5"
|
||||
Text="Lorem ipsum dolor sit amet, consectetuer ising elit, sed diam nonummy nibh uismod tincidunt ut laoreet suscipit lobortis ni ut wisi quipexerci quis consequat minim veniam, quis nostrud exerci tation ullam corper. Lorem ipsum dolor sit amet, consectetuer ising elit, sed diam nonummy nibh uismod tincidunt ut laoreet suscipit lobortis ni ut wisi quipexerci quis consequat minim veniam, quis nostrud exerci tation ullam corper."/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</HubSection>
|
||||
</Hub>
|
||||
</Grid>
|
||||
</Page>
|
105
ModernKeePass/Pages/DatabaseViewPage.xaml.cs
Normal file
105
ModernKeePass/Pages/DatabaseViewPage.xaml.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePassLib;
|
||||
using ModernKeePassLib.Interfaces;
|
||||
using ModernKeePassLib.Keys;
|
||||
using ModernKeePassLib.Serialization;
|
||||
using Windows.Storage;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using System.Linq;
|
||||
using System;
|
||||
|
||||
// The Hub Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=321224
|
||||
|
||||
namespace ModernKeePass.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// A page that displays a grouped collection of items.
|
||||
/// </summary>
|
||||
public sealed partial class DatabaseViewPage : Page
|
||||
{
|
||||
private NavigationHelper navigationHelper;
|
||||
private ObservableDictionary defaultViewModel = new ObservableDictionary();
|
||||
private PwDatabase _database = new PwDatabase();
|
||||
|
||||
/// <summary>
|
||||
/// This can be changed to a strongly typed view model.
|
||||
/// </summary>
|
||||
public ObservableDictionary DefaultViewModel
|
||||
{
|
||||
get { return this.defaultViewModel; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// NavigationHelper is used on each page to aid in navigation and
|
||||
/// process lifetime management
|
||||
/// </summary>
|
||||
public NavigationHelper NavigationHelper
|
||||
{
|
||||
get { return this.navigationHelper; }
|
||||
}
|
||||
|
||||
public DatabaseViewPage()
|
||||
{
|
||||
this.InitializeComponent();
|
||||
this.navigationHelper = new NavigationHelper(this);
|
||||
this.navigationHelper.LoadState += navigationHelper_LoadState;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Populates the page with content passed during navigation. Any saved state is also
|
||||
/// provided when recreating a page from a prior session.
|
||||
/// </summary>
|
||||
/// <param name="sender">
|
||||
/// The source of the event; typically <see cref="Common.NavigationHelper"/>
|
||||
/// </param>
|
||||
/// <param name="e">Event data that provides both the navigation parameter passed to
|
||||
/// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested and
|
||||
/// a dictionary of state preserved by this page during an earlier
|
||||
/// session. The state will be null the first time a page is visited.</param>
|
||||
private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
|
||||
{
|
||||
// TODO: Assign a collection of bindable groups to this.DefaultViewModel["Groups"]
|
||||
}
|
||||
|
||||
#region NavigationHelper registration
|
||||
|
||||
/// The methods provided in this section are simply used to allow
|
||||
/// NavigationHelper to respond to the page's navigation methods.
|
||||
///
|
||||
/// Page specific logic should be placed in event handlers for the
|
||||
/// <see cref="Common.NavigationHelper.LoadState"/>
|
||||
/// and <see cref="Common.NavigationHelper.SaveState"/>.
|
||||
/// The navigation parameter is available in the LoadState method
|
||||
/// in addition to page state preserved during an earlier session.
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
navigationHelper.OnNavigatedTo(e);
|
||||
if (e.Parameter is StorageFile)
|
||||
{
|
||||
var file = e.Parameter as StorageFile;
|
||||
var key = new CompositeKey();
|
||||
key.AddUserKey(new KcpPassword("test"));
|
||||
try
|
||||
{
|
||||
_database.Open(IOConnectionInfo.FromPath(file.Path), key, new NullStatusLogger());
|
||||
|
||||
DefaultViewModel["Groups"] = _database.RootGroup.GetGroups(false).Select(g => g.Name);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_database.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnNavigatedFrom(NavigationEventArgs e)
|
||||
{
|
||||
navigationHelper.OnNavigatedFrom(e);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user