mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
Create a shared project with all Win App common files (8.1 and 10)
Finally use the dependency injected Resource Service
This commit is contained in:
27
WinAppCommon/Actions/ClipboardAction.cs
Normal file
27
WinAppCommon/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 { return (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;
|
||||
}
|
||||
}
|
||||
}
|
33
WinAppCommon/Actions/NavigateToUrlAction.cs
Normal file
33
WinAppCommon/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 { return (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
WinAppCommon/Actions/SetupFocusAction.cs
Normal file
27
WinAppCommon/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 { return (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
WinAppCommon/Actions/ToastAction.cs
Normal file
33
WinAppCommon/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 { return (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 { return (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