Recycle bin is now created when deleting first element instead of selecting new group in Settings

This commit is contained in:
bg45
2017-11-01 17:35:57 -04:00
committed by BONNEVILLE Geoffroy
parent 7e642e3b73
commit 82ef424365
5 changed files with 17 additions and 6 deletions

View File

@@ -1,6 +1,7 @@
using System; using System;
using Windows.Storage; using Windows.Storage;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using ModernKeePass.ViewModels; using ModernKeePass.ViewModels;
using ModernKeePassLib; using ModernKeePassLib;
using ModernKeePassLib.Interfaces; using ModernKeePassLib.Interfaces;
@@ -129,5 +130,12 @@ namespace ModernKeePass.Common
{ {
_pwDatabase.DeletedObjects.Add(new PwDeletedObject(id, DateTime.UtcNow)); _pwDatabase.DeletedObjects.Add(new PwDeletedObject(id, DateTime.UtcNow));
} }
public void CreateRecycleBin()
{
RecycleBin = RootGroup.AddNewGroup("Recycle bin");
RecycleBin.IsSelected = true;
RecycleBin.IconSymbol = Symbol.Delete;
}
} }
} }

View File

@@ -27,7 +27,7 @@
</TransitionCollection> </TransitionCollection>
</Grid.ChildrenTransitions> </Grid.ChildrenTransitions>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="40"/> <RowDefinition Height="50"/>
<RowDefinition Height="*"/> <RowDefinition Height="*"/>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
@@ -43,7 +43,7 @@
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<Button x:Name="BackButton" <Button x:Name="BackButton"
Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}" Command="{Binding NavigationHelper.GoBackCommand, ElementName=PageRoot}"
Height="40" Height="50"
AutomationProperties.Name="Back" AutomationProperties.Name="Back"
AutomationProperties.AutomationId="BackButton" AutomationProperties.AutomationId="BackButton"
AutomationProperties.ItemType="Navigation Button" AutomationProperties.ItemType="Navigation Button"

View File

@@ -14,7 +14,6 @@
<viewModels:SettingsDatabaseVm /> <viewModels:SettingsDatabaseVm />
</Page.DataContext> </Page.DataContext>
<StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <StackPanel Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ToggleSwitch Header="Recycle bin" OffContent="Disabled" OnContent="Enabled" IsOn="{Binding HasRecycleBin, Mode=TwoWay}" /> <ToggleSwitch Header="Recycle bin" OffContent="Disabled" OnContent="Enabled" IsOn="{Binding HasRecycleBin, Mode=TwoWay}" />
<ComboBox ItemsSource="{Binding Source={StaticResource RecycleBinGroups}}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" IsEnabled="{Binding HasRecycleBin}" /> <ComboBox ItemsSource="{Binding Source={StaticResource RecycleBinGroups}}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" IsEnabled="{Binding HasRecycleBin}" />

View File

@@ -196,6 +196,8 @@ namespace ModernKeePass.ViewModels
public void MarkForDelete() public void MarkForDelete()
{ {
if (_app.Database.RecycleBinEnabled && _app.Database.RecycleBin?.IdUuid == null)
_app.Database.CreateRecycleBin();
Move(_app.Database.RecycleBinEnabled && !ParentGroup.IsSelected ? _app.Database.RecycleBin : null); Move(_app.Database.RecycleBinEnabled && !ParentGroup.IsSelected ? _app.Database.RecycleBin : null);
} }

View File

@@ -32,16 +32,16 @@ namespace ModernKeePass.ViewModels
/// </summary> /// </summary>
public bool IsSelected public bool IsSelected
{ {
get { return _app.Database.RecycleBinEnabled && _app.Database.RecycleBin.Id == Id; } get { return _app.Database.RecycleBinEnabled && _app.Database.RecycleBin?.Id == Id; }
set set
{ {
if (value && _pwGroup != null) _app.Database.RecycleBin = this; if (value && _pwGroup != null) _app.Database.RecycleBin = this;
else if (value && _pwGroup == null) /*else if (value && _pwGroup == null)
{ {
var recycleBin = _app.Database.RootGroup.AddNewGroup("Recycle bin"); var recycleBin = _app.Database.RootGroup.AddNewGroup("Recycle bin");
recycleBin.IsSelected = true; recycleBin.IsSelected = true;
recycleBin.IconSymbol = Symbol.Delete; recycleBin.IconSymbol = Symbol.Delete;
} }*/
} }
} }
@@ -133,6 +133,8 @@ namespace ModernKeePass.ViewModels
public void MarkForDelete() public void MarkForDelete()
{ {
if (_app.Database.RecycleBinEnabled && _app.Database.RecycleBin?.IdUuid == null)
_app.Database.CreateRecycleBin();
Move(_app.Database.RecycleBinEnabled && !IsSelected ? _app.Database.RecycleBin : null); Move(_app.Database.RecycleBinEnabled && !IsSelected ? _app.Database.RecycleBin : null);
} }