mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 23:50:18 -04:00
Implementing Recent Files WIP
Code refactoring Entry coloring
This commit is contained in:

committed by
BONNEVILLE Geoffroy

parent
817f25e8a8
commit
1ca3f29da0
@@ -18,7 +18,6 @@
|
||||
</Page.DataContext>
|
||||
|
||||
<Grid>
|
||||
|
||||
<Grid.Resources>
|
||||
<CollectionViewSource
|
||||
x:Name="groupsViewSource"
|
||||
@@ -36,7 +35,6 @@
|
||||
<RowDefinition Height="140"/>
|
||||
<RowDefinition Height="*"/>
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<!-- Horizontal scrolling grid -->
|
||||
<GridView
|
||||
x:Name="groupsGridView"
|
||||
@@ -80,9 +78,9 @@
|
||||
IsSynchronizedWithCurrentItem="False" >
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<StackPanel Orientation="Horizontal" Background="{Binding BackgroundColor}">
|
||||
<SymbolIcon Symbol="{Binding IconSymbol}" Margin="0,5,0,0"/>
|
||||
<TextBlock Text="{Binding Title}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="30,0,0,0"/>
|
||||
<TextBlock Text="{Binding Title}" Style="{StaticResource TitleTextBlockStyle}" TextWrapping="NoWrap" HorizontalAlignment="Left" VerticalAlignment="Center" Margin="30,0,0,10" Foreground="{Binding ForegroundColor}"/>
|
||||
</StackPanel>
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
@@ -91,6 +89,12 @@
|
||||
<TextBlock Text="Entries" FontSize="20" Margin="0,20,0,20" />
|
||||
</DataTemplate>
|
||||
</ListView.HeaderTemplate>
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
</ListView>
|
||||
</GridView.Header>
|
||||
<GridView.ItemContainerStyle>
|
||||
|
@@ -7,6 +7,8 @@ using Windows.UI.Xaml.Input;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.ViewModels;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.Storage;
|
||||
|
||||
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
@@ -22,7 +24,6 @@ namespace ModernKeePass.Pages
|
||||
public OpenDatabasePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new DatabaseVm();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
@@ -42,9 +43,28 @@ namespace ModernKeePass.Pages
|
||||
picker.FileTypeFilter.Add(".kdbx");
|
||||
|
||||
var file = await picker.PickSingleFileAsync();
|
||||
if (file == null) return;
|
||||
// Application now has read/write access to the picked file
|
||||
if (file == null) return;
|
||||
// Initialize KDBX database
|
||||
((App)Application.Current).Database = new DatabaseHelper(file);
|
||||
AddToRecentFiles(file);
|
||||
ShowPassword(file);
|
||||
}
|
||||
|
||||
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;*/
|
||||
}
|
||||
|
||||
private void ShowPassword(StorageFile file)
|
||||
{
|
||||
var databaseVm = DataContext as DatabaseVm;
|
||||
if (databaseVm == null) return;
|
||||
databaseVm.SelectedVisibility = Visibility.Visible;
|
||||
|
36
ModernKeePass/Pages/RecentDatabasesPage.xaml
Normal file
36
ModernKeePass/Pages/RecentDatabasesPage.xaml
Normal file
@@ -0,0 +1,36 @@
|
||||
<Page
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:local="using:ModernKeePass.Pages"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:viewModels="using:ModernKeePass.ViewModels"
|
||||
x:Class="ModernKeePass.Pages.RecentDatabasesPage"
|
||||
mc:Ignorable="d">
|
||||
<Page.DataContext>
|
||||
<viewModels:RecentVm/>
|
||||
</Page.DataContext>
|
||||
<Page.Resources>
|
||||
<CollectionViewSource
|
||||
x:Name="RecentItemsSource"
|
||||
Source="{Binding RecentItems}" />
|
||||
</Page.Resources>
|
||||
<ListView
|
||||
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"
|
||||
ItemsSource="{Binding Source={StaticResource RecentItemsSource}}"
|
||||
x:Name="RecentListView"
|
||||
SelectionChanged="RecentListView_SelectionChanged"
|
||||
IsSynchronizedWithCurrentItem="False">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding Name}" Width="350" Padding="5" />
|
||||
</DataTemplate>
|
||||
</ListView.ItemTemplate>
|
||||
<ListView.ItemContainerStyle>
|
||||
<Style TargetType="ListViewItem">
|
||||
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Stretch" />
|
||||
</Style>
|
||||
</ListView.ItemContainerStyle>
|
||||
</ListView>
|
||||
</Page>
|
55
ModernKeePass/Pages/RecentDatabasesPage.xaml.cs
Normal file
55
ModernKeePass/Pages/RecentDatabasesPage.xaml.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Models;
|
||||
using ModernKeePass.ViewModels;
|
||||
using Windows.Storage;
|
||||
using Windows.Storage.AccessCache;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Windows.UI.Xaml.Navigation;
|
||||
|
||||
// Pour en savoir plus sur le modèle d'élément Page vierge, consultez la page http://go.microsoft.com/fwlink/?LinkId=234238
|
||||
|
||||
namespace ModernKeePass.Pages
|
||||
{
|
||||
/// <summary>
|
||||
/// Une page vide peut être utilisée seule ou constituer une page de destination au sein d'un frame.
|
||||
/// </summary>
|
||||
public sealed partial class RecentDatabasesPage : Page
|
||||
{
|
||||
private Frame _mainFrame;
|
||||
|
||||
public RecentDatabasesPage()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
{
|
||||
base.OnNavigatedTo(e);
|
||||
_mainFrame = e.Parameter as Frame;
|
||||
//RecentListView.SelectedIndex = -1;
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
var recentVm = DataContext as RecentVm;
|
||||
recentVm.RecentItems = new ObservableCollection<RecentItem>(
|
||||
from entry in mru.Entries
|
||||
select new RecentItem() { Name = entry.Metadata, Token = entry.Token });
|
||||
recentVm.NotifyPropertyChanged("RecentItems");
|
||||
}
|
||||
|
||||
private async void RecentListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
//if (RecentListView == null || e.RemovedItems.Count > 0) return;
|
||||
var recentItem = e.AddedItems[0] as RecentItem;
|
||||
var mru = StorageApplicationPermissions.MostRecentlyUsedList;
|
||||
var file = await mru.GetFileAsync(recentItem.Token) as StorageFile;
|
||||
|
||||
var app = (App)Application.Current;
|
||||
app.Database = new DatabaseHelper(file);
|
||||
app.Database.Open("test");
|
||||
_mainFrame.Navigate(typeof(GroupDetailPage), app.Database.RootGroup);
|
||||
}
|
||||
}
|
||||
}
|
@@ -11,17 +11,8 @@
|
||||
<viewModels:DatabaseVm/>
|
||||
</Page.DataContext>
|
||||
|
||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<Grid.ChildrenTransitions>
|
||||
<TransitionCollection>
|
||||
<EntranceThemeTransition/>
|
||||
</TransitionCollection>
|
||||
</Grid.ChildrenTransitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<HyperlinkButton Grid.Row="0" x:Name="SaveButton" Content="Save and close" Click="SaveButton_OnClick" VerticalAlignment="Top" IsEnabled="{Binding IsOpen}" />
|
||||
<HyperlinkButton Grid.Row="1" x:Name="SaveAsButton" Content="Save as..." VerticalAlignment="Top" IsEnabled="False" />
|
||||
</Grid>
|
||||
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||
<HyperlinkButton x:Name="SaveButton" Content="Save and close" Click="SaveButton_OnClick" VerticalAlignment="Top" IsEnabled="{Binding IsOpen}" />
|
||||
<HyperlinkButton x:Name="SaveAsButton" Content="Save as..." VerticalAlignment="Top" IsEnabled="False" />
|
||||
</StackPanel>
|
||||
</Page>
|
||||
|
@@ -16,7 +16,6 @@ namespace ModernKeePass.Pages
|
||||
public SaveDatabasePage()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = new DatabaseVm();
|
||||
}
|
||||
|
||||
protected override void OnNavigatedTo(NavigationEventArgs e)
|
||||
|
Reference in New Issue
Block a user