81 lines
2.5 KiB
C#
81 lines
2.5 KiB
C#
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using Livia.Utility.DependencyInjection;
|
|
using Livia.Views.Utility;
|
|
using MaterialDesignThemes.Wpf;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace Livia.Views;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for WarningDialog.xaml
|
|
/// </summary>
|
|
|
|
public partial class WarningDialog
|
|
{
|
|
private readonly bool _waitForResponse;
|
|
private readonly ILogger _logger;
|
|
|
|
public WarningDialog(WarningWindowKind kind, string message, bool waitForResponse)
|
|
{
|
|
_waitForResponse = waitForResponse;
|
|
InitializeComponent();
|
|
_logger = ActivatorUtilities.GetServiceOrCreateInstance<ILogger>(ServiceProviderFactory.ServiceProvider);
|
|
MessageTextBlock.Text = message;
|
|
string title;
|
|
|
|
switch (kind)
|
|
{
|
|
case WarningWindowKind.Confirmation:
|
|
title = (string)Application.Current.TryFindResource("Confirm");
|
|
DialogIcon.Kind = PackIconKind.InfoCircleOutline;
|
|
DialogIcon.Foreground = new SolidColorBrush(Color.FromRgb(211, 47, 47));
|
|
CancelButton.Visibility = Visibility.Visible;
|
|
break;
|
|
case WarningWindowKind.Info:
|
|
title = (string)Application.Current.TryFindResource("Info");
|
|
DialogIcon.Kind = PackIconKind.InfoCircleOutline;
|
|
break;
|
|
case WarningWindowKind.Warning:
|
|
title = (string)Application.Current.TryFindResource("Warning");
|
|
DialogIcon.Kind = PackIconKind.AlertOctagonOutline;
|
|
break;
|
|
case WarningWindowKind.Error:
|
|
default:
|
|
title = (string)Application.Current.TryFindResource("Error");
|
|
DialogIcon.Kind = PackIconKind.AlertOutline;
|
|
break;
|
|
}
|
|
|
|
Title = title;
|
|
TitleTextBlock.Text = title;
|
|
}
|
|
|
|
private void ConfirmButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_waitForResponse)
|
|
DialogResult = true;
|
|
Close();
|
|
}
|
|
|
|
private void CancelButtonClick(object sender, RoutedEventArgs e)
|
|
{
|
|
if (_waitForResponse)
|
|
DialogResult = false;
|
|
Close();
|
|
}
|
|
|
|
private void TitleBarMouseLeftButtonDown(object sender, MouseEventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DragMove();
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
_logger.LogError(exception, "Error dragging window, sender = {sender}, event = {event}", sender, e);
|
|
}
|
|
}
|
|
} |