WIP Delete and restore entities as Actions

This commit is contained in:
BONNEVILLE Geoffroy
2018-06-21 18:40:44 +02:00
parent d533abada5
commit a6f82b4541
7 changed files with 131 additions and 58 deletions

View File

@@ -0,0 +1,54 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Microsoft.Xaml.Interactivity;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
using ModernKeePass.ViewModels;
namespace ModernKeePass.Actions
{
public class DeleteEntityAction : DependencyObject, IAction
{
public IPwEntity Entity
{
get { return (IPwEntity)GetValue(EntityProperty); }
set { SetValue(EntityProperty, value); }
}
public static readonly DependencyProperty EntityProperty =
DependencyProperty.Register("Entity", typeof(IPwEntity), typeof(DeleteEntityAction),
new PropertyMetadata(null));
public Frame Frame
{
get { return (Frame)GetValue(FrameProperty); }
set { SetValue(FrameProperty, value); }
}
public static readonly DependencyProperty FrameProperty =
DependencyProperty.Register("Frame", typeof(Frame), typeof(DeleteEntityAction),
new PropertyMetadata(null));
public object Execute(object sender, object parameter)
{
var resource = new ResourcesService();
var type = Entity is GroupVm ? "Group" : "Entry";
var message = Entity.IsRecycleOnDelete
? resource.GetResourceValue($"{type}RecyclingConfirmation")
: resource.GetResourceValue($"{type}DeletingConfirmation");
var text = Entity.IsRecycleOnDelete ? resource.GetResourceValue($"{type}Recycled") : resource.GetResourceValue($"{type}Deleted");
MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
resource.GetResourceValue("EntityDeleteActionButton"),
resource.GetResourceValue("EntityDeleteCancelButton"), a =>
{
ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityDeleting"), text);
Entity.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
if (Frame.CanGoBack) Frame.GoBack();
}, null).GetAwaiter();
return null;
}
}
}

View File

@@ -0,0 +1,46 @@
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Microsoft.Xaml.Interactivity;
using ModernKeePass.Common;
using ModernKeePass.Interfaces;
using ModernKeePass.Services;
using ModernKeePass.ViewModels;
namespace ModernKeePass.Actions
{
public class RestoreEntityAction : DependencyObject, IAction
{
public IPwEntity Entity
{
get { return (IPwEntity)GetValue(EntityProperty); }
set { SetValue(EntityProperty, value); }
}
public static readonly DependencyProperty EntityProperty =
DependencyProperty.Register("Entity", typeof(IPwEntity), typeof(RestoreEntityAction),
new PropertyMetadata(null));
public Frame Frame
{
get { return (Frame)GetValue(FrameProperty); }
set { SetValue(FrameProperty, value); }
}
public static readonly DependencyProperty FrameProperty =
DependencyProperty.Register("Frame", typeof(Frame), typeof(RestoreEntityAction),
new PropertyMetadata(null));
public object Execute(object sender, object parameter)
{
var resource = new ResourcesService();
var type = Entity is GroupVm ? "Group" : "Entry";
ToastNotificationHelper.ShowMovedToast(Entity, resource.GetResourceValue("EntityRestoredTitle"),
resource.GetResourceValue($"{type}Restored"));
if (Frame.CanGoBack) Frame.GoBack();
return null;
}
}
}

View File

@@ -109,7 +109,9 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="Actions\ClipboardAction.cs" />
<Compile Include="Actions\DeleteEntityAction.cs" />
<Compile Include="Actions\NavigateToUrlAction.cs" />
<Compile Include="Actions\RestoreEntityAction.cs" />
<Compile Include="Actions\SetupFocusAction.cs" />
<Compile Include="Actions\ToastAction.cs" />
<Compile Include="App.xaml.cs">

View File

@@ -402,8 +402,20 @@
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</AppBarToggleButton>
<AppBarButton Icon="Undo" x:Uid="AppBarRestore" Visibility="{Binding ParentGroup.IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Click="RestoreButton_Click" Command="{Binding UndoDeleteCommand}" />
<AppBarButton Icon="Delete" x:Uid="AppBarDelete" Click="DeleteButton_Click" />
<AppBarButton Icon="Undo" x:Uid="AppBarRestore" Visibility="{Binding ParentGroup.IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Command="{Binding UndoDeleteCommand}">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<actions:RestoreEntityAction Entity="{Binding}" Frame="{Binding Frame, ElementName=PageRoot}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</AppBarButton>
<AppBarButton Icon="Delete" x:Uid="AppBarDelete">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<actions:DeleteEntityAction Entity="{Binding}" Frame="{Binding Frame, ElementName=PageRoot}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</AppBarButton>
</CommandBar>
</Page.BottomAppBar>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

View File

@@ -55,30 +55,6 @@ namespace ModernKeePass.Views
#endregion
private async void DeleteButton_Click(object sender, RoutedEventArgs e)
{
var resource = new ResourcesService();
var message = Model.IsRecycleOnDelete
? resource.GetResourceValue("EntryRecyclingConfirmation")
: resource.GetResourceValue("EntryDeletingConfirmation");
var text = Model.IsRecycleOnDelete ? resource.GetResourceValue("EntryRecycled") : resource.GetResourceValue("EntryDeleted");
await MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
resource.GetResourceValue("EntityDeleteActionButton"),
resource.GetResourceValue("EntityDeleteCancelButton"), a =>
{
ToastNotificationHelper.ShowMovedToast(Model, resource.GetResourceValue("EntityDeleting"), text);
Model.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
if (Frame.CanGoBack) Frame.GoBack();
}, null);
}
private void RestoreButton_Click(object sender, RoutedEventArgs e)
{
var resource = new ResourcesService();
ToastNotificationHelper.ShowMovedToast(Model, resource.GetResourceValue("EntityRestoredTitle"), resource.GetResourceValue("EntryRestored"));
if (Frame.CanGoBack) Frame.GoBack();
}
private void EntryDetailPage_OnSizeChanged(object sender, SizeChangedEventArgs e)
{
VisualStateManager.GoToState(this, e.NewSize.Width < 700 ? "Small" : "Large", true);

View File

@@ -8,7 +8,6 @@
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
xmlns:actions="using:ModernKeePass.Actions"
xmlns:templateSelectors="using:ModernKeePass.TemplateSelectors"
xmlns:userControls="using:ModernKeePass.Views.UserControls"
x:Name="PageRoot"
x:Class="ModernKeePass.Views.GroupDetailPage"
@@ -64,15 +63,24 @@
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</AppBarToggleButton>
<AppBarButton Icon="Undo" x:Uid="AppBarRestore" Visibility="{Binding ShowRestore, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Click="RestoreButton_Click" Command="{Binding UndoDeleteCommand}" />
<AppBarButton Icon="Delete" x:Uid="AppBarDelete" IsEnabled="{Binding IsNotRoot}" Visibility="{Binding IsSelected, Converter={StaticResource InverseBooleanToVisibilityConverter}}" Click="DeleteButton_Click" />
<AppBarButton Icon="Undo" x:Uid="AppBarRestore" Visibility="{Binding ShowRestore, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Command="{Binding UndoDeleteCommand}">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<actions:RestoreEntityAction Entity="{Binding}" Frame="{Binding Frame, ElementName=PageRoot}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</AppBarButton>
<AppBarButton Icon="Delete" x:Uid="AppBarDelete" IsEnabled="{Binding IsNotRoot}" Visibility="{Binding IsSelected, Converter={StaticResource InverseBooleanToVisibilityConverter}}">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="Click">
<actions:DeleteEntityAction Entity="{Binding}" Frame="{Binding Frame, ElementName=PageRoot}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</AppBarButton>
</CommandBar>
</Page.BottomAppBar>
<Grid>
<Grid.Resources>
<CollectionViewSource
x:Name="GroupsViewSource"
Source="{Binding Groups}" />
<CollectionViewSource
x:Name="EntriesViewSource"
Source="{Binding Entries}" />

View File

@@ -96,32 +96,7 @@ namespace ModernKeePass.Views
}
Frame.Navigate(typeof(EntryDetailPage), entry);
}
private async void DeleteButton_Click(object sender, RoutedEventArgs e)
{
var resource = new ResourcesService();
var message = Model.IsRecycleOnDelete
? resource.GetResourceValue("GroupRecyclingConfirmation")
: resource.GetResourceValue("GroupDeletingConfirmation");
var text = Model.IsRecycleOnDelete ? resource.GetResourceValue("GroupRecycled") : resource.GetResourceValue("GroupDeleted");
await MessageDialogHelper.ShowActionDialog(resource.GetResourceValue("EntityDeleteTitle"), message,
resource.GetResourceValue("EntityDeleteActionButton"),
resource.GetResourceValue("EntityDeleteCancelButton"), a =>
{
ToastNotificationHelper.ShowMovedToast(Model, resource.GetResourceValue("EntityDeleting"), text);
Model.MarkForDelete(resource.GetResourceValue("RecycleBinTitle"));
if (Frame.CanGoBack) Frame.GoBack();
}, null);
}
private void RestoreButton_Click(object sender, RoutedEventArgs e)
{
var resource = new ResourcesService();
ToastNotificationHelper.ShowMovedToast(Model, resource.GetResourceValue("EntityRestoredTitle"),
resource.GetResourceValue("GroupRestored"));
if (Frame.CanGoBack) Frame.GoBack();
}
private void SemanticZoom_ViewChangeStarted(object sender, SemanticZoomViewChangedEventArgs e)
{
// We need to synchronize the two lists (zoomed-in and zoomed-out) because the source is different