Fix ESC handling in ticket completion dropdowns
This commit is contained in:
@@ -3,26 +3,26 @@ using FasdDesktopUi.Basics;
|
||||
using FasdDesktopUi.Basics.Models;
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using WinForms = System.Windows.Forms;
|
||||
using static C4IT.Logging.cLogManager;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Interop;
|
||||
using System.Windows.Media;
|
||||
using WinForms = System.Windows.Forms;
|
||||
using static C4IT.Logging.cLogManager;
|
||||
|
||||
namespace FasdDesktopUi.Pages.TicketCompletion
|
||||
{
|
||||
public partial class TicketCompletion : Window, IBlurInvoker, INotifyPropertyChanged
|
||||
{
|
||||
private const double MinWindowHeightDip = 220d;
|
||||
private const double WindowWorkingAreaMarginDip = 12d;
|
||||
private const double DialogNonContentReserveDip = 180d;
|
||||
private bool isUpdatingDialogBounds;
|
||||
private bool isCanceled = false;
|
||||
public partial class TicketCompletion : Window, IBlurInvoker, INotifyPropertyChanged
|
||||
{
|
||||
private const double MinWindowHeightDip = 220d;
|
||||
private const double WindowWorkingAreaMarginDip = 12d;
|
||||
private const double DialogNonContentReserveDip = 180d;
|
||||
private bool isUpdatingDialogBounds;
|
||||
private bool isCanceled = false;
|
||||
|
||||
private bool _WaitForClosing = false;
|
||||
public bool WaitForClosing
|
||||
@@ -49,31 +49,31 @@ namespace FasdDesktopUi.Pages.TicketCompletion
|
||||
CloseCaseDialogUc.DataProvider = _dataProvider;
|
||||
}
|
||||
|
||||
protected override void OnInitialized(EventArgs e)
|
||||
{
|
||||
base.OnInitialized(e);
|
||||
|
||||
cFocusInvoker.GotFocus += ElementGotFocus;
|
||||
cFocusInvoker.LostFocus += ElementLostFocus;
|
||||
SizeChanged += TicketCompletion_SizeChanged;
|
||||
Loaded += TicketCompletion_Loaded;
|
||||
}
|
||||
|
||||
protected override void OnSourceInitialized(EventArgs e)
|
||||
{
|
||||
base.OnSourceInitialized(e);
|
||||
UpdateDialogMaxHeightToScreen();
|
||||
}
|
||||
|
||||
protected override void OnLocationChanged(EventArgs e)
|
||||
{
|
||||
base.OnLocationChanged(e);
|
||||
UpdateDialogMaxHeightToScreen();
|
||||
}
|
||||
|
||||
private void TicketCompletion_Loaded(object sender, RoutedEventArgs e) => UpdateDialogMaxHeightToScreen();
|
||||
|
||||
private void TicketCompletion_SizeChanged(object sender, SizeChangedEventArgs e) => UpdateDialogMaxHeightToScreen();
|
||||
protected override void OnInitialized(EventArgs e)
|
||||
{
|
||||
base.OnInitialized(e);
|
||||
|
||||
cFocusInvoker.GotFocus += ElementGotFocus;
|
||||
cFocusInvoker.LostFocus += ElementLostFocus;
|
||||
SizeChanged += TicketCompletion_SizeChanged;
|
||||
Loaded += TicketCompletion_Loaded;
|
||||
}
|
||||
|
||||
protected override void OnSourceInitialized(EventArgs e)
|
||||
{
|
||||
base.OnSourceInitialized(e);
|
||||
UpdateDialogMaxHeightToScreen();
|
||||
}
|
||||
|
||||
protected override void OnLocationChanged(EventArgs e)
|
||||
{
|
||||
base.OnLocationChanged(e);
|
||||
UpdateDialogMaxHeightToScreen();
|
||||
}
|
||||
|
||||
private void TicketCompletion_Loaded(object sender, RoutedEventArgs e) => UpdateDialogMaxHeightToScreen();
|
||||
|
||||
private void TicketCompletion_SizeChanged(object sender, SizeChangedEventArgs e) => UpdateDialogMaxHeightToScreen();
|
||||
|
||||
#region ClosingBusy
|
||||
|
||||
@@ -126,98 +126,98 @@ namespace FasdDesktopUi.Pages.TicketCompletion
|
||||
return null;
|
||||
}
|
||||
|
||||
#region Close_Click
|
||||
|
||||
private void Close_Click()
|
||||
{
|
||||
isCanceled = true;
|
||||
TrySetDialogResult(null);
|
||||
Close();
|
||||
}
|
||||
#region Close_Click
|
||||
|
||||
private void CloseButton_Click(object sender, InputEventArgs e) => Close_Click();
|
||||
|
||||
#endregion
|
||||
|
||||
private void TrySetDialogResult(bool? result)
|
||||
{
|
||||
try
|
||||
{
|
||||
DialogResult = result;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// Window was not shown as dialog; ignore.
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDialogMaxHeightToScreen()
|
||||
{
|
||||
if (isUpdatingDialogBounds)
|
||||
return;
|
||||
|
||||
isUpdatingDialogBounds = true;
|
||||
try
|
||||
{
|
||||
WinForms.Screen screen = null;
|
||||
IntPtr currentHandle = new WindowInteropHelper(this).Handle;
|
||||
|
||||
if (currentHandle != IntPtr.Zero)
|
||||
{
|
||||
screen = WinForms.Screen.FromHandle(currentHandle);
|
||||
}
|
||||
else if (Owner != null)
|
||||
{
|
||||
IntPtr ownerHandle = new WindowInteropHelper(Owner).Handle;
|
||||
if (ownerHandle != IntPtr.Zero)
|
||||
screen = WinForms.Screen.FromHandle(ownerHandle);
|
||||
}
|
||||
|
||||
screen = screen ?? WinForms.Screen.PrimaryScreen;
|
||||
var workingArea = screen?.WorkingArea ?? WinForms.Screen.PrimaryScreen.WorkingArea;
|
||||
var dpiScaleY = VisualTreeHelper.GetDpi(this).DpiScaleY;
|
||||
var safeDpiScaleY = Math.Max(0.1, dpiScaleY);
|
||||
var workingAreaTopDip = workingArea.Top / safeDpiScaleY;
|
||||
var workingAreaBottomDip = workingArea.Bottom / safeDpiScaleY;
|
||||
var workingAreaHeightDip = workingArea.Height / safeDpiScaleY;
|
||||
var availableWindowHeightDip = workingAreaHeightDip - (WindowWorkingAreaMarginDip * 2);
|
||||
|
||||
MaxHeight = Math.Max(MinWindowHeightDip, availableWindowHeightDip);
|
||||
|
||||
if (!double.IsNaN(Top))
|
||||
{
|
||||
var minTop = workingAreaTopDip + WindowWorkingAreaMarginDip;
|
||||
var maxBottom = workingAreaBottomDip - WindowWorkingAreaMarginDip;
|
||||
|
||||
if (Top < minTop)
|
||||
Top = minTop;
|
||||
|
||||
var currentBottom = Top + ActualHeight;
|
||||
if (currentBottom > maxBottom)
|
||||
Top = Math.Max(minTop, maxBottom - ActualHeight);
|
||||
}
|
||||
|
||||
double nonDialogReserve = DialogNonContentReserveDip;
|
||||
if (CloseCaseDialogUc != null && CloseCaseDialogUc.IsLoaded)
|
||||
{
|
||||
var estimatedReserve = ActualHeight - CloseCaseDialogUc.ActualHeight;
|
||||
if (estimatedReserve > 0)
|
||||
nonDialogReserve = Math.Max(nonDialogReserve, estimatedReserve + WindowWorkingAreaMarginDip);
|
||||
}
|
||||
|
||||
CloseCaseDialogUc?.SetDialogContentMaxHeight(MaxHeight - nonDialogReserve);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogException(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isUpdatingDialogBounds = false;
|
||||
}
|
||||
}
|
||||
|
||||
#region Internal Focus Events
|
||||
private void Close_Click()
|
||||
{
|
||||
isCanceled = true;
|
||||
TrySetDialogResult(null);
|
||||
Close();
|
||||
}
|
||||
|
||||
private void CloseButton_Click(object sender, InputEventArgs e) => Close_Click();
|
||||
|
||||
#endregion
|
||||
|
||||
private void TrySetDialogResult(bool? result)
|
||||
{
|
||||
try
|
||||
{
|
||||
DialogResult = result;
|
||||
}
|
||||
catch (InvalidOperationException)
|
||||
{
|
||||
// Window was not shown as dialog; ignore.
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateDialogMaxHeightToScreen()
|
||||
{
|
||||
if (isUpdatingDialogBounds)
|
||||
return;
|
||||
|
||||
isUpdatingDialogBounds = true;
|
||||
try
|
||||
{
|
||||
WinForms.Screen screen = null;
|
||||
IntPtr currentHandle = new WindowInteropHelper(this).Handle;
|
||||
|
||||
if (currentHandle != IntPtr.Zero)
|
||||
{
|
||||
screen = WinForms.Screen.FromHandle(currentHandle);
|
||||
}
|
||||
else if (Owner != null)
|
||||
{
|
||||
IntPtr ownerHandle = new WindowInteropHelper(Owner).Handle;
|
||||
if (ownerHandle != IntPtr.Zero)
|
||||
screen = WinForms.Screen.FromHandle(ownerHandle);
|
||||
}
|
||||
|
||||
screen = screen ?? WinForms.Screen.PrimaryScreen;
|
||||
var workingArea = screen?.WorkingArea ?? WinForms.Screen.PrimaryScreen.WorkingArea;
|
||||
var dpiScaleY = VisualTreeHelper.GetDpi(this).DpiScaleY;
|
||||
var safeDpiScaleY = Math.Max(0.1, dpiScaleY);
|
||||
var workingAreaTopDip = workingArea.Top / safeDpiScaleY;
|
||||
var workingAreaBottomDip = workingArea.Bottom / safeDpiScaleY;
|
||||
var workingAreaHeightDip = workingArea.Height / safeDpiScaleY;
|
||||
var availableWindowHeightDip = workingAreaHeightDip - (WindowWorkingAreaMarginDip * 2);
|
||||
|
||||
MaxHeight = Math.Max(MinWindowHeightDip, availableWindowHeightDip);
|
||||
|
||||
if (!double.IsNaN(Top))
|
||||
{
|
||||
var minTop = workingAreaTopDip + WindowWorkingAreaMarginDip;
|
||||
var maxBottom = workingAreaBottomDip - WindowWorkingAreaMarginDip;
|
||||
|
||||
if (Top < minTop)
|
||||
Top = minTop;
|
||||
|
||||
var currentBottom = Top + ActualHeight;
|
||||
if (currentBottom > maxBottom)
|
||||
Top = Math.Max(minTop, maxBottom - ActualHeight);
|
||||
}
|
||||
|
||||
double nonDialogReserve = DialogNonContentReserveDip;
|
||||
if (CloseCaseDialogUc != null && CloseCaseDialogUc.IsLoaded)
|
||||
{
|
||||
var estimatedReserve = ActualHeight - CloseCaseDialogUc.ActualHeight;
|
||||
if (estimatedReserve > 0)
|
||||
nonDialogReserve = Math.Max(nonDialogReserve, estimatedReserve + WindowWorkingAreaMarginDip);
|
||||
}
|
||||
|
||||
CloseCaseDialogUc?.SetDialogContentMaxHeight(MaxHeight - nonDialogReserve);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogException(ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
isUpdatingDialogBounds = false;
|
||||
}
|
||||
}
|
||||
|
||||
#region Internal Focus Events
|
||||
|
||||
private void ElementGotFocus(object sender, EventArgs e)
|
||||
{
|
||||
@@ -285,7 +285,14 @@ namespace FasdDesktopUi.Pages.TicketCompletion
|
||||
switch (e.Key)
|
||||
{
|
||||
case Key.Escape:
|
||||
if (CloseCaseDialogUc?.TryHandleEscapeKey() == true)
|
||||
{
|
||||
e.Handled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
Close_Click();
|
||||
e.Handled = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -303,15 +310,15 @@ namespace FasdDesktopUi.Pages.TicketCompletion
|
||||
|
||||
bool closedSuccessfull = await CloseCaseDialogUc.CloseCaseAsync(_dataProvider.Identities.FirstOrDefault(identity => identity.Class == enumFasdInformationClass.User).Id);
|
||||
|
||||
if (closedSuccessfull)
|
||||
{
|
||||
SuccessPage.SuccessPage successPage = new SuccessPage.SuccessPage();
|
||||
successPage.Show();
|
||||
await _dataProvider?.CloseCaseAsync();
|
||||
TrySetDialogResult(true);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
if (closedSuccessfull)
|
||||
{
|
||||
SuccessPage.SuccessPage successPage = new SuccessPage.SuccessPage();
|
||||
successPage.Show();
|
||||
await _dataProvider?.CloseCaseAsync();
|
||||
TrySetDialogResult(true);
|
||||
Close();
|
||||
}
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
|
||||
Reference in New Issue
Block a user