feat: make mode a flag.

This commit is contained in:
Dong Bin
2025-04-18 19:39:13 +08:00
parent 8eaafee693
commit a01d36ceb3
2 changed files with 4 additions and 3 deletions

View File

@@ -190,7 +190,7 @@ public class PopConfirm : ContentControl
void OnCanExecuteChanged(object? _, System.EventArgs a) void OnCanExecuteChanged(object? _, System.EventArgs a)
{ {
count++; count++;
if (count != 2) return; if (count < 1) return;
var canExecute = command.CanExecute(button.CommandParameter); var canExecute = command.CanExecute(button.CommandParameter);
if (canExecute) if (canExecute)
{ {
@@ -225,14 +225,14 @@ public class PopConfirm : ContentControl
private void SetupChildrenEventSubscriptions(Control? child, PopConfirmTriggerMode mode) private void SetupChildrenEventSubscriptions(Control? child, PopConfirmTriggerMode mode)
{ {
if (child is null) return; if (child is null) return;
if (mode == PopConfirmTriggerMode.Click) if (mode.HasFlag(PopConfirmTriggerMode.Click))
{ {
if (child is Button button) if (child is Button button)
Button.ClickEvent.AddHandler(OnMainButtonClicked, button); Button.ClickEvent.AddHandler(OnMainButtonClicked, button);
else else
PointerPressedEvent.AddHandler(OnMainElementPressed, child); PointerPressedEvent.AddHandler(OnMainElementPressed, child);
} }
else if (mode == PopConfirmTriggerMode.Focus) if (mode.HasFlag(PopConfirmTriggerMode.Focus))
{ {
GotFocusEvent.AddHandler(OnMainElementGotFocus, child); GotFocusEvent.AddHandler(OnMainElementGotFocus, child);
LostFocusEvent.AddHandler(OnMainElementLostFocus, child); LostFocusEvent.AddHandler(OnMainElementLostFocus, child);

View File

@@ -1,5 +1,6 @@
namespace Ursa.Controls; namespace Ursa.Controls;
[Flags]
public enum PopConfirmTriggerMode public enum PopConfirmTriggerMode
{ {
Click, Click,