Entries and groups icons are now handled with int

Static mapping is changed to a converter
This commit is contained in:
BONNEVILLE Geoffroy
2018-06-14 10:20:00 +02:00
parent cc65c56042
commit 8a5db88225
7 changed files with 28 additions and 29 deletions

View File

@@ -1,12 +1,15 @@
using Windows.UI.Xaml.Controls; using System;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;
using ModernKeePassLib; using ModernKeePassLib;
namespace ModernKeePass.Mappings namespace ModernKeePass.Converters
{ {
public static class PwIconToSegoeMapping public class IntToSymbolConverter : IValueConverter
{ {
public static Symbol GetSymbolFromIcon(PwIcon icon) public object Convert(object value, Type targetType, object parameter, string language)
{ {
var icon = (PwIcon) value;
switch (icon) switch (icon)
{ {
case PwIcon.Key: return Symbol.Permissions; case PwIcon.Key: return Symbol.Permissions;
@@ -79,8 +82,9 @@ namespace ModernKeePass.Mappings
} }
} }
public static PwIcon GetIconFromSymbol(Symbol symbol) public object ConvertBack(object value, Type targetType, object parameter, string language)
{ {
var symbol = (Symbol) value;
switch (symbol) switch (symbol)
{ {
/*case Symbol.Previous: /*case Symbol.Previous:

View File

@@ -1,4 +1,4 @@
using Windows.UI.Xaml.Controls; using System.Collections.Generic;
using ModernKeePass.ViewModels; using ModernKeePass.ViewModels;
namespace ModernKeePass.Interfaces namespace ModernKeePass.Interfaces
@@ -7,9 +7,10 @@ namespace ModernKeePass.Interfaces
{ {
GroupVm ParentGroup { get; } GroupVm ParentGroup { get; }
GroupVm PreviousGroup { get; } GroupVm PreviousGroup { get; }
Symbol IconSymbol { get; } int IconId { get; }
string Id { get; } string Id { get; }
string Name { get; set; } string Name { get; set; }
IEnumerable<IPwEntity> BreadCrumb { get; }
bool IsEditMode { get; } bool IsEditMode { get; }
bool IsRecycleOnDelete { get; } bool IsRecycleOnDelete { get; }

View File

@@ -114,6 +114,7 @@
<Compile Include="App.xaml.cs"> <Compile Include="App.xaml.cs">
<DependentUpon>App.xaml</DependentUpon> <DependentUpon>App.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Converters\IntToSymbolConverter.cs" />
<Compile Include="Exceptions\DatabaseOpenedException.cs" /> <Compile Include="Exceptions\DatabaseOpenedException.cs" />
<Compile Include="Interfaces\ILicenseService.cs" /> <Compile Include="Interfaces\ILicenseService.cs" />
<Compile Include="Interfaces\IProxyInvocationHandler.cs" /> <Compile Include="Interfaces\IProxyInvocationHandler.cs" />
@@ -185,7 +186,6 @@
<Compile Include="Views\MainPage.xaml.cs"> <Compile Include="Views\MainPage.xaml.cs">
<DependentUpon>MainPage.xaml</DependentUpon> <DependentUpon>MainPage.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="Mappings\PwIconToSegoeMapping.cs" />
<Compile Include="Views\MainPageFrames\AboutPage.xaml.cs"> <Compile Include="Views\MainPageFrames\AboutPage.xaml.cs">
<DependentUpon>AboutPage.xaml</DependentUpon> <DependentUpon>AboutPage.xaml</DependentUpon>
</Compile> </Compile>

View File

@@ -224,7 +224,7 @@ namespace ModernKeePass.Services
{ {
RecycleBin = RootGroup.AddNewGroup(title); RecycleBin = RootGroup.AddNewGroup(title);
RecycleBin.IsSelected = true; RecycleBin.IsSelected = true;
RecycleBin.IconSymbol = Symbol.Delete; RecycleBin.IconId = (int)PwIcon.TrashBin;
} }
private void CreateSampleData() private void CreateSampleData()

View File

@@ -1,9 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Interfaces; using ModernKeePass.Interfaces;
using ModernKeePass.Mappings;
using ModernKeePass.Services; using ModernKeePass.Services;
using ModernKeePassLib; using ModernKeePassLib;
using ModernKeePassLib.Cryptography.PasswordGenerator; using ModernKeePassLib.Cryptography.PasswordGenerator;
@@ -79,14 +77,12 @@ namespace ModernKeePass.ViewModels
set { SetEntryValue(PwDefs.NotesField, value); } set { SetEntryValue(PwDefs.NotesField, value); }
} }
public Symbol IconSymbol public int IconId
{ {
get get
{ {
if (_pwEntry == null) return Symbol.Add; if (_pwEntry?.IconId != null) return (int) _pwEntry?.IconId;
if (HasExpired) return Symbol.Priority; return -1;
var result = PwIconToSegoeMapping.GetSymbolFromIcon(_pwEntry.IconId);
return result == Symbol.More ? Symbol.Permissions : result;
} }
} }

View File

@@ -3,11 +3,8 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Linq; using System.Linq;
using System.Text;
using Windows.UI.Xaml.Controls;
using ModernKeePass.Common; using ModernKeePass.Common;
using ModernKeePass.Interfaces; using ModernKeePass.Interfaces;
using ModernKeePass.Mappings;
using ModernKeePass.Services; using ModernKeePass.Services;
using ModernKeePassLib; using ModernKeePassLib;
@@ -71,14 +68,14 @@ namespace ModernKeePass.ViewModels
set { _pwGroup.Name = value; } set { _pwGroup.Name = value; }
} }
public Symbol IconSymbol public int IconId
{ {
get get
{ {
var result = PwIconToSegoeMapping.GetSymbolFromIcon(_pwGroup.IconId); if (_pwGroup?.IconId != null) return (int) _pwGroup?.IconId;
return result == Symbol.More ? Symbol.Folder : result; return -1;
} }
set { _pwGroup.IconId = PwIconToSegoeMapping.GetIconFromSymbol(value); } set { _pwGroup.IconId = (PwIcon)value; }
} }
public bool IsEditMode public bool IsEditMode

View File

@@ -19,6 +19,7 @@
<converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/> <converters:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
<converters:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter"/> <converters:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter"/>
<converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/> <converters:NullToBooleanConverter x:Key="NullToBooleanConverter"/>
<converters:IntToSymbolConverter x:Key="IntToSymbolConverter"/>
</Page.Resources> </Page.Resources>
<Page.DataContext> <Page.DataContext>
<viewModels:GroupVm /> <viewModels:GroupVm />
@@ -128,7 +129,7 @@
<ListView.Resources> <ListView.Resources>
<DataTemplate x:Name="IsRecycleBin"> <DataTemplate x:Name="IsRecycleBin">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<SymbolIcon Symbol="{Binding IconSymbol}" Margin="8,0,0,0"> <SymbolIcon Symbol="{Binding IconId, Converter={StaticResource IntToSymbolConverter}}" Margin="8,0,0,0">
<ToolTipService.ToolTip> <ToolTipService.ToolTip>
<ToolTip Content="{Binding Name}" /> <ToolTip Content="{Binding Name}" />
</ToolTipService.ToolTip> </ToolTipService.ToolTip>
@@ -138,7 +139,7 @@
</DataTemplate> </DataTemplate>
<DataTemplate x:Name="IsNotRecycleBin"> <DataTemplate x:Name="IsNotRecycleBin">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<SymbolIcon Symbol="{Binding IconSymbol}" Margin="8,0,0,0"> <SymbolIcon Symbol="{Binding IconId, Converter={StaticResource IntToSymbolConverter}}" Margin="8,0,0,0">
<ToolTipService.ToolTip> <ToolTipService.ToolTip>
<ToolTip Content="{Binding Name}" /> <ToolTip Content="{Binding Name}" />
</ToolTipService.ToolTip> </ToolTipService.ToolTip>
@@ -237,7 +238,7 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Border Grid.Column="0" Background="{Binding BackgroundColor, ConverterParameter={StaticResource MainColor}, Converter={StaticResource ColorToBrushConverter}}"> <Border Grid.Column="0" Background="{Binding BackgroundColor, ConverterParameter={StaticResource MainColor}, Converter={StaticResource ColorToBrushConverter}}">
<Viewbox MaxHeight="50" Width="100"> <Viewbox MaxHeight="50" Width="100">
<SymbolIcon Symbol="{Binding IconSymbol}" Foreground="{StaticResource TextColor}" /> <SymbolIcon Symbol="{Binding IconId, Converter={StaticResource IntToSymbolConverter}}" Foreground="{StaticResource TextColor}" />
</Viewbox> </Viewbox>
</Border> </Border>
<StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="10,10,0,0" > <StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="10,10,0,0" >