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:
Geoffroy BONNEVILLE
2020-04-06 20:20:45 +02:00
parent e795a8c3c4
commit 56d93a5187
292 changed files with 48614 additions and 837 deletions

View 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;
}
}
}

View 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;
}
}
}

View 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;
}
}
}
}

View 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)));
}
}
}

View 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;
}
}
}