Sorting now works for entries (not yet for groups)

This commit is contained in:
BONNEVILLE Geoffroy
2017-11-30 11:05:47 +01:00
parent f2731c49dd
commit 33223934e3
7 changed files with 48 additions and 17 deletions

View File

@@ -394,11 +394,11 @@
</AppBarButton>
</CommandBar.SecondaryCommands>
<AppBarToggleButton Icon="Edit" Label="Edit" IsChecked="{Binding IsEditMode, Mode=TwoWay}">
<interactivity:Interaction.Behaviors>
<!--<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:ChangePropertyAction TargetObject="{Binding ElementName=CommandBar}" PropertyName="IsOpen" Value="False" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</interactivity:Interaction.Behaviors>-->
</AppBarToggleButton>
<AppBarButton Icon="Undo" Label="Restore" Visibility="{Binding ParentGroup.IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Click="RestoreButton_Click">
<interactivity:Interaction.Behaviors>

View File

@@ -44,18 +44,31 @@
</AppBarButton>
</CommandBar.SecondaryCommands>
<AppBarButton Icon="Sort" Label="Sort" Visibility="{Binding IsEditMode, Converter={StaticResource BooleanToVisibilityConverter}}">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:CallMethodAction MethodName="SortEntries" TargetObject="{Binding}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem x:Uid="AppBarSortEntries">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:CallMethodAction MethodName="SortEntries" TargetObject="{Binding}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</MenuFlyoutItem>
<MenuFlyoutItem x:Uid="AppBarSortGroups">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:CallMethodAction MethodName="SortGroups" TargetObject="{Binding}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</MenuFlyoutItem>
</MenuFlyout>
</Button.Flyout>
</AppBarButton>
<AppBarToggleButton Icon="Edit" Label="Edit" IsChecked="{Binding IsEditMode, Mode=TwoWay}">
<interactivity:Interaction.Behaviors>
<!--<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<core:ChangePropertyAction TargetObject="{Binding ElementName=CommandBar}" PropertyName="IsOpen" Value="False" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</interactivity:Interaction.Behaviors>-->
</AppBarToggleButton>
<AppBarButton Icon="Undo" Label="Restore" Visibility="{Binding ShowRestore, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Click="RestoreButton_Click">
<interactivity:Interaction.Behaviors>

View File

@@ -132,6 +132,12 @@
<data name="AboutHomepage.Text" xml:space="preserve">
<value>Homepage:</value>
</data>
<data name="AppBarSortEntries.Text" xml:space="preserve">
<value>Entries</value>
</data>
<data name="AppBarSortGroups.Text" xml:space="preserve">
<value>Groups</value>
</data>
<data name="CompositeKeyNewKeyFileTooltip.Content" xml:space="preserve">
<value>Create new key file</value>
</data>

View File

@@ -183,12 +183,26 @@ namespace ModernKeePass.ViewModels
public void SortEntries()
{
var comparer = new PwEntryComparer(PwDefs.TitleField, true, true);
var comparer = new PwEntryComparer(PwDefs.TitleField, true, false);
try
{
// TODO: this throws an exception
_pwGroup.Entries.Sort(comparer);
Entries = new ObservableCollection<EntryVm>(Entries.OrderBy(e => e.Name));
OnPropertyChanged("Entries");
}
catch (Exception e)
{
MessageDialogService.ShowErrorDialog(e);
}
}
public void SortGroups()
{
try
{
_pwGroup.SortSubGroups(false);
Groups = new ObservableCollection<GroupVm>(Groups.Skip(1).OrderBy(g => g.Name));
OnPropertyChanged("Groups");
}
catch (Exception e)
{