mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
WIP Delete and restore entities as Actions
This commit is contained in:
54
ModernKeePass/Actions/DeleteEntityAction.cs
Normal file
54
ModernKeePass/Actions/DeleteEntityAction.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
46
ModernKeePass/Actions/RestoreEntityAction.cs
Normal file
46
ModernKeePass/Actions/RestoreEntityAction.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -109,7 +109,9 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="Actions\ClipboardAction.cs" />
|
<Compile Include="Actions\ClipboardAction.cs" />
|
||||||
|
<Compile Include="Actions\DeleteEntityAction.cs" />
|
||||||
<Compile Include="Actions\NavigateToUrlAction.cs" />
|
<Compile Include="Actions\NavigateToUrlAction.cs" />
|
||||||
|
<Compile Include="Actions\RestoreEntityAction.cs" />
|
||||||
<Compile Include="Actions\SetupFocusAction.cs" />
|
<Compile Include="Actions\SetupFocusAction.cs" />
|
||||||
<Compile Include="Actions\ToastAction.cs" />
|
<Compile Include="Actions\ToastAction.cs" />
|
||||||
<Compile Include="App.xaml.cs">
|
<Compile Include="App.xaml.cs">
|
||||||
|
@@ -402,8 +402,20 @@
|
|||||||
</core:EventTriggerBehavior>
|
</core:EventTriggerBehavior>
|
||||||
</interactivity:Interaction.Behaviors>
|
</interactivity:Interaction.Behaviors>
|
||||||
</AppBarToggleButton>
|
</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="Undo" x:Uid="AppBarRestore" Visibility="{Binding ParentGroup.IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Command="{Binding UndoDeleteCommand}">
|
||||||
<AppBarButton Icon="Delete" x:Uid="AppBarDelete" Click="DeleteButton_Click" />
|
<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>
|
</CommandBar>
|
||||||
</Page.BottomAppBar>
|
</Page.BottomAppBar>
|
||||||
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
|
||||||
|
@@ -55,30 +55,6 @@ namespace ModernKeePass.Views
|
|||||||
|
|
||||||
#endregion
|
#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)
|
private void EntryDetailPage_OnSizeChanged(object sender, SizeChangedEventArgs e)
|
||||||
{
|
{
|
||||||
VisualStateManager.GoToState(this, e.NewSize.Width < 700 ? "Small" : "Large", true);
|
VisualStateManager.GoToState(this, e.NewSize.Width < 700 ? "Small" : "Large", true);
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
|
||||||
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
|
||||||
xmlns:actions="using:ModernKeePass.Actions"
|
xmlns:actions="using:ModernKeePass.Actions"
|
||||||
xmlns:templateSelectors="using:ModernKeePass.TemplateSelectors"
|
|
||||||
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
xmlns:userControls="using:ModernKeePass.Views.UserControls"
|
||||||
x:Name="PageRoot"
|
x:Name="PageRoot"
|
||||||
x:Class="ModernKeePass.Views.GroupDetailPage"
|
x:Class="ModernKeePass.Views.GroupDetailPage"
|
||||||
@@ -64,15 +63,24 @@
|
|||||||
</core:EventTriggerBehavior>
|
</core:EventTriggerBehavior>
|
||||||
</interactivity:Interaction.Behaviors>
|
</interactivity:Interaction.Behaviors>
|
||||||
</AppBarToggleButton>
|
</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="Undo" x:Uid="AppBarRestore" Visibility="{Binding ShowRestore, Converter={StaticResource BooleanToVisibilityConverter}}" IsEnabled="{Binding PreviousGroup, Converter={StaticResource NullToBooleanConverter}}" Command="{Binding UndoDeleteCommand}">
|
||||||
<AppBarButton Icon="Delete" x:Uid="AppBarDelete" IsEnabled="{Binding IsNotRoot}" Visibility="{Binding IsSelected, Converter={StaticResource InverseBooleanToVisibilityConverter}}" Click="DeleteButton_Click" />
|
<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>
|
</CommandBar>
|
||||||
</Page.BottomAppBar>
|
</Page.BottomAppBar>
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Resources>
|
<Grid.Resources>
|
||||||
<CollectionViewSource
|
|
||||||
x:Name="GroupsViewSource"
|
|
||||||
Source="{Binding Groups}" />
|
|
||||||
<CollectionViewSource
|
<CollectionViewSource
|
||||||
x:Name="EntriesViewSource"
|
x:Name="EntriesViewSource"
|
||||||
Source="{Binding Entries}" />
|
Source="{Binding Entries}" />
|
||||||
|
@@ -97,31 +97,6 @@ namespace ModernKeePass.Views
|
|||||||
Frame.Navigate(typeof(EntryDetailPage), entry);
|
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)
|
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
|
// We need to synchronize the two lists (zoomed-in and zoomed-out) because the source is different
|
||||||
|
Reference in New Issue
Block a user