mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-28 23:08:36 +08:00
Refactor Dialog
add EscapeStandardButtonProperty
This commit is contained in:
@@ -111,6 +111,9 @@ public class Dialog : TemplatedControl,
|
||||
public static readonly StyledProperty<DialogStandardButton> DefaultStandardButtonProperty =
|
||||
DialogButtonBox.DefaultStandardButtonProperty.AddOwner<Dialog>();
|
||||
|
||||
public static readonly StyledProperty<DialogStandardButton> EscapeStandardButtonProperty =
|
||||
DialogButtonBox.EscapeStandardButtonProperty.AddOwner<Dialog>();
|
||||
|
||||
public static readonly StyledProperty<bool> IsFooterVisibleProperty =
|
||||
AvaloniaProperty.Register<Dialog, bool>(nameof(IsFooterVisible), true);
|
||||
|
||||
@@ -294,6 +297,12 @@ public class Dialog : TemplatedControl,
|
||||
set => SetValue(DefaultStandardButtonProperty, value);
|
||||
}
|
||||
|
||||
public DialogStandardButton EscapeStandardButton
|
||||
{
|
||||
get => GetValue(EscapeStandardButtonProperty);
|
||||
set => SetValue(EscapeStandardButtonProperty, value);
|
||||
}
|
||||
|
||||
public bool IsFooterVisible
|
||||
{
|
||||
get => GetValue(IsFooterVisibleProperty);
|
||||
@@ -309,7 +318,7 @@ public class Dialog : TemplatedControl,
|
||||
public IDialogHost? Host => _openState?.DialogHost;
|
||||
IDialogHost? IDialogHostProvider.DialogHost => Host;
|
||||
|
||||
public AvaloniaList<Button> CustomButtons { get; } = new ();
|
||||
public AvaloniaList<DialogBoxButton> CustomButtons { get; } = new ();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -624,6 +633,7 @@ public class Dialog : TemplatedControl,
|
||||
disposables.Add(BindUtils.RelayBind(this, IsDragMovableProperty, dialogHost, DialogHost.IsMoveEnabledProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, StandardButtonsProperty, dialogHost, DialogHost.StandardButtonsProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, DefaultStandardButtonProperty, dialogHost, DialogHost.DefaultStandardButtonProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, EscapeStandardButtonProperty, dialogHost, DialogHost.EscapeStandardButtonProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, IsClosableProperty, dialogHost, DialogHost.IsCloseCaptionButtonEnabledProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, IsFooterVisibleProperty, dialogHost, DialogHost.IsFooterVisibleProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, ContentProperty, dialogHost, DialogHost.ContentProperty));
|
||||
@@ -642,6 +652,7 @@ public class Dialog : TemplatedControl,
|
||||
disposables.Add(BindUtils.RelayBind(this, IsDragMovableProperty, dialogHost, OverlayDialogHost.IsDragMovableProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, StandardButtonsProperty, dialogHost, OverlayDialogHost.StandardButtonsProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, DefaultStandardButtonProperty, dialogHost, OverlayDialogHost.DefaultStandardButtonProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, EscapeStandardButtonProperty, dialogHost, OverlayDialogHost.EscapeStandardButtonProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, IsFooterVisibleProperty, dialogHost, OverlayDialogHost.IsFooterVisibleProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, ContentProperty, dialogHost, OverlayDialogHost.ContentProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, ContentTemplateProperty, dialogHost, OverlayDialogHost.ContentTemplateProperty));
|
||||
@@ -1097,7 +1108,7 @@ public class Dialog : TemplatedControl,
|
||||
return;
|
||||
}
|
||||
|
||||
AvaloniaList<Button>? targetButtons = null;
|
||||
AvaloniaList<DialogBoxButton>? targetButtons = null;
|
||||
if (DialogHostType == DialogHostType.Overlay)
|
||||
{
|
||||
if (_openState.DialogHost is OverlayDialogHost overlayDialogHost)
|
||||
@@ -1112,11 +1123,11 @@ public class Dialog : TemplatedControl,
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
var newItems = e.NewItems!.OfType<Button>();
|
||||
var newItems = e.NewItems!.OfType<DialogBoxButton>();
|
||||
targetButtons?.AddRange(newItems);
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
var oldItems = e.OldItems!.OfType<Button>();
|
||||
var oldItems = e.OldItems!.OfType<DialogBoxButton>();
|
||||
targetButtons?.RemoveAll(oldItems);
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Replace:
|
||||
|
||||
@@ -2,5 +2,7 @@ namespace AtomUI.Controls;
|
||||
|
||||
public class DialogBoxButton : Button
|
||||
{
|
||||
public DialogStandardButton StandardButtonType { get; set; }
|
||||
public DialogStandardButton? StandardButtonType { get; set; }
|
||||
public bool IsDefaultConfirmButton { get; set; }
|
||||
public bool IsDefaultEscapeButton { get; set; }
|
||||
}
|
||||
@@ -55,10 +55,10 @@ public class DialogButtonBox : TemplatedControl,
|
||||
set => SetValue(IsMotionEnabledProperty, value);
|
||||
}
|
||||
|
||||
public AvaloniaList<Button> CustomButtons { get; } = new ();
|
||||
public AvaloniaList<DialogBoxButton> CustomButtons { get; } = new ();
|
||||
|
||||
public Dictionary<DialogButtonRole, List<Button>> ButtonGroup => _buttonGroup;
|
||||
public Dictionary<DialogButtonRole, List<Button>> StandardButtonGroup => _standardButtonGroup;
|
||||
public Dictionary<DialogButtonRole, List<DialogBoxButton>> ButtonGroup => _buttonGroup;
|
||||
public Dictionary<DialogButtonRole, List<DialogBoxButton>> StandardButtonGroup => _standardButtonGroup;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -98,6 +98,9 @@ public class DialogButtonBox : TemplatedControl,
|
||||
public static readonly StyledProperty<string?> ResetButtonTextProperty =
|
||||
AvaloniaProperty.Register<DialogButtonBox, string?>(nameof (ResetButtonText));
|
||||
|
||||
public static readonly StyledProperty<string?> ReloadButtonTextProperty =
|
||||
AvaloniaProperty.Register<DialogButtonBox, string?>(nameof (ReloadButtonText));
|
||||
|
||||
public static readonly StyledProperty<string?> RestoreDefaultsButtonTextProperty =
|
||||
AvaloniaProperty.Register<DialogButtonBox, string?>(nameof (RestoreDefaultsButtonText));
|
||||
|
||||
@@ -176,6 +179,12 @@ public class DialogButtonBox : TemplatedControl,
|
||||
set => SetValue(ResetButtonTextProperty, value);
|
||||
}
|
||||
|
||||
public string? ReloadButtonText
|
||||
{
|
||||
get => GetValue(ReloadButtonTextProperty);
|
||||
set => SetValue(ReloadButtonTextProperty, value);
|
||||
}
|
||||
|
||||
public string? RestoreDefaultsButtonText
|
||||
{
|
||||
get => GetValue(RestoreDefaultsButtonTextProperty);
|
||||
@@ -248,8 +257,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
private StackPanel? _centerGroup;
|
||||
private StackPanel? _rightGroup;
|
||||
private List<DialogBoxButton>? _standardButtons;
|
||||
private Dictionary<DialogButtonRole, List<Button>> _buttonGroup;
|
||||
private Dictionary<DialogButtonRole, List<Button>> _standardButtonGroup;
|
||||
private Dictionary<DialogButtonRole, List<DialogBoxButton>> _buttonGroup;
|
||||
private Dictionary<DialogButtonRole, List<DialogBoxButton>> _standardButtonGroup;
|
||||
private Dictionary<Button, CompositeDisposable> _bindingDisposables;
|
||||
|
||||
static DialogButtonBox()
|
||||
@@ -261,8 +270,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
this.RegisterResources();
|
||||
CustomButtons.CollectionChanged += new NotifyCollectionChangedEventHandler(HandleCustomButtonsChanged);
|
||||
_standardButtonGroup = new Dictionary<DialogButtonRole, List<Button>>();
|
||||
_buttonGroup = new Dictionary<DialogButtonRole, List<Button>>();
|
||||
_standardButtonGroup = new Dictionary<DialogButtonRole, List<DialogBoxButton>>();
|
||||
_buttonGroup = new Dictionary<DialogButtonRole, List<DialogBoxButton>>();
|
||||
_bindingDisposables = new Dictionary<Button, CompositeDisposable>();
|
||||
}
|
||||
|
||||
@@ -303,7 +312,7 @@ public class DialogButtonBox : TemplatedControl,
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
var newItems = e.NewItems!.OfType<Button>();
|
||||
var newItems = e.NewItems!.OfType<DialogBoxButton>();
|
||||
foreach (var item in newItems)
|
||||
{
|
||||
DialogButtonRole role = DialogButtonRole.NoRole;
|
||||
@@ -315,7 +324,7 @@ public class DialogButtonBox : TemplatedControl,
|
||||
}
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
var oldItems = e.OldItems!.OfType<Button>();
|
||||
var oldItems = e.OldItems!.OfType<DialogBoxButton>();
|
||||
foreach (var item in oldItems)
|
||||
{
|
||||
DialogButtonRole role = DialogButtonRole.NoRole;
|
||||
@@ -339,13 +348,13 @@ public class DialogButtonBox : TemplatedControl,
|
||||
}
|
||||
}
|
||||
|
||||
private void AddButtonToGroup(DialogButtonRole buttonRole, Button button, bool isStandard)
|
||||
private void AddButtonToGroup(DialogButtonRole buttonRole, DialogBoxButton button, bool isStandard)
|
||||
{
|
||||
List<Button>? buttons;
|
||||
List<DialogBoxButton>? buttons;
|
||||
var targetGroup = isStandard ? _standardButtonGroup : _buttonGroup;
|
||||
if (!targetGroup.ContainsKey(buttonRole))
|
||||
{
|
||||
buttons = new List<Button>();
|
||||
buttons = new List<DialogBoxButton>();
|
||||
targetGroup.Add(buttonRole, buttons);
|
||||
}
|
||||
else
|
||||
@@ -357,13 +366,13 @@ public class DialogButtonBox : TemplatedControl,
|
||||
buttons.Add(button);
|
||||
}
|
||||
|
||||
private void RemoveButtonFromGroup(DialogButtonRole buttonRole, Button button, bool isStandard)
|
||||
private void RemoveButtonFromGroup(DialogButtonRole buttonRole, DialogBoxButton button, bool isStandard)
|
||||
{
|
||||
var targetGroup = isStandard ? _standardButtonGroup : _buttonGroup;
|
||||
List<Button>? buttons;
|
||||
var targetGroup = isStandard ? _standardButtonGroup : _buttonGroup;
|
||||
List<DialogBoxButton>? buttons;
|
||||
if (!targetGroup.ContainsKey(buttonRole))
|
||||
{
|
||||
buttons = new List<Button>();
|
||||
buttons = new List<DialogBoxButton>();
|
||||
targetGroup.Add(buttonRole, buttons);
|
||||
}
|
||||
else
|
||||
@@ -403,6 +412,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.AcceptRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Ok ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Ok,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Ok,
|
||||
StandardButtonType = DialogStandardButton.Ok
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -419,6 +430,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.AcceptRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Open ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Open,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Open,
|
||||
StandardButtonType = DialogStandardButton.Open
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -435,6 +448,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.AcceptRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Save ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Save,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Save,
|
||||
StandardButtonType = DialogStandardButton.Save
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -451,6 +466,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.AcceptRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.SaveAll ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.SaveAll,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.SaveAll,
|
||||
StandardButtonType = DialogStandardButton.SaveAll
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -467,6 +484,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.AcceptRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Retry ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Retry,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Retry,
|
||||
StandardButtonType = DialogStandardButton.Retry
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -483,6 +502,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.AcceptRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Ignore ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Ignore,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Ignore,
|
||||
StandardButtonType = DialogStandardButton.Ignore
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -499,6 +520,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.YesRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Yes ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Yes,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Yes,
|
||||
StandardButtonType = DialogStandardButton.Yes
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -515,6 +538,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.YesRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.YesToAll ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.YesToAll,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.YesToAll,
|
||||
StandardButtonType = DialogStandardButton.YesToAll
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -531,6 +556,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.RejectRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Cancel ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Cancel,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Cancel,
|
||||
StandardButtonType = DialogStandardButton.Cancel
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -547,6 +574,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.RejectRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Close ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Close,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Close,
|
||||
StandardButtonType = DialogStandardButton.Close
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -563,6 +592,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.RejectRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Abort ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Abort,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Abort,
|
||||
StandardButtonType = DialogStandardButton.Abort
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -579,6 +610,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.NoRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.No ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.No,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.No,
|
||||
StandardButtonType = DialogStandardButton.No
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -595,6 +628,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.NoRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.NoToAll ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.NoToAll,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.NoToAll,
|
||||
StandardButtonType = DialogStandardButton.NoToAll
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -611,6 +646,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.DestructiveRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Discard ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Discard,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Discard,
|
||||
StandardButtonType = DialogStandardButton.Discard
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -627,6 +664,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.HelpRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Help ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Help,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Help,
|
||||
StandardButtonType = DialogStandardButton.Help
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -643,6 +682,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.ResetRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Reset ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Reset,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Reset,
|
||||
StandardButtonType = DialogStandardButton.Reset
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -653,12 +694,32 @@ public class DialogButtonBox : TemplatedControl,
|
||||
AddButtonToGroup(DialogButtonRole.ResetRole, button, true);
|
||||
}
|
||||
|
||||
if (StandardButtons.HasFlag(DialogStandardButton.Reload))
|
||||
{
|
||||
var button = new DialogBoxButton
|
||||
{
|
||||
Tag = DialogButtonRole.ResetRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Reload ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Reload,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Reload,
|
||||
StandardButtonType = DialogStandardButton.Reload
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
disposables.Add(BindUtils.RelayBind(this, ResetButtonTextProperty, button, Button.ContentProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, IsMotionEnabledProperty, button, Button.IsMotionEnabledProperty));
|
||||
_bindingDisposables.Add(button, disposables);
|
||||
_standardButtons.Add(button);
|
||||
AddButtonToGroup(DialogButtonRole.ResetRole, button, true);
|
||||
}
|
||||
|
||||
if (StandardButtons.HasFlag(DialogStandardButton.RestoreDefaults))
|
||||
{
|
||||
var button = new DialogBoxButton
|
||||
{
|
||||
Tag = DialogButtonRole.ResetRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.RestoreDefaults ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.RestoreDefaults,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.RestoreDefaults,
|
||||
StandardButtonType = DialogStandardButton.RestoreDefaults
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -675,6 +736,8 @@ public class DialogButtonBox : TemplatedControl,
|
||||
{
|
||||
Tag = DialogButtonRole.ApplyRole,
|
||||
ButtonType = DefaultStandardButton == DialogStandardButton.Apply ? ButtonType.Primary : ButtonType.Default,
|
||||
IsDefaultConfirmButton = DefaultStandardButton == DialogStandardButton.Apply,
|
||||
IsDefaultEscapeButton = EscapeStandardButton == DialogStandardButton.Apply,
|
||||
StandardButtonType = DialogStandardButton.Apply
|
||||
};
|
||||
var disposables = new CompositeDisposable(2);
|
||||
@@ -705,7 +768,7 @@ public class DialogButtonBox : TemplatedControl,
|
||||
|
||||
// 后面可以定义各种操作系统的风格,现在先写死
|
||||
// 标准
|
||||
var standardAcceptList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.AcceptRole) ?? new List<Button>();
|
||||
var standardAcceptList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.AcceptRole) ?? new List<DialogBoxButton>();
|
||||
var standardAcceptIndex = 0;
|
||||
|
||||
if (standardAcceptList.Count > 0)
|
||||
@@ -715,7 +778,7 @@ public class DialogButtonBox : TemplatedControl,
|
||||
}
|
||||
|
||||
// 自定义
|
||||
var acceptList = _buttonGroup.GetValueOrDefault(DialogButtonRole.AcceptRole) ?? new List<Button>();
|
||||
var acceptList = _buttonGroup.GetValueOrDefault(DialogButtonRole.AcceptRole) ?? new List<DialogBoxButton>();
|
||||
var acceptIndex = 0;
|
||||
|
||||
if (acceptList.Count > 0)
|
||||
@@ -725,7 +788,7 @@ public class DialogButtonBox : TemplatedControl,
|
||||
}
|
||||
|
||||
// 标准
|
||||
var standardYesList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.YesRole) ?? new List<Button>();
|
||||
var standardYesList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.YesRole) ?? new List<DialogBoxButton>();
|
||||
var standardYesIndex = 0;
|
||||
|
||||
if (standardYesList.Count > 0)
|
||||
@@ -735,7 +798,7 @@ public class DialogButtonBox : TemplatedControl,
|
||||
}
|
||||
// 自定义
|
||||
|
||||
var yesList = _buttonGroup.GetValueOrDefault(DialogButtonRole.YesRole) ?? new List<Button>();
|
||||
var yesList = _buttonGroup.GetValueOrDefault(DialogButtonRole.YesRole) ?? new List<DialogBoxButton>();
|
||||
var yesIndex = 0;
|
||||
|
||||
if (yesList.Count > 0)
|
||||
@@ -746,28 +809,28 @@ public class DialogButtonBox : TemplatedControl,
|
||||
|
||||
// 输出 reject
|
||||
// 标准
|
||||
var standardRejectList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.RejectRole) ?? new List<Button>();
|
||||
var standardRejectList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.RejectRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var rejectButton in standardRejectList)
|
||||
{
|
||||
rightGroupButtons.Add(rejectButton);
|
||||
}
|
||||
|
||||
// 自定义
|
||||
var rejectList = _buttonGroup.GetValueOrDefault(DialogButtonRole.RejectRole) ?? new List<Button>();
|
||||
var rejectList = _buttonGroup.GetValueOrDefault(DialogButtonRole.RejectRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var rejectButton in rejectList)
|
||||
{
|
||||
rightGroupButtons.Add(rejectButton);
|
||||
}
|
||||
|
||||
// 输出 No
|
||||
var standardNoList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.NoRole) ?? new List<Button>();
|
||||
var standardNoList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.NoRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var button in standardNoList)
|
||||
{
|
||||
rightGroupButtons.Add(button);
|
||||
}
|
||||
|
||||
// 自定义
|
||||
var noList = _buttonGroup.GetValueOrDefault(DialogButtonRole.NoRole) ?? new List<Button>();
|
||||
var noList = _buttonGroup.GetValueOrDefault(DialogButtonRole.NoRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var button in noList)
|
||||
{
|
||||
rightGroupButtons.Add(button);
|
||||
@@ -822,7 +885,7 @@ public class DialogButtonBox : TemplatedControl,
|
||||
Debug.Assert(_centerGroup != null);
|
||||
var centerGroupButtons = new List<Button>();
|
||||
// 标准
|
||||
var standardDestructiveList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.DestructiveRole) ?? new List<Button>();
|
||||
var standardDestructiveList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.DestructiveRole) ?? new List<DialogBoxButton>();
|
||||
|
||||
foreach (var button in standardDestructiveList)
|
||||
{
|
||||
@@ -830,7 +893,7 @@ public class DialogButtonBox : TemplatedControl,
|
||||
}
|
||||
|
||||
// 自定义
|
||||
var destructiveList = _buttonGroup.GetValueOrDefault(DialogButtonRole.DestructiveRole) ?? new List<Button>();
|
||||
var destructiveList = _buttonGroup.GetValueOrDefault(DialogButtonRole.DestructiveRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var button in destructiveList)
|
||||
{
|
||||
centerGroupButtons.Add(button);
|
||||
@@ -844,42 +907,42 @@ public class DialogButtonBox : TemplatedControl,
|
||||
Debug.Assert(_leftGroup != null);
|
||||
var leftGroupButtons = new List<Button>();
|
||||
// 标准
|
||||
var standardHelpList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.HelpRole) ?? new List<Button>();
|
||||
var standardHelpList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.HelpRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var button in standardHelpList)
|
||||
{
|
||||
leftGroupButtons.Add(button);
|
||||
}
|
||||
|
||||
// 自定义
|
||||
var helpList = _buttonGroup.GetValueOrDefault(DialogButtonRole.HelpRole) ?? new List<Button>();
|
||||
var helpList = _buttonGroup.GetValueOrDefault(DialogButtonRole.HelpRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var button in helpList)
|
||||
{
|
||||
leftGroupButtons.Add(button);
|
||||
}
|
||||
|
||||
// 标准
|
||||
var standardResetList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.ResetRole) ?? new List<Button>();
|
||||
var standardResetList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.ResetRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var button in standardResetList)
|
||||
{
|
||||
leftGroupButtons.Add(button);
|
||||
}
|
||||
|
||||
// 自定义
|
||||
var resetList = _buttonGroup.GetValueOrDefault(DialogButtonRole.ResetRole) ?? new List<Button>();
|
||||
var resetList = _buttonGroup.GetValueOrDefault(DialogButtonRole.ResetRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var button in resetList)
|
||||
{
|
||||
leftGroupButtons.Add(button);
|
||||
}
|
||||
|
||||
// 标准
|
||||
var standardApplyList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.ResetRole) ?? new List<Button>();
|
||||
var standardApplyList = _standardButtonGroup.GetValueOrDefault(DialogButtonRole.ResetRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var button in standardApplyList)
|
||||
{
|
||||
leftGroupButtons.Add(button);
|
||||
}
|
||||
|
||||
// 自定义
|
||||
var applyList = _buttonGroup.GetValueOrDefault(DialogButtonRole.ApplyRole) ?? new List<Button>();
|
||||
var applyList = _buttonGroup.GetValueOrDefault(DialogButtonRole.ApplyRole) ?? new List<DialogBoxButton>();
|
||||
foreach (var button in applyList)
|
||||
{
|
||||
leftGroupButtons.Add(button);
|
||||
|
||||
@@ -29,6 +29,9 @@ internal class DialogHost : Window,
|
||||
public static readonly StyledProperty<DialogStandardButton> DefaultStandardButtonProperty =
|
||||
DialogButtonBox.DefaultStandardButtonProperty.AddOwner<DialogHost>();
|
||||
|
||||
public static readonly StyledProperty<DialogStandardButton> EscapeStandardButtonProperty =
|
||||
DialogButtonBox.EscapeStandardButtonProperty.AddOwner<DialogHost>();
|
||||
|
||||
public static readonly StyledProperty<bool> IsFooterVisibleProperty =
|
||||
Dialog.IsFooterVisibleProperty.AddOwner<DialogHost>();
|
||||
|
||||
@@ -53,6 +56,12 @@ internal class DialogHost : Window,
|
||||
set => SetValue(DefaultStandardButtonProperty, value);
|
||||
}
|
||||
|
||||
public DialogStandardButton EscapeStandardButton
|
||||
{
|
||||
get => GetValue(EscapeStandardButtonProperty);
|
||||
set => SetValue(EscapeStandardButtonProperty, value);
|
||||
}
|
||||
|
||||
public bool IsFooterVisible
|
||||
{
|
||||
get => GetValue(IsFooterVisibleProperty);
|
||||
@@ -88,7 +97,7 @@ internal class DialogHost : Window,
|
||||
|
||||
Visual IDialogHost.HostedVisualTreeRoot => this;
|
||||
|
||||
public AvaloniaList<Button> CustomButtons { get; } = new ();
|
||||
public AvaloniaList<DialogBoxButton> CustomButtons { get; } = new ();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -225,11 +234,11 @@ internal class DialogHost : Window,
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
var newItems = e.NewItems!.OfType<Button>();
|
||||
var newItems = e.NewItems!.OfType<DialogBoxButton>();
|
||||
_buttonBox.CustomButtons.AddRange(newItems);
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
var oldItems = e.OldItems!.OfType<Button>();
|
||||
var oldItems = e.OldItems!.OfType<DialogBoxButton>();
|
||||
_buttonBox.CustomButtons.RemoveAll(oldItems);
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Replace:
|
||||
|
||||
@@ -42,45 +42,49 @@ public enum DialogStandardButton
|
||||
/// </summary>
|
||||
Reset = 0x00000080,
|
||||
/// <summary>
|
||||
/// A "Reload" button defined with the ResetRole.
|
||||
/// </summary>
|
||||
Reload = 0x00000100,
|
||||
/// <summary>
|
||||
/// A "Restore Defaults" button defined with the ResetRole.
|
||||
/// </summary>
|
||||
RestoreDefaults = 0x00000100,
|
||||
RestoreDefaults = 0x00000200,
|
||||
/// <summary>
|
||||
/// A "Help" button defined with the HelpRole.
|
||||
/// </summary>
|
||||
Help = 0x00000200,
|
||||
Help = 0x00000400,
|
||||
/// <summary>
|
||||
/// A "Save All" button defined with the AcceptRole.
|
||||
/// </summary>
|
||||
SaveAll = 0x00000400,
|
||||
SaveAll = 0x00000800,
|
||||
/// <summary>
|
||||
/// A "Yes" button defined with the YesRole.
|
||||
/// </summary>
|
||||
Yes = 0x00000800,
|
||||
Yes = 0x00001000,
|
||||
/// <summary>
|
||||
/// A "Yes to All" button defined with the YesRole.
|
||||
/// </summary>
|
||||
YesToAll = 0x00001000,
|
||||
YesToAll = 0x00002000,
|
||||
/// <summary>
|
||||
/// A "No" button defined with the NoRole.
|
||||
/// </summary>
|
||||
No = 0x00002000,
|
||||
No = 0x00004000,
|
||||
/// <summary>
|
||||
/// A "No to All" button defined with the NoRole.
|
||||
/// </summary>
|
||||
NoToAll = 0x00004000,
|
||||
NoToAll = 0x00008000,
|
||||
/// <summary>
|
||||
/// An "Abort" button defined with the RejectRole.
|
||||
/// </summary>
|
||||
Abort = 0x00008000,
|
||||
Abort = 0x00010000,
|
||||
/// <summary>
|
||||
/// A "Retry" button defined with the AcceptRole.
|
||||
/// </summary>
|
||||
Retry = 0x00010000,
|
||||
Retry = 0x00020000,
|
||||
/// <summary>
|
||||
/// An "Ignore" button defined with the AcceptRole.
|
||||
/// </summary>
|
||||
Ignore = 0x00020000,
|
||||
Ignore = 0x00040000,
|
||||
}
|
||||
|
||||
public readonly struct DialogStandardButtons : IEquatable<DialogStandardButtons>
|
||||
|
||||
@@ -13,6 +13,7 @@ internal class en_US : LanguageProvider
|
||||
public const string Discard = "Discard";
|
||||
public const string Apply = "Apply";
|
||||
public const string Reset = "Reset";
|
||||
public const string Reload = "Reload";
|
||||
public const string RestoreDefaults = "Restore Defaults";
|
||||
public const string Help = "Help";
|
||||
public const string SaveAll = "Save All";
|
||||
|
||||
@@ -13,6 +13,7 @@ internal class zh_CN : LanguageProvider
|
||||
public const string Discard = "丢弃";
|
||||
public const string Apply = "应用";
|
||||
public const string Reset = "重置";
|
||||
public const string Reload = "重新加载";
|
||||
public const string RestoreDefaults = "恢复默认值";
|
||||
public const string Help = "帮助";
|
||||
public const string SaveAll = "全部保存";
|
||||
|
||||
@@ -57,6 +57,9 @@ internal class OverlayDialogHost : ContentControl,
|
||||
public static readonly StyledProperty<DialogStandardButton> DefaultStandardButtonProperty =
|
||||
DialogButtonBox.DefaultStandardButtonProperty.AddOwner<OverlayDialogHost>();
|
||||
|
||||
public static readonly StyledProperty<DialogStandardButton> EscapeStandardButtonProperty =
|
||||
DialogButtonBox.EscapeStandardButtonProperty.AddOwner<OverlayDialogHost>();
|
||||
|
||||
public static readonly StyledProperty<bool> IsFooterVisibleProperty =
|
||||
Dialog.IsFooterVisibleProperty.AddOwner<OverlayDialogHost>();
|
||||
|
||||
@@ -128,6 +131,12 @@ internal class OverlayDialogHost : ContentControl,
|
||||
get => GetValue(DefaultStandardButtonProperty);
|
||||
set => SetValue(DefaultStandardButtonProperty, value);
|
||||
}
|
||||
|
||||
public DialogStandardButton EscapeStandardButton
|
||||
{
|
||||
get => GetValue(EscapeStandardButtonProperty);
|
||||
set => SetValue(EscapeStandardButtonProperty, value);
|
||||
}
|
||||
|
||||
public bool IsFooterVisible
|
||||
{
|
||||
@@ -141,7 +150,7 @@ internal class OverlayDialogHost : ContentControl,
|
||||
set => SetValue(IsMotionEnabledProperty, value);
|
||||
}
|
||||
|
||||
public AvaloniaList<Button> CustomButtons { get; } = new ();
|
||||
public AvaloniaList<DialogBoxButton> CustomButtons { get; } = new ();
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -715,11 +724,11 @@ internal class OverlayDialogHost : ContentControl,
|
||||
switch (e.Action)
|
||||
{
|
||||
case NotifyCollectionChangedAction.Add:
|
||||
var newItems = e.NewItems!.OfType<Button>();
|
||||
var newItems = e.NewItems!.OfType<DialogBoxButton>();
|
||||
_buttonBox.CustomButtons.AddRange(newItems);
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Remove:
|
||||
var oldItems = e.OldItems!.OfType<Button>();
|
||||
var oldItems = e.OldItems!.OfType<DialogBoxButton>();
|
||||
_buttonBox.CustomButtons.RemoveAll(oldItems);
|
||||
break;
|
||||
case NotifyCollectionChangedAction.Replace:
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
<Setter Property="DiscardButtonText" Value="{DynamicResource {x:Static dialogLang:DialogLangResourceKey.Discard}}"/>
|
||||
<Setter Property="ApplyButtonText" Value="{DynamicResource {x:Static dialogLang:DialogLangResourceKey.Apply}}"/>
|
||||
<Setter Property="ResetButtonText" Value="{DynamicResource {x:Static dialogLang:DialogLangResourceKey.Reset}}"/>
|
||||
<Setter Property="ReloadButtonText" Value="{DynamicResource {x:Static dialogLang:DialogLangResourceKey.Reload}}"/>
|
||||
<Setter Property="RestoreDefaultsButtonText" Value="{DynamicResource {x:Static dialogLang:DialogLangResourceKey.RestoreDefaults}}"/>
|
||||
<Setter Property="HelpButtonText" Value="{DynamicResource {x:Static dialogLang:DialogLangResourceKey.Help}}"/>
|
||||
<Setter Property="SaveAllButtonText" Value="{DynamicResource {x:Static dialogLang:DialogLangResourceKey.SaveAll}}"/>
|
||||
|
||||
@@ -31,7 +31,8 @@
|
||||
<atom:DialogButtonBox Name="{x:Static atom:DialogThemeConstants.ButtonBoxPart}"
|
||||
IsMotionEnabled="{TemplateBinding IsMotionEnabled}"
|
||||
StandardButtons="{TemplateBinding StandardButtons}"
|
||||
DefaultStandardButton="{TemplateBinding DefaultStandardButton}" />
|
||||
DefaultStandardButton="{TemplateBinding DefaultStandardButton}"
|
||||
EscapeStandardButton="{TemplateBinding EscapeStandardButton}"/>
|
||||
</Border>
|
||||
<Border Name="ContentFrame"
|
||||
CornerRadius="{TemplateBinding CornerRadius}"
|
||||
|
||||
@@ -23,7 +23,8 @@
|
||||
<atom:DialogButtonBox Name="{x:Static atom:DialogThemeConstants.ButtonBoxPart}"
|
||||
IsMotionEnabled="{TemplateBinding IsMotionEnabled}"
|
||||
StandardButtons="{TemplateBinding StandardButtons}"
|
||||
DefaultStandardButton="{TemplateBinding DefaultStandardButton}" />
|
||||
DefaultStandardButton="{TemplateBinding DefaultStandardButton}"
|
||||
EscapeStandardButton="{TemplateBinding EscapeStandardButton}"/>
|
||||
</Border>
|
||||
<Border Name="ContentFrame">
|
||||
<ContentPresenter Name="ContentPresenter"
|
||||
|
||||
+1
@@ -25,6 +25,7 @@ namespace AtomUI.Controls.DialogLang
|
||||
public static readonly LanguageResourceKey NoToAll = new LanguageResourceKey("Dialog.NoToAll", "AtomUI.Lang");
|
||||
public static readonly LanguageResourceKey Ok = new LanguageResourceKey("Dialog.Ok", "AtomUI.Lang");
|
||||
public static readonly LanguageResourceKey Open = new LanguageResourceKey("Dialog.Open", "AtomUI.Lang");
|
||||
public static readonly LanguageResourceKey Reload = new LanguageResourceKey("Dialog.Reload", "AtomUI.Lang");
|
||||
public static readonly LanguageResourceKey Reset = new LanguageResourceKey("Dialog.Reset", "AtomUI.Lang");
|
||||
public static readonly LanguageResourceKey RestoreDefaults = new LanguageResourceKey("Dialog.RestoreDefaults", "AtomUI.Lang");
|
||||
public static readonly LanguageResourceKey Retry = new LanguageResourceKey("Dialog.Retry", "AtomUI.Lang");
|
||||
|
||||
@@ -309,6 +309,11 @@ public class MessageBox : TemplatedControl,
|
||||
{
|
||||
_dialog.StandardButtons = DialogStandardButton.Ok;
|
||||
}
|
||||
else if (Style == MessageBoxStyle.Confirm)
|
||||
{
|
||||
SetValue(IconProperty, AntDesignIconPackage.ExclamationCircleFilled(), BindingPriority.Template);
|
||||
_dialog.StandardButtons = DialogStandardButton.Ok | DialogStandardButton.Cancel;
|
||||
}
|
||||
}
|
||||
|
||||
private void ConfigureOkButton()
|
||||
|
||||
@@ -60,10 +60,17 @@
|
||||
</Panel>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
||||
<Style Selector="^ /template/ atom|IconPresenter#StyleIconPresenter">
|
||||
<Setter Property="IconWidth" Value="{DynamicResource {x:Static atom:MessageBoxTokenKey.StyleIconSize}}" />
|
||||
<Setter Property="IconHeight" Value="{DynamicResource {x:Static atom:MessageBoxTokenKey.StyleIconSize}}" />
|
||||
</Style>
|
||||
|
||||
<Style Selector="^[Style=Confirm]">
|
||||
<Style Selector="^ /template/ atom|IconPresenter#StyleIconPresenter">
|
||||
<Setter Property="NormalFilledBrush" Value="{DynamicResource {x:Static atom:SharedTokenKey.ColorWarning}}" />
|
||||
</Style>
|
||||
</Style>
|
||||
|
||||
<Style Selector="^[Style=Information]">
|
||||
<Style Selector="^ /template/ atom|IconPresenter#StyleIconPresenter">
|
||||
|
||||
@@ -62,6 +62,13 @@
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
|
||||
|
||||
<Style Selector="^[Style=Confirm]">
|
||||
<Style Selector="^ /template/ atom|IconPresenter#StyleIconPresenter">
|
||||
<Setter Property="NormalFilledBrush" Value="{DynamicResource {x:Static atom:SharedTokenKey.ColorWarning}}" />
|
||||
</Style>
|
||||
</Style>
|
||||
|
||||
<Style Selector="^ /template/ atom|IconPresenter#StyleIconPresenter">
|
||||
<Setter Property="IconWidth" Value="{DynamicResource {x:Static atom:MessageBoxTokenKey.StyleIconSize}}" />
|
||||
<Setter Property="IconHeight" Value="{DynamicResource {x:Static atom:MessageBoxTokenKey.StyleIconSize}}" />
|
||||
|
||||
Reference in New Issue
Block a user