mirror of
https://github.com/wismna/ModernKeePass.git
synced 2025-10-03 15:40:18 -04:00
New toast action to show toast messages from XAML
Code cleanup for Sonar Tests corrections
This commit is contained in:
33
ModernKeePass/Actions/ToastAction.cs
Normal file
33
ModernKeePass/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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -114,7 +114,8 @@ namespace ModernKeePass
|
||||
|
||||
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
|
||||
{
|
||||
//TODO: Load state from previously terminated application
|
||||
// Load state from previously terminated application
|
||||
await SuspensionManager.RestoreAsync();
|
||||
#if DEBUG
|
||||
await MessageDialogHelper.ShowNotificationDialog("App terminated", "Windows or an error made the app terminate");
|
||||
#endif
|
||||
@@ -164,7 +165,7 @@ namespace ModernKeePass
|
||||
/// <param name="e">Details about the navigation failure</param>
|
||||
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
|
||||
{
|
||||
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
|
||||
throw new NavigationException(e.SourcePageType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -174,7 +175,7 @@ namespace ModernKeePass
|
||||
/// </summary>
|
||||
/// <param name="sender">The source of the suspend request.</param>
|
||||
/// <param name="e">Details about the suspend request.</param>
|
||||
private void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
private async void OnSuspending(object sender, SuspendingEventArgs e)
|
||||
{
|
||||
var deferral = e.SuspendingOperation.GetDeferral();
|
||||
var database = DatabaseService.Instance;
|
||||
@@ -187,6 +188,7 @@ namespace ModernKeePass
|
||||
{
|
||||
ToastNotificationHelper.ShowErrorToast(exception);
|
||||
}
|
||||
await SuspensionManager.SaveAsync();
|
||||
deferral.Complete();
|
||||
}
|
||||
|
||||
|
@@ -17,7 +17,7 @@ namespace ModernKeePass.Common
|
||||
/// carry across sessions, but that should be discarded when an application crashes or is
|
||||
/// upgraded.
|
||||
/// </summary>
|
||||
internal sealed class SuspensionManager
|
||||
internal static class SuspensionManager
|
||||
{
|
||||
private static Dictionary<string, object> _sessionState = new Dictionary<string, object>();
|
||||
private static readonly List<Type> _knownTypes = new List<Type>();
|
||||
|
@@ -1,9 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace ModernKeePass.Exceptions
|
||||
{
|
||||
public class DatabaseOpenedException: Exception
|
||||
{
|
||||
|
||||
}
|
||||
}
|
11
ModernKeePass/Exceptions/NavigationException.cs
Normal file
11
ModernKeePass/Exceptions/NavigationException.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace ModernKeePass.Exceptions
|
||||
{
|
||||
public class NavigationException: Exception
|
||||
{
|
||||
public NavigationException(Type pageType) : base($"Failed to load Page {pageType.FullName}")
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@@ -111,11 +111,12 @@
|
||||
<Compile Include="Actions\ClipboardAction.cs" />
|
||||
<Compile Include="Actions\NavigateToUrlAction.cs" />
|
||||
<Compile Include="Actions\SetupFocusAction.cs" />
|
||||
<Compile Include="Actions\ToastAction.cs" />
|
||||
<Compile Include="App.xaml.cs">
|
||||
<DependentUpon>App.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Converters\IntToSymbolConverter.cs" />
|
||||
<Compile Include="Exceptions\DatabaseOpenedException.cs" />
|
||||
<Compile Include="Exceptions\NavigationException.cs" />
|
||||
<Compile Include="Interfaces\IProxyInvocationHandler.cs" />
|
||||
<Compile Include="Interfaces\IRecentService.cs" />
|
||||
<Compile Include="Interfaces\IRecentItem.cs" />
|
||||
|
@@ -294,4 +294,7 @@
|
||||
<data name="MessageDialogSaveErrorTitle" xml:space="preserve">
|
||||
<value>Save error</value>
|
||||
</data>
|
||||
<data name="ToastSavedMessage" xml:space="preserve">
|
||||
<value>Database successfully saved!</value>
|
||||
</data>
|
||||
</root>
|
@@ -387,4 +387,13 @@
|
||||
<data name="HistoryLeftListView.HeaderLabel" xml:space="preserve">
|
||||
<value>History</value>
|
||||
</data>
|
||||
<data name="ToastCopyLogin.Message" xml:space="preserve">
|
||||
<value>Login successfully copied!</value>
|
||||
</data>
|
||||
<data name="ToastCopyPassword.Message" xml:space="preserve">
|
||||
<value>Password successfully copied!</value>
|
||||
</data>
|
||||
<data name="ToastCopyUrl.Message" xml:space="preserve">
|
||||
<value>URL successfully copied!</value>
|
||||
</data>
|
||||
</root>
|
@@ -187,7 +187,7 @@
|
||||
<value>Attention</value>
|
||||
</data>
|
||||
<data name="EntityDeleting" xml:space="preserve">
|
||||
<value>Suprression</value>
|
||||
<value>Suppression</value>
|
||||
</data>
|
||||
<data name="EntityRestoredTitle" xml:space="preserve">
|
||||
<value>Restauré</value>
|
||||
@@ -208,10 +208,10 @@
|
||||
<value>Entrée replacée dans son groupe d'origine</value>
|
||||
</data>
|
||||
<data name="GroupDeleted" xml:space="preserve">
|
||||
<value>Groupe supprimé défnitivement</value>
|
||||
<value>Groupe supprimé définitivement</value>
|
||||
</data>
|
||||
<data name="GroupDeletingConfirmation" xml:space="preserve">
|
||||
<value>Êtes-vous sûr de vouloir supprimer ce group et toutes ses entrées ?</value>
|
||||
<value>Êtes-vous sûr de vouloir supprimer ce groupe et toutes ses entrées ?</value>
|
||||
</data>
|
||||
<data name="GroupRecycled" xml:space="preserve">
|
||||
<value>Groupe placé dans la Corbeille</value>
|
||||
@@ -294,4 +294,7 @@
|
||||
<data name="MessageDialogSaveErrorTitle" xml:space="preserve">
|
||||
<value>Erreur de sauvegarde</value>
|
||||
</data>
|
||||
<data name="ToastSavedMessage" xml:space="preserve">
|
||||
<value>Base de données sauvegardée avec succès !</value>
|
||||
</data>
|
||||
</root>
|
@@ -387,4 +387,13 @@
|
||||
<data name="HistoryLeftListView.HeaderLabel" xml:space="preserve">
|
||||
<value>Historique</value>
|
||||
</data>
|
||||
<data name="ToastCopyLogin.Message" xml:space="preserve">
|
||||
<value>Login copié avec succès !</value>
|
||||
</data>
|
||||
<data name="ToastCopyPassword.Message" xml:space="preserve">
|
||||
<value>Mot de passe copié avec succès !</value>
|
||||
</data>
|
||||
<data name="ToastCopyUrl.Message" xml:space="preserve">
|
||||
<value>URL copié avec succès !</value>
|
||||
</data>
|
||||
</root>
|
@@ -153,6 +153,7 @@
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="Click">
|
||||
<actions:ClipboardAction Text="{Binding UserName}" />
|
||||
<actions:ToastAction x:Uid="ToastCopyLogin" Title="{Binding Name}" />
|
||||
</core:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</MenuFlyoutItem>
|
||||
@@ -160,6 +161,7 @@
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="Click">
|
||||
<actions:ClipboardAction Text="{Binding Password}" />
|
||||
<actions:ToastAction x:Uid="ToastCopyPassword" Title="{Binding Name}" />
|
||||
</core:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</MenuFlyoutItem>
|
||||
@@ -167,6 +169,7 @@
|
||||
<interactivity:Interaction.Behaviors>
|
||||
<core:EventTriggerBehavior EventName="Click">
|
||||
<actions:NavigateToUrlAction Url="{Binding Url}" />
|
||||
<actions:ToastAction x:Uid="ToastCopyUrl" Title="{Binding Name}" />
|
||||
</core:EventTriggerBehavior>
|
||||
</interactivity:Interaction.Behaviors>
|
||||
</MenuFlyoutItem>
|
||||
|
@@ -103,6 +103,9 @@ namespace ModernKeePass.Views.UserControls
|
||||
async command =>
|
||||
{
|
||||
database.Save();
|
||||
ToastNotificationHelper.ShowGenericToast(
|
||||
database.Name,
|
||||
resource.GetResourceValue("ToastSavedMessage"));
|
||||
database.Close(false);
|
||||
await OpenDatabase(resource);
|
||||
},
|
||||
|
Reference in New Issue
Block a user