code optimization

This commit is contained in:
2024-06-05 19:15:32 +02:00
parent d4be7d0566
commit 1b49c54822
151 changed files with 4124 additions and 4673 deletions

View File

@@ -1,86 +1,76 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace Pilz.UI.Telerik.Dialogs;
namespace Pilz.UI.Telerik.Dialogs
partial class DialogBase
{
partial class DialogBase
{
public delegate void DialogLoadingEventHandler(DialogLoadingEventArgs e);
public delegate void DialogClosedEventHandler(DialogClosedEventArgs e);
public delegate void DialogLoadingEventHandler(DialogLoadingEventArgs e);
public delegate void DialogClosedEventHandler(DialogClosedEventArgs e);
public static event DialogLoadingEventHandler? DialogLoading;
public static event DialogClosedEventHandler? DialogClosed;
public static event DialogLoadingEventHandler? DialogLoading;
public static event DialogClosedEventHandler? DialogClosed;
public static T Show<T>(string title, Icon icon, object? tag = null) where T : FlyoutBase
public static T Show<T>(string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return Show<T>(null, title, icon, tag);
}
public static T ShowDialog<T>(string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return ShowDialog<T>(null, title, icon, tag);
}
public static T Show<T>(IWin32Window? parent, string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return Show(CreatePanelInstance<T>(tag), parent, title, icon);
}
public static T ShowDialog<T>(IWin32Window? parent, string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return ShowDialog(CreatePanelInstance<T>(tag), parent, title, icon);
}
public static T Show<T>(T dialogPanel, string title, Icon icon) where T : FlyoutBase
{
return Show(dialogPanel, null, title, icon);
}
public static T ShowDialog<T>(T dialogPanel, string title, Icon icon) where T : FlyoutBase
{
return ShowDialog(dialogPanel, null, title, icon);
}
public static T Show<T>(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : FlyoutBase
{
CreateForm(dialogPanel, parent, title, icon).Show();
return dialogPanel;
}
public static T ShowDialog<T>(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : FlyoutBase
{
CreateForm(dialogPanel, parent, title, icon).ShowDialog();
return dialogPanel;
}
private static T CreatePanelInstance<T>(object? tag) where T : FlyoutBase
{
T dialogPanel = Activator.CreateInstance<T>();
dialogPanel.Tag = tag;
return dialogPanel;
}
private static DialogBase CreateForm<T>(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : FlyoutBase
{
dialogPanel.Dock = DockStyle.Fill;
var dialog = new DialogBase(dialogPanel)
{
return Show<T>(null, title, icon, tag);
}
Text = title,
Icon = icon,
StartPosition = parent == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent,
ClientSize = dialogPanel.Size
};
public static T ShowDialog<T>(string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return ShowDialog<T>(null, title, icon, tag);
}
dialog.Controls.Add(dialogPanel);
public static T Show<T>(IWin32Window? parent, string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return Show(CreatePanelInstance<T>(tag), parent, title, icon);
}
public static T ShowDialog<T>(IWin32Window? parent, string title, Icon icon, object? tag = null) where T : FlyoutBase
{
return ShowDialog(CreatePanelInstance<T>(tag), parent, title, icon);
}
public static T Show<T>(T dialogPanel, string title, Icon icon) where T : FlyoutBase
{
return Show(dialogPanel, null, title, icon);
}
public static T ShowDialog<T>(T dialogPanel, string title, Icon icon) where T : FlyoutBase
{
return ShowDialog(dialogPanel, null, title, icon);
}
public static T Show<T>(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : FlyoutBase
{
CreateForm(dialogPanel, parent, title, icon).Show();
return dialogPanel;
}
public static T ShowDialog<T>(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : FlyoutBase
{
CreateForm(dialogPanel, parent, title, icon).ShowDialog();
return dialogPanel;
}
private static T CreatePanelInstance<T>(object? tag) where T : FlyoutBase
{
T dialogPanel = Activator.CreateInstance<T>();
dialogPanel.Tag = tag;
return dialogPanel;
}
private static DialogBase CreateForm<T>(T dialogPanel, IWin32Window? parent, string title, Icon icon) where T : FlyoutBase
{
dialogPanel.Dock = DockStyle.Fill;
var dialog = new DialogBase(dialogPanel)
{
Text = title,
Icon = icon,
StartPosition = parent == null ? FormStartPosition.CenterScreen : FormStartPosition.CenterParent,
ClientSize = dialogPanel.Size
};
dialog.Controls.Add(dialogPanel);
return dialog;
}
}
return dialog;
}
}

View File

@@ -1,39 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI;
namespace Pilz.UI.Telerik.Dialogs
namespace Pilz.UI.Telerik.Dialogs;
public partial class DialogBase : RadForm
{
public partial class DialogBase : RadForm
public FlyoutBase? DialogPanel { get; private set; }
private DialogBase()
{
public FlyoutBase? DialogPanel { get; private set; }
Load += DialogBaseForm_Load;
FormClosed += DialogBaseForm_FormClosed;
}
private DialogBase()
{
Load += DialogBaseForm_Load;
FormClosed += DialogBaseForm_FormClosed;
}
public DialogBase(FlyoutBase? dialogPanel) : this()
{
DialogPanel = dialogPanel;
}
public DialogBase(FlyoutBase? dialogPanel) : this()
{
DialogPanel = dialogPanel;
}
private void DialogBaseForm_Load(object? sender, EventArgs e)
{
if (DialogPanel is ILoadContent iLoadContent)
iLoadContent.LoadContent();
private void DialogBaseForm_Load(object? sender, EventArgs e)
{
if (DialogPanel is ILoadContent iLoadContent)
iLoadContent.LoadContent();
DialogLoading?.Invoke(new DialogLoadingEventArgs(this));
}
DialogLoading?.Invoke(new DialogLoadingEventArgs(this));
}
private void DialogBaseForm_FormClosed(object? sender, FormClosedEventArgs e)
{
DialogClosed?.Invoke(new DialogClosedEventArgs(this));
}
private void DialogBaseForm_FormClosed(object? sender, FormClosedEventArgs e)
{
DialogClosed?.Invoke(new DialogClosedEventArgs(this));
}
}

View File

@@ -1,20 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Pilz.UI.Telerik.Dialogs;
namespace Pilz.UI.Telerik.Dialogs
public class DialogClosedEventArgs : EventArgs
{
public class DialogClosedEventArgs : EventArgs
{
public DialogBase Parent { get; private set; }
public FlyoutBase? Content => Parent?.DialogPanel;
public DialogBase Parent { get; private set; }
public FlyoutBase? Content => Parent?.DialogPanel;
public DialogClosedEventArgs(DialogBase dialog)
{
Parent = dialog;
}
public DialogClosedEventArgs(DialogBase dialog)
{
Parent = dialog;
}
}

View File

@@ -1,21 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace Pilz.UI.Telerik.Dialogs;
namespace Pilz.UI.Telerik.Dialogs
public class DialogLoadingEventArgs : EventArgs
{
public class DialogLoadingEventArgs : EventArgs
{
public DialogBase Parent { get; private set; }
public FlyoutBase? Content => Parent?.DialogPanel;
public DialogBase Parent { get; private set; }
public FlyoutBase? Content => Parent?.DialogPanel;
public DialogLoadingEventArgs(DialogBase dialog)
{
Parent = dialog;
}
public DialogLoadingEventArgs(DialogBase dialog)
{
Parent = dialog;
}
}

View File

@@ -1,101 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI.SplashScreen;
using Telerik.WinControls.UI;
using System.Windows.Forms;
namespace Pilz.UI.Telerik.Dialogs
namespace Pilz.UI.Telerik.Dialogs;
partial class FlyoutBase
{
partial class FlyoutBase
public delegate void FlyoutCreatedEventHandler(FlyoutCreatedEventArgs e);
public delegate void FlyoutClosedEventHandler(FlyoutClosedEventArgs e);
public static event FlyoutCreatedEventHandler FlyoutCreated
{
public delegate void FlyoutCreatedEventHandler(FlyoutCreatedEventArgs e);
public delegate void FlyoutClosedEventHandler(FlyoutClosedEventArgs e);
add => flyoutCreatedHandlers.Add(value);
remove => flyoutCreatedHandlers.Remove(value);
}
public static event FlyoutCreatedEventHandler FlyoutCreated
public static event FlyoutClosedEventHandler FlyoutClosed
{
add => flyoutCloseHandlers.Add(value);
remove => flyoutCloseHandlers.Remove(value);
}
private static readonly List<FlyoutCreatedEventHandler> flyoutCreatedHandlers = new();
private static readonly List<FlyoutClosedEventHandler> flyoutCloseHandlers = new();
private static object? tagToAssign = null;
public static Control? ParentContext { get; private set; } = null;
static FlyoutBase()
{
RadFlyoutManager.ContentCreated += RadFlyoutManager_ContentCreated;
RadFlyoutManager.FlyoutClosed += RadFlyoutManager_FlyoutClosed;
}
private static void RadFlyoutManager_ContentCreated(ContentCreatedEventArgs e)
{
if (e.Content is FlyoutBase dialogBase)
{
add => flyoutCreatedHandlers.Add(value);
remove => flyoutCreatedHandlers.Remove(value);
}
if (tagToAssign != null)
dialogBase.Tag = tagToAssign;
public static event FlyoutClosedEventHandler FlyoutClosed
{
add => flyoutCloseHandlers.Add(value);
remove => flyoutCloseHandlers.Remove(value);
}
var eventArgs = new FlyoutCreatedEventArgs((FlyoutBase)e.Content);
private static readonly List<FlyoutCreatedEventHandler> flyoutCreatedHandlers = new();
private static readonly List<FlyoutClosedEventHandler> flyoutCloseHandlers = new();
private static object? tagToAssign = null;
public static Control? ParentContext { get; private set; } = null;
if (dialogBase is ILoadContent iLoadContent)
iLoadContent.LoadContent();
static FlyoutBase()
{
RadFlyoutManager.ContentCreated += RadFlyoutManager_ContentCreated;
RadFlyoutManager.FlyoutClosed += RadFlyoutManager_FlyoutClosed;
}
private static void RadFlyoutManager_ContentCreated(ContentCreatedEventArgs e)
{
if (e.Content is FlyoutBase dialogBase)
foreach (var args in flyoutCreatedHandlers)
{
if (tagToAssign != null)
dialogBase.Tag = tagToAssign;
var eventArgs = new FlyoutCreatedEventArgs((FlyoutBase)e.Content);
if (dialogBase is ILoadContent iLoadContent)
iLoadContent.LoadContent();
foreach (var args in flyoutCreatedHandlers)
{
if (ParentContext != null)
ParentContext?.Invoke(args, eventArgs);
else
args.Invoke(eventArgs);
}
if (ParentContext != null)
ParentContext?.Invoke(args, eventArgs);
else
args.Invoke(eventArgs);
}
}
private static void RadFlyoutManager_FlyoutClosed(global::Telerik.WinControls.UI.SplashScreen.FlyoutClosedEventArgs e)
{
if (e.Content is FlyoutBase dialogBase)
{
var eventArgs = new FlyoutClosedEventArgs((FlyoutBase)e.Content);
foreach (var args in flyoutCloseHandlers)
{
if (ParentContext != null)
ParentContext?.Invoke(args, eventArgs);
else
args.Invoke(eventArgs);
}
}
ParentContext = null;
}
public static void Show<T>(Control controlToAssociate, object? tag = null)
{
Show(controlToAssociate, typeof(T), tag);
}
public static void Show(Control controlToAssociate, Type flyoutContentType, object? tag = null)
{
tagToAssign = tag;
ParentContext = controlToAssociate;
RadFlyoutManager.Show(controlToAssociate, flyoutContentType);
}
protected static void CloseFlyout()
{
if (ParentContext == null)
throw new NullReferenceException(nameof(ParentContext));
ParentContext.BeginInvoke(RadFlyoutManager.Close);
}
}
private static void RadFlyoutManager_FlyoutClosed(global::Telerik.WinControls.UI.SplashScreen.FlyoutClosedEventArgs e)
{
if (e.Content is FlyoutBase dialogBase)
{
var eventArgs = new FlyoutClosedEventArgs((FlyoutBase)e.Content);
foreach (var args in flyoutCloseHandlers)
{
if (ParentContext != null)
ParentContext?.Invoke(args, eventArgs);
else
args.Invoke(eventArgs);
}
}
ParentContext = null;
}
public static void Show<T>(Control controlToAssociate, object? tag = null)
{
Show(controlToAssociate, typeof(T), tag);
}
public static void Show(Control controlToAssociate, Type flyoutContentType, object? tag = null)
{
tagToAssign = tag;
ParentContext = controlToAssociate;
RadFlyoutManager.Show(controlToAssociate, flyoutContentType);
}
protected static void CloseFlyout()
{
if (ParentContext == null)
throw new NullReferenceException(nameof(ParentContext));
ParentContext.BeginInvoke(RadFlyoutManager.Close);
}
}

View File

@@ -1,99 +1,85 @@
using Pilz.UI.Telerik;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.WinControls;
using Telerik.WinControls.UI;
using Telerik.WinControls.UI.SplashScreen;
using static Telerik.WinControls.UI.PopupEditorNotificationData;
using Telerik.WinControls;
namespace Pilz.UI.Telerik.Dialogs
namespace Pilz.UI.Telerik.Dialogs;
public partial class FlyoutBase : UserControl
{
public partial class FlyoutBase : UserControl
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;
protected bool ActionPanelVisible
{
public static RadSvgImage? CancelSvg { get; set; } = null;
public static RadSvgImage? ConfirmSvg { get; set; } = null;
get => tableLayoutPanel_ActionButtons.Visible;
set => tableLayoutPanel_ActionButtons.Visible = value;
}
public DialogResult Result { get; protected set; }
public bool RegisterDialogAccept { get; set; } = true;
public bool RegisterDialogCancel { get; set; } = false;
protected bool CancelButtonVisible
{
get => radButton_Cancel.Visible;
set => radButton_Cancel.Visible = value;
}
protected bool ActionPanelVisible
protected bool CancelButtonEnable
{
get => radButton_Cancel.Enabled;
set => radButton_Cancel.Enabled = value;
}
protected bool ConfirmButtonEnable
{
get => radButton_Confirm.Enabled;
set => radButton_Confirm.Enabled = value;
}
protected FlyoutBase()
{
InitializeComponent();
ParentChanged += FlyoutDialogBase_ParentChanged;
// SVG Symbols
radButton_Cancel.SvgImage = CancelSvg;
radButton_Confirm.SvgImage = ConfirmSvg;
}
private void FlyoutDialogBase_ParentChanged(object? sender, EventArgs e)
{
var frm = FindForm();
if (frm != null)
{
get => tableLayoutPanel_ActionButtons.Visible;
set => tableLayoutPanel_ActionButtons.Visible = value;
}
protected bool CancelButtonVisible
{
get => radButton_Cancel.Visible;
set => radButton_Cancel.Visible = value;
}
protected bool CancelButtonEnable
{
get => radButton_Cancel.Enabled;
set => radButton_Cancel.Enabled = value;
}
protected bool ConfirmButtonEnable
{
get => radButton_Confirm.Enabled;
set => radButton_Confirm.Enabled = value;
}
protected FlyoutBase()
{
InitializeComponent();
ParentChanged += FlyoutDialogBase_ParentChanged;
// SVG Symbols
radButton_Cancel.SvgImage = CancelSvg;
radButton_Confirm.SvgImage = ConfirmSvg;
}
private 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;
}
}
protected void Close(DialogResult result)
{
Result = result;
if (FindForm() is DialogBase dialogForm)
dialogForm.Close();
else
CloseFlyout();
}
private void RadButton_Confirm_Click(object sender, EventArgs e)
{
if (ValidateOK())
Close(DialogResult.OK);
}
private void RadButton_Cancel_Click(object sender, EventArgs e)
{
Close(DialogResult.Cancel);
}
protected virtual bool ValidateOK()
{
return true;
if (RegisterDialogAccept)
frm.AcceptButton = radButton_Confirm;
if (RegisterDialogCancel)
frm.CancelButton = radButton_Cancel;
}
}
protected void Close(DialogResult result)
{
Result = result;
if (FindForm() is DialogBase dialogForm)
dialogForm.Close();
else
CloseFlyout();
}
private void RadButton_Confirm_Click(object sender, EventArgs e)
{
if (ValidateOK())
Close(DialogResult.OK);
}
private void RadButton_Cancel_Click(object sender, EventArgs e)
{
Close(DialogResult.Cancel);
}
protected virtual bool ValidateOK()
{
return true;
}
}

View File

@@ -1,18 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Pilz.UI.Telerik.Dialogs;
namespace Pilz.UI.Telerik.Dialogs
public class FlyoutClosedEventArgs : global::Telerik.WinControls.UI.SplashScreen.FlyoutClosedEventArgs
{
public class FlyoutClosedEventArgs : global::Telerik.WinControls.UI.SplashScreen.FlyoutClosedEventArgs
{
public new FlyoutBase? Content => base.Content as FlyoutBase;
public new FlyoutBase? Content => base.Content as FlyoutBase;
public FlyoutClosedEventArgs(FlyoutBase content) : base(content)
{
}
public FlyoutClosedEventArgs(FlyoutBase content) : base(content)
{
}
}

View File

@@ -1,19 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Telerik.WinControls.UI.SplashScreen;
using Telerik.WinControls.UI.SplashScreen;
namespace Pilz.UI.Telerik.Dialogs
namespace Pilz.UI.Telerik.Dialogs;
public class FlyoutCreatedEventArgs : ContentCreatedEventArgs
{
public class FlyoutCreatedEventArgs : ContentCreatedEventArgs
{
public new FlyoutBase? Content => base.Content as FlyoutBase;
public new FlyoutBase? Content => base.Content as FlyoutBase;
public FlyoutCreatedEventArgs(FlyoutBase content) : base(content)
{
}
public FlyoutCreatedEventArgs(FlyoutBase content) : base(content)
{
}
}

View File

@@ -1,13 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Pilz.UI.Telerik.Dialogs;
namespace Pilz.UI.Telerik.Dialogs
public interface ILoadContent
{
public interface ILoadContent
{
void LoadContent();
}
void LoadContent();
}