diff --git a/ModernKeePass/Actions/DeleteEntityAction.cs b/ModernKeePass/Actions/DeleteEntityAction.cs new file mode 100644 index 0000000..a927077 --- /dev/null +++ b/ModernKeePass/Actions/DeleteEntityAction.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/ModernKeePass/Actions/RestoreEntityAction.cs b/ModernKeePass/Actions/RestoreEntityAction.cs new file mode 100644 index 0000000..f627001 --- /dev/null +++ b/ModernKeePass/Actions/RestoreEntityAction.cs @@ -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; + } + } +} \ No newline at end of file diff --git a/ModernKeePass/ModernKeePass.App.csproj b/ModernKeePass/ModernKeePass.App.csproj index 2f71684..944281b 100644 --- a/ModernKeePass/ModernKeePass.App.csproj +++ b/ModernKeePass/ModernKeePass.App.csproj @@ -109,7 +109,9 @@ + + diff --git a/ModernKeePass/Views/EntryDetailPage.xaml b/ModernKeePass/Views/EntryDetailPage.xaml index bb422a8..9ba61d2 100644 --- a/ModernKeePass/Views/EntryDetailPage.xaml +++ b/ModernKeePass/Views/EntryDetailPage.xaml @@ -402,8 +402,20 @@ - - + + + + + + + + + + + + + + diff --git a/ModernKeePass/Views/EntryDetailPage.xaml.cs b/ModernKeePass/Views/EntryDetailPage.xaml.cs index 3521112..a3b675d 100644 --- a/ModernKeePass/Views/EntryDetailPage.xaml.cs +++ b/ModernKeePass/Views/EntryDetailPage.xaml.cs @@ -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); diff --git a/ModernKeePass/Views/GroupDetailPage.xaml b/ModernKeePass/Views/GroupDetailPage.xaml index 51ad55d..70f929d 100644 --- a/ModernKeePass/Views/GroupDetailPage.xaml +++ b/ModernKeePass/Views/GroupDetailPage.xaml @@ -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 @@ - - + + + + + + + + + + + + + + - diff --git a/ModernKeePass/Views/GroupDetailPage.xaml.cs b/ModernKeePass/Views/GroupDetailPage.xaml.cs index 18e4adf..1ae9fec 100644 --- a/ModernKeePass/Views/GroupDetailPage.xaml.cs +++ b/ModernKeePass/Views/GroupDetailPage.xaml.cs @@ -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