mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-04 08:00:16 -04:00
Moved application code to the Application layer
Imported Win10 project Code cleanup WIP - Use common UWP services for Win8.1 and Win10
This commit is contained in:
27
ModernKeePass10/Actions/ClipboardAction.cs
Normal file
27
ModernKeePass10/Actions/ClipboardAction.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Windows.ApplicationModel.DataTransfer;
|
||||
using Windows.UI.Xaml;
|
||||
using Microsoft.Xaml.Interactivity;
|
||||
|
||||
namespace ModernKeePass.Actions
|
||||
{
|
||||
public class ClipboardAction : DependencyObject, IAction
|
||||
{
|
||||
public string Text
|
||||
{
|
||||
get => (string)GetValue(TextProperty);
|
||||
set => SetValue(TextProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TextProperty =
|
||||
DependencyProperty.Register("Text", typeof(string), typeof(ClipboardAction), new PropertyMetadata(string.Empty));
|
||||
|
||||
public object Execute(object sender, object parameter)
|
||||
{
|
||||
if (string.IsNullOrEmpty(Text)) return null;
|
||||
var dataPackage = new DataPackage { RequestedOperation = DataPackageOperation.Copy };
|
||||
dataPackage.SetText(Text);
|
||||
Clipboard.SetContent(dataPackage);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
65
ModernKeePass10/Actions/DeleteEntityAction.cs
Normal file
65
ModernKeePass10/Actions/DeleteEntityAction.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System.Windows.Input;
|
||||
using Windows.UI.Xaml;
|
||||
using Autofac;
|
||||
using Microsoft.Xaml.Interactivity;
|
||||
using ModernKeePass.Common;
|
||||
using ModernKeePass.Domain.Entities;
|
||||
using ModernKeePass.Domain.Interfaces;
|
||||
|
||||
namespace ModernKeePass.Actions
|
||||
{
|
||||
public class DeleteEntityAction : DependencyObject, IAction
|
||||
{
|
||||
private readonly IResourceService _resourceService;
|
||||
private readonly IDatabaseService _databaseService;
|
||||
|
||||
public Entity Entity
|
||||
{
|
||||
get => (Entity)GetValue(EntityProperty);
|
||||
set => SetValue(EntityProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty EntityProperty =
|
||||
DependencyProperty.Register("Entity", typeof(Entity), typeof(DeleteEntityAction),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
public ICommand Command
|
||||
{
|
||||
get => (ICommand)GetValue(CommandProperty);
|
||||
set => SetValue(CommandProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CommandProperty =
|
||||
DependencyProperty.Register("Command", typeof(ICommand), typeof(DeleteEntityAction),
|
||||
new PropertyMetadata(null));
|
||||
|
||||
public DeleteEntityAction(): this(App.Container.Resolve<IResourceService>(), App.Container.Resolve<IDatabaseService>())
|
||||
{ }
|
||||
|
||||
public DeleteEntityAction(IResourceService resourceService, IDatabaseService databaseService)
|
||||
{
|
||||
_resourceService = resourceService;
|
||||
_databaseService = databaseService;
|
||||
}
|
||||
|
||||
public object Execute(object sender, object parameter)
|
||||
{
|
||||
var type = Entity is GroupEntity ? "Group" : "Entry";
|
||||
|
||||
var message = _databaseService.IsRecycleBinEnabled
|
||||
? _resourceService.GetResourceValue($"{type}RecyclingConfirmation")
|
||||
: _resourceService.GetResourceValue($"{type}DeletingConfirmation");
|
||||
var text = _databaseService.IsRecycleBinEnabled ? _resourceService.GetResourceValue($"{type}Recycled") : _resourceService.GetResourceValue($"{type}Deleted");
|
||||
MessageDialogHelper.ShowActionDialog(_resourceService.GetResourceValue("EntityDeleteTitle"), message,
|
||||
_resourceService.GetResourceValue("EntityDeleteActionButton"),
|
||||
_resourceService.GetResourceValue("EntityDeleteCancelButton"), a =>
|
||||
{
|
||||
ToastNotificationHelper.ShowMovedToast(Entity, _resourceService.GetResourceValue("EntityDeleting"), text);
|
||||
//Entity.MarkForDelete(_resourceService.GetResourceValue("RecycleBinTitle"));
|
||||
Command.Execute(null);
|
||||
}, null).GetAwaiter();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
33
ModernKeePass10/Actions/NavigateToUrlAction.cs
Normal file
33
ModernKeePass10/Actions/NavigateToUrlAction.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using Windows.UI.Xaml;
|
||||
using Microsoft.Xaml.Interactivity;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.Actions
|
||||
{
|
||||
public class NavigateToUrlAction : DependencyObject, IAction
|
||||
{
|
||||
public string Url
|
||||
{
|
||||
get => (string)GetValue(UrlProperty);
|
||||
set => SetValue(UrlProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty UrlProperty =
|
||||
DependencyProperty.Register("Url", typeof(string), typeof(NavigateToUrlAction), new PropertyMetadata(string.Empty));
|
||||
|
||||
public object Execute(object sender, object parameter)
|
||||
{
|
||||
try
|
||||
{
|
||||
var uri = new Uri(Url);
|
||||
return Windows.System.Launcher.LaunchUriAsync(uri).GetAwaiter().GetResult();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageDialogHelper.ShowErrorDialog(ex).GetAwaiter();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
ModernKeePass10/Actions/SetupFocusAction.cs
Normal file
27
ModernKeePass10/Actions/SetupFocusAction.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System.Threading.Tasks;
|
||||
using Windows.UI.Core;
|
||||
using Windows.UI.Xaml;
|
||||
using Windows.UI.Xaml.Controls;
|
||||
using Microsoft.Xaml.Interactivity;
|
||||
|
||||
namespace ModernKeePass.Actions
|
||||
{
|
||||
public class SetupFocusAction : DependencyObject, IAction
|
||||
{
|
||||
public Control TargetObject
|
||||
{
|
||||
get => (Control)GetValue(TargetObjectProperty);
|
||||
set => SetValue(TargetObjectProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TargetObjectProperty =
|
||||
DependencyProperty.Register("TargetObject", typeof(Control), typeof(SetupFocusAction), new PropertyMetadata(null));
|
||||
|
||||
public object Execute(object sender, object parameter)
|
||||
{
|
||||
return Task.Factory.StartNew(
|
||||
() => Dispatcher.RunAsync(CoreDispatcherPriority.Low,
|
||||
() => TargetObject?.Focus(FocusState.Programmatic)));
|
||||
}
|
||||
}
|
||||
}
|
33
ModernKeePass10/Actions/ToastAction.cs
Normal file
33
ModernKeePass10/Actions/ToastAction.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Windows.UI.Xaml;
|
||||
using Microsoft.Xaml.Interactivity;
|
||||
using ModernKeePass.Common;
|
||||
|
||||
namespace ModernKeePass.Actions
|
||||
{
|
||||
public class ToastAction : DependencyObject, IAction
|
||||
{
|
||||
public string Title
|
||||
{
|
||||
get => (string)GetValue(TitleProperty);
|
||||
set => SetValue(TitleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TitleProperty =
|
||||
DependencyProperty.Register("Title", typeof(string), typeof(ToastAction), new PropertyMetadata(string.Empty));
|
||||
|
||||
public string Message
|
||||
{
|
||||
get => (string)GetValue(MessageProperty);
|
||||
set => SetValue(MessageProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MessageProperty =
|
||||
DependencyProperty.Register("Message", typeof(string), typeof(ToastAction), new PropertyMetadata(string.Empty));
|
||||
|
||||
public object Execute(object sender, object parameter)
|
||||
{
|
||||
ToastNotificationHelper.ShowGenericToast(Title, Message);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user