From a8a172b00ca8e2c0e265c33358822ee43d14b31d Mon Sep 17 00:00:00 2001 From: zengwenjie <1663900244@qq.com> Date: Thu, 18 Sep 2025 18:22:58 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=96=E5=86=99=E3=80=8CIContainerElement?= =?UTF-8?q?=E3=80=8D=E7=B1=BB=E5=9E=8B=E7=9A=84=E8=BE=85=E5=8A=A9=E6=89=A9?= =?UTF-8?q?=E5=B1=95=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Contract/Interface/IContainerElement.cs | 71 +-------------- .../Deedy.Activity/Helpers/ActionHelper.cs | 87 +++++++++++++++++++ 2 files changed, 90 insertions(+), 68 deletions(-) create mode 100644 DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs diff --git a/DeedyDesigner/Deedy.Activity/Contract/Interface/IContainerElement.cs b/DeedyDesigner/Deedy.Activity/Contract/Interface/IContainerElement.cs index 218d431..f469cc4 100644 --- a/DeedyDesigner/Deedy.Activity/Contract/Interface/IContainerElement.cs +++ b/DeedyDesigner/Deedy.Activity/Contract/Interface/IContainerElement.cs @@ -11,78 +11,13 @@ namespace Deedy.Activity { public void Append(IElement element) => this.Elements.Add(element); public void Remove(IElement element) => this.Elements.Remove(element); - public void Insert(IElement element, uint index) - { - if (element == null) return; - if (index < this.Elements.Count) this.Elements.Insert((int)index, element); - if (index >= this.Elements.Count) this.Elements.Add(element); - } - public void MoveTo(IElement element, uint index) - { - if (element == null) return; - int newIndex = (index >= this.Elements.Count) ? this.Elements.Count - 1 : (int)index; - int oldIndex = this.Elements.IndexOf(element); - if (oldIndex < 0) this.Elements.Insert(newIndex, element); - else this.Elements.Move(oldIndex, newIndex); - } + public void Insert(IElement element, uint index) => this.Help_Insert(element, index); + public void MoveTo(IElement element, uint index) => this.Help_MoveTo(element, index); /// /// 如果类型上没有组装规则,则认为不允许组装,否则按照组装规则处理 /// /// 要进行组装检查的单元实例 /// 是否允许组装 - public bool CombineChecking(IElement element, out DragDropEffects effects) - { - DragDropEffects resultEffects = DragDropEffects.None; - List _AllowTypes = []; - List _RejectTypes = []; - this.GetCombineRules(ref _AllowTypes, ref _RejectTypes); - if (element == null) - { - effects = resultEffects; - return false; - } - // 如果没有组装规则则直接返回 - if (_AllowTypes.Count == 0 && _RejectTypes.Count == 0) - { - effects = resultEffects; - return false; - } - - Type uType = element.GetType(); - bool allow = false; - foreach (var aRule in _AllowTypes) - { - if (aRule.BaseType.IsAssignableFrom(uType)) - { - if (!aRule.Excluded.Contains(uType)) - { - allow = true; - break; - } - } - } - if (!allow) - { - effects = resultEffects; - return allow; // 如果没有匹配的放行规则则直接返回 - } - - resultEffects |= DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link; - - foreach (var rRule in _RejectTypes) - { - if (rRule.BaseType.IsAssignableFrom(uType)) - { - if (!rRule.Excluded.Contains(uType)) - { - resultEffects &= DragDropEffects.None; - allow = false; - break; - } - } - } - effects = resultEffects; - return allow; - } + public bool CombineChecking(IElement element, out DragDropEffects effects) => this.Help_CombineChecking(element, out effects); } } diff --git a/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs b/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs new file mode 100644 index 0000000..e5919c4 --- /dev/null +++ b/DeedyDesigner/Deedy.Activity/Helpers/ActionHelper.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; + +namespace Deedy.Activity +{ + public static partial class Helper + { + /// + /// 如果类型上没有组装规则,则认为不允许组装,否则按照组装规则处理 + /// + /// 要进行组装检查的单元实例 + /// 是否允许组装 + public static bool Help_CombineChecking(this IContainerElement container, IElement element, out DragDropEffects effects) + { + DragDropEffects resultEffects = DragDropEffects.None; + List _AllowTypes = []; + List _RejectTypes = []; + GetCombineRules(container, ref _AllowTypes, ref _RejectTypes); + + if (element == null) + { + effects = resultEffects; + return false; + } + // 如果没有组装规则则直接返回 + if (_AllowTypes.Count == 0 && _RejectTypes.Count == 0) + { + effects = resultEffects; + return false; + } + + Type uType = element.GetType(); + bool allow = false; + foreach (var aRule in _AllowTypes) + { + if (aRule.BaseType.IsAssignableFrom(uType)) + { + if (!aRule.Excluded.Contains(uType)) + { + allow = true; + break; + } + } + } + if (!allow) + { + effects = resultEffects; + return allow; // 如果没有匹配的放行规则则直接返回 + } + + resultEffects |= DragDropEffects.Copy | DragDropEffects.Move | DragDropEffects.Link; + + foreach (var rRule in _RejectTypes) + { + if (rRule.BaseType.IsAssignableFrom(uType)) + { + if (!rRule.Excluded.Contains(uType)) + { + resultEffects &= DragDropEffects.None; + allow = false; + break; + } + } + } + effects = resultEffects; + return allow; + } + public static void Help_Insert(this IContainerElement @this, IElement element, uint index) + { + if (element == null) return; + if (index < @this.Elements.Count) @this.Elements.Insert((int)index, element); + if (index >= @this.Elements.Count) @this.Elements.Add(element); + } + public static void Help_MoveTo(this IContainerElement @this, IElement element, uint index) + { + if (element == null) return; + int newIndex = (index >= @this.Elements.Count) ? @this.Elements.Count - 1 : (int)index; + int oldIndex = @this.Elements.IndexOf(element); + if (oldIndex < 0) @this.Elements.Insert(newIndex, element); + else @this.Elements.Move(oldIndex, newIndex); + } + } +}