257 lines
7.6 KiB
C#
257 lines
7.6 KiB
C#
using System.ComponentModel;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Telerik.WinControls;
|
|
using Telerik.WinControls.UI;
|
|
|
|
namespace Pilz.UI.Telerik.Dialogs;
|
|
|
|
public partial class RadFlyoutBase : UserControl
|
|
{
|
|
private bool addedControlsToUi;
|
|
|
|
private RadButton radButton_Cancel;
|
|
private RadButton radButton_Confirm;
|
|
private TableLayoutPanel tableLayoutPanel_ActionPanel;
|
|
private TableLayoutPanel tableLayoutPanel_TitlePanel;
|
|
private RadLabel radLabel_Title;
|
|
|
|
public static RadSvgImage? CancelSvg { get; set; } = null;
|
|
public static RadSvgImage? ConfirmSvg { get; set; } = null;
|
|
|
|
public DialogResult Result { get; protected set; }
|
|
public bool RegisterDialogAccept { get; set; } = true;
|
|
public bool RegisterDialogCancel { get; set; } = false;
|
|
|
|
[DefaultValue(true)]
|
|
public bool ActionPanelVisible
|
|
{
|
|
get => tableLayoutPanel_ActionPanel.Visible;
|
|
set => tableLayoutPanel_ActionPanel.Visible = value;
|
|
}
|
|
|
|
[DefaultValue(true)]
|
|
protected bool CancelButtonVisible
|
|
{
|
|
get => radButton_Cancel.Visible;
|
|
set => radButton_Cancel.Visible = value;
|
|
}
|
|
|
|
[DefaultValue(true)]
|
|
protected bool CancelButtonEnable
|
|
{
|
|
get => radButton_Cancel.Enabled;
|
|
set => radButton_Cancel.Enabled = value;
|
|
}
|
|
|
|
[DefaultValue(true)]
|
|
protected bool ConfirmButtonEnable
|
|
{
|
|
get => radButton_Confirm.Enabled;
|
|
set => radButton_Confirm.Enabled = value;
|
|
}
|
|
|
|
[Localizable(true)]
|
|
[DefaultValue("Okay")]
|
|
public string ConfirmButtonText
|
|
{
|
|
get => radButton_Confirm.Text;
|
|
set => radButton_Confirm.Text = value;
|
|
}
|
|
|
|
[Localizable(true)]
|
|
[DefaultValue("Cancel")]
|
|
public string CancelButtonText
|
|
{
|
|
get => radButton_Cancel.Text;
|
|
set => radButton_Cancel.Text = value;
|
|
}
|
|
|
|
[Localizable(true)]
|
|
[DefaultValue("")]
|
|
public string Title
|
|
{
|
|
get => radLabel_Title.Text;
|
|
set
|
|
{
|
|
radLabel_Title.Text = value;
|
|
SetShowTitlePanel();
|
|
}
|
|
}
|
|
|
|
[DefaultValue(null)]
|
|
public RadSvgImage TitleIcon
|
|
{
|
|
get => radLabel_Title.SvgImage;
|
|
set
|
|
{
|
|
radLabel_Title.SvgImage = value;
|
|
SetShowTitlePanel();
|
|
}
|
|
}
|
|
|
|
protected RadFlyoutBase()
|
|
{
|
|
InitializeComponent();
|
|
ParentChanged += FlyoutDialogBase_ParentChanged;
|
|
}
|
|
|
|
[MemberNotNull(nameof(radButton_Cancel))]
|
|
[MemberNotNull(nameof(radButton_Confirm))]
|
|
[MemberNotNull(nameof(tableLayoutPanel_ActionPanel))]
|
|
[MemberNotNull(nameof(tableLayoutPanel_TitlePanel))]
|
|
[MemberNotNull(nameof(radLabel_Title))]
|
|
private void InitializeComponent()
|
|
{
|
|
// radButton_Cancel
|
|
radButton_Cancel = new()
|
|
{
|
|
Name = "radButton_Cancel",
|
|
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
|
|
ImageAlignment = ContentAlignment.MiddleRight,
|
|
Size = new Size(110, 24),
|
|
TabIndex = 1,
|
|
Text = "Cancel",
|
|
TextAlignment = ContentAlignment.MiddleLeft,
|
|
TextImageRelation = TextImageRelation.ImageBeforeText,
|
|
SvgImage = CancelSvg
|
|
};
|
|
radButton_Cancel.TabIndex = int.MaxValue;
|
|
radButton_Cancel.Click += RadButton_Cancel_Click;
|
|
|
|
// radButton_Confirm
|
|
radButton_Confirm = new()
|
|
{
|
|
Name = "radButton_Confirm",
|
|
Anchor = AnchorStyles.Bottom | AnchorStyles.Right,
|
|
ImageAlignment = ContentAlignment.MiddleRight,
|
|
Size = new Size(110, 24),
|
|
TabIndex = 0,
|
|
Text = "Okay",
|
|
TextAlignment = ContentAlignment.MiddleLeft,
|
|
TextImageRelation = TextImageRelation.ImageBeforeText,
|
|
SvgImage = ConfirmSvg
|
|
};
|
|
radButton_Confirm.TabIndex = int.MaxValue - 1;
|
|
radButton_Confirm.Click += RadButton_Confirm_Click;
|
|
|
|
// radLabel_Title
|
|
radLabel_Title = new()
|
|
{
|
|
Name = "radLabel_Title",
|
|
AutoSize = false,
|
|
Dock = DockStyle.Fill,
|
|
TabStop = false,
|
|
TextImageRelation = TextImageRelation.ImageBeforeText
|
|
};
|
|
|
|
// tableLayoutPanel_ActionPanel
|
|
tableLayoutPanel_ActionPanel = new()
|
|
{
|
|
Name = "tableLayoutPanel_ActionPanel",
|
|
Dock = DockStyle.Bottom,
|
|
Size = new Size(ClientSize.Width, 30),
|
|
TabStop = false,
|
|
ColumnCount = 3,
|
|
RowCount = 1,
|
|
};
|
|
tableLayoutPanel_ActionPanel.SuspendLayout();
|
|
tableLayoutPanel_ActionPanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 100F));
|
|
tableLayoutPanel_ActionPanel.ColumnStyles.Add(new ColumnStyle());
|
|
tableLayoutPanel_ActionPanel.ColumnStyles.Add(new ColumnStyle());
|
|
tableLayoutPanel_ActionPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, 30F));
|
|
tableLayoutPanel_ActionPanel.Controls.Add(radButton_Confirm, 1, 0);
|
|
tableLayoutPanel_ActionPanel.Controls.Add(radButton_Cancel, 2, 0);
|
|
|
|
// tableLayoutPanel_TitlePanel
|
|
tableLayoutPanel_TitlePanel = new()
|
|
{
|
|
Name = "tableLayoutPanel_TitlePanel",
|
|
Dock = DockStyle.Top,
|
|
TabStop = false,
|
|
Visible = false,
|
|
ColumnCount = 1,
|
|
RowCount = 1
|
|
};
|
|
tableLayoutPanel_TitlePanel.SuspendLayout();
|
|
tableLayoutPanel_TitlePanel.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 50F));
|
|
tableLayoutPanel_TitlePanel.Controls.Add(radLabel_Title, 0, 0);
|
|
tableLayoutPanel_TitlePanel.RowStyles.Add(new RowStyle(SizeType.Percent, 50F));
|
|
tableLayoutPanel_TitlePanel.Size = new Size(300, 30);
|
|
|
|
// RadFlyoutBase
|
|
AutoScaleDimensions = new SizeF(7F, 15F);
|
|
AutoScaleMode = AutoScaleMode.Font;
|
|
Size = new Size(300, 150);
|
|
|
|
tableLayoutPanel_TitlePanel.ResumeLayout(false);
|
|
tableLayoutPanel_ActionPanel.ResumeLayout(false);
|
|
}
|
|
|
|
protected override void OnLoad(EventArgs e)
|
|
{
|
|
if (!addedControlsToUi)
|
|
{
|
|
SuspendLayout();
|
|
Controls.Add(tableLayoutPanel_ActionPanel);
|
|
tableLayoutPanel_ActionPanel.BringToFront();
|
|
Controls.Add(tableLayoutPanel_TitlePanel);
|
|
tableLayoutPanel_TitlePanel.BringToFront();
|
|
ResumeLayout(false);
|
|
PerformLayout();
|
|
addedControlsToUi = true;
|
|
}
|
|
base.OnLoad(e);
|
|
}
|
|
|
|
protected virtual void FlyoutDialogBase_ParentChanged(object? sender, EventArgs e)
|
|
{
|
|
var frm = FindForm();
|
|
|
|
if (frm != null)
|
|
{
|
|
if (RegisterDialogAccept)
|
|
frm.AcceptButton = radButton_Confirm;
|
|
|
|
if (RegisterDialogCancel)
|
|
frm.CancelButton = radButton_Cancel;
|
|
|
|
if (AutoSize)
|
|
{
|
|
frm.AutoSize = true;
|
|
frm.AutoSizeMode = AutoSizeMode.GrowAndShrink;
|
|
}
|
|
}
|
|
}
|
|
|
|
protected void Close(DialogResult result)
|
|
{
|
|
Result = result;
|
|
|
|
if (FindForm() is RadDialogBase dialogForm)
|
|
dialogForm.Close();
|
|
else
|
|
CloseFlyout();
|
|
}
|
|
|
|
protected virtual bool ValidateOK()
|
|
{
|
|
return true;
|
|
}
|
|
|
|
protected virtual void SetShowTitlePanel()
|
|
{
|
|
tableLayoutPanel_TitlePanel.Visible = !string.IsNullOrWhiteSpace(radLabel_Title.Text) || radLabel_Title.SvgImage != null;
|
|
}
|
|
|
|
protected virtual void RadButton_Confirm_Click(object? sender, EventArgs e)
|
|
{
|
|
if (ValidateOK())
|
|
Close(DialogResult.OK);
|
|
}
|
|
|
|
protected virtual void RadButton_Cancel_Click(object? sender, EventArgs e)
|
|
{
|
|
Close(DialogResult.Cancel);
|
|
}
|
|
}
|