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

committed by
BONNEVILLE Geoffroy

parent
817f25e8a8
commit
1ca3f29da0
@@ -29,21 +29,21 @@ namespace ModernKeePass
|
||||
new MainMenuItem {Title = "Open", PageType = typeof(OpenDatabasePage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Page2},
|
||||
new MainMenuItem {Title = "New" /*, PageType = typeof(NewDatabasePage)*/, Destination = MenuFrame, SymbolIcon = Symbol.Add},
|
||||
new MainMenuItem {Title = "Save" , PageType = typeof(SaveDatabasePage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Save},
|
||||
new MainMenuItem {Title = "Recent" /*, PageType = typeof(RecentDatabasesPage)*/, Destination = MenuFrame, SymbolIcon = Symbol.Copy}
|
||||
new MainMenuItem {Title = "Recent" , PageType = typeof(RecentDatabasesPage), Destination = MenuFrame, Parameter = Frame, SymbolIcon = Symbol.Copy}
|
||||
};
|
||||
var app = (App)Application.Current;
|
||||
if (app.Database != null && app.Database.IsOpen)
|
||||
mainMenuItems.Add(new MainMenuItem { Title = app.Database.Name, PageType = typeof(GroupDetailPage), Destination = Frame, Parameter = app.Database.RootGroup, Group = 1, SymbolIcon = Symbol.ProtectedDocument});
|
||||
var result = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
|
||||
MenuItemsSource.Source = result;
|
||||
|
||||
var mainVm = DataContext as MainVm;
|
||||
mainVm.MainMenuItems = from item in mainMenuItems group item by item.Group into grp orderby grp.Key select grp;
|
||||
mainVm.NotifyPropertyChanged("MainMenuItems");
|
||||
}
|
||||
|
||||
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
var listView = sender as ListView;
|
||||
if (listView == null) return;
|
||||
var selectedItem = listView.SelectedItem as MainMenuItem;
|
||||
selectedItem?.Destination.Navigate(selectedItem.PageType, selectedItem.Parameter);
|
||||
var mainMenuItem = e.AddedItems[0] as MainMenuItem;
|
||||
mainMenuItem?.Destination.Navigate(mainMenuItem.PageType, mainMenuItem.Parameter);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
8
ModernKeePass/Models/RecentItem.cs
Normal file
8
ModernKeePass/Models/RecentItem.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace ModernKeePass.Models
|
||||
{
|
||||
public class RecentItem
|
||||
{
|
||||
public string Token { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
@@ -123,6 +123,7 @@
|
||||
</Compile>
|
||||
<Compile Include="Mappings\PwIconToSegoeMapping.cs" />
|
||||
<Compile Include="Models\MainMenuItem.cs" />
|
||||
<Compile Include="Models\RecentItem.cs" />
|
||||
<Compile Include="Pages\EntryDetailPage.xaml.cs">
|
||||
<DependentUpon>EntryDetailPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -132,6 +133,9 @@
|
||||
<Compile Include="Pages\OpenDatabasePage.xaml.cs">
|
||||
<DependentUpon>OpenDatabasePage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pages\RecentDatabasesPage.xaml.cs">
|
||||
<DependentUpon>RecentDatabasesPage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Pages\SaveDatabasePage.xaml.cs">
|
||||
<DependentUpon>SaveDatabasePage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -140,6 +144,7 @@
|
||||
<Compile Include="ViewModels\EntryVm.cs" />
|
||||
<Compile Include="ViewModels\GroupVm.cs" />
|
||||
<Compile Include="ViewModels\MainVm.cs" />
|
||||
<Compile Include="ViewModels\RecentVm.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<AppxManifest Include="Package.appxmanifest">
|
||||
@@ -173,6 +178,10 @@
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Pages\RecentDatabasesPage.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
</Page>
|
||||
<Page Include="Pages\SaveDatabasePage.xaml">
|
||||
<SubType>Designer</SubType>
|
||||
<Generator>MSBuild:Compile</Generator>
|
||||
@@ -183,7 +192,7 @@
|
||||
<HintPath>..\packages\Portable.BouncyCastle.1.8.1.3\lib\netstandard1.0\BouncyCastle.Crypto.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="ModernKeePassLib, Version=2.28.1.27501, Culture=neutral, processorArchitecture=MSIL">
|
||||
<Reference Include="ModernKeePassLib, Version=2.28.1.30896, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\ModernKeePassLib.2.28.3000\lib\netstandard1.2\ModernKeePassLib.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
|
@@ -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)
|
||||
|
@@ -1,12 +1,15 @@
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using ModernKeePass.Mappings;
|
||||
using ModernKeePassLib;
|
||||
using ModernKeePassLib.Security;
|
||||
using Windows.UI.Xaml.Media;
|
||||
using Windows.UI;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class EntryVm : INotifyPropertyChanged
|
||||
public class EntryVm
|
||||
{
|
||||
public string Title
|
||||
{
|
||||
@@ -34,6 +37,10 @@ namespace ModernKeePass.ViewModels
|
||||
set { SetEntryValue(PwDefs.NotesField, value); }
|
||||
}
|
||||
|
||||
public SolidColorBrush BackgroundColor => CreateFromColor(_pwEntry.BackgroundColor, Colors.Transparent);
|
||||
|
||||
public SolidColorBrush ForegroundColor => CreateFromColor(_pwEntry.ForegroundColor, Colors.White);
|
||||
|
||||
public Symbol IconSymbol
|
||||
{
|
||||
get
|
||||
@@ -42,9 +49,7 @@ namespace ModernKeePass.ViewModels
|
||||
return result == Symbol.More ? Symbol.Permissions : result;
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
|
||||
private readonly PwEntry _pwEntry;
|
||||
|
||||
public EntryVm() { }
|
||||
@@ -62,5 +67,15 @@ namespace ModernKeePass.ViewModels
|
||||
{
|
||||
_pwEntry.Strings.Set(key, new ProtectedString(true, newValue));
|
||||
}
|
||||
|
||||
private SolidColorBrush CreateFromColor(System.Drawing.Color color, Windows.UI.Color defaultValue)
|
||||
{
|
||||
if (color == System.Drawing.Color.Empty) return new SolidColorBrush(defaultValue);
|
||||
return new SolidColorBrush(Windows.UI.Color.FromArgb(
|
||||
color.A,
|
||||
color.R,
|
||||
color.G,
|
||||
color.B));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,10 +1,18 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using ModernKeePass.Models;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class MainVm
|
||||
public class MainVm : INotifyPropertyChanged
|
||||
{
|
||||
public ObservableCollection<MainMenuItem> MainMenuItems { get; set; }
|
||||
public IOrderedEnumerable<IGrouping<int, MainMenuItem>> MainMenuItems { get; set; }
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
public void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
18
ModernKeePass/ViewModels/RecentVm.cs
Normal file
18
ModernKeePass/ViewModels/RecentVm.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using ModernKeePass.Models;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace ModernKeePass.ViewModels
|
||||
{
|
||||
public class RecentVm : INotifyPropertyChanged
|
||||
{
|
||||
public ObservableCollection<RecentItem> RecentItems { get; set; }
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
public void NotifyPropertyChanged(string propertyName)
|
||||
{
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user