This commit is contained in:
于智纯
2025-09-17 22:02:20 +08:00
13 changed files with 258 additions and 40 deletions

View File

@@ -29,6 +29,9 @@ namespace Deedy.Activity
[TemplatePart(Name = PART_StateDecorator, Type = typeof(ViewerStateDecorator))]
public class ActionViewer : Control, IActionViewer
{
public static double IndentRuler { get; set; } = 30;
public const string PART_ItemsContainer = "PART_ItemsContainer";
public const string PART_TitleContainer = "PART_TitleContainer";
public const string PART_StateDecorator = "PART_StateDecorator";
@@ -46,7 +49,7 @@ namespace Deedy.Activity
{
ToolTipService.SetInitialShowDelay(this, 0);
ToolTipService.SetBetweenShowDelay(this, 0);
this.LogInfos = new LogInfoCollection();
this.LogInfos = new();
}
public override void OnApplyTemplate()
{
@@ -72,6 +75,7 @@ namespace Deedy.Activity
/// <returns>字段中的值</returns>
protected virtual T GetField<T>(ref T field, [CallerMemberName] string? propertyName = null)
{
//TODO这里处理内部属性获取逻辑包括运行时参数映射逻辑
return field;
}
/// <summary>
@@ -85,6 +89,7 @@ namespace Deedy.Activity
protected virtual bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
//TODO这里处理内部属性变更逻辑包括运行时参数映射逻辑
field = value;
OnPropertyChanged(propertyName);
return true;
@@ -294,8 +299,28 @@ namespace Deedy.Activity
protected internal set { SetValue(IsSelectedPropertyKey, value); }
}
public static readonly DependencyPropertyKey IsSelectedPropertyKey =
DependencyProperty.RegisterReadOnly("IsSelected", typeof(bool), typeof(ActionViewer), new PropertyMetadata(false));
DependencyProperty.RegisterReadOnly("IsSelected", typeof(bool), typeof(ActionViewer), new PropertyMetadata(false,
(d, e) => (d as ActionViewer)?.IsSelected_PropertyChangedCallback(e)));
public static readonly DependencyProperty IsSelectedProperty = IsSelectedPropertyKey.DependencyProperty;
/// <summary>
/// 处理「ActionViewer.IsSelected」属性变更
/// </summary>
protected virtual void IsSelected_PropertyChangedCallback(DependencyPropertyChangedEventArgs e)
{
if ((bool)e.NewValue)
{
//TODO发送节点选中事件
if (this.ActionElement is IContainerForFunction container)
{
if (container.IsEmbedded) this.IsExpanded = true;
else
{
//TODO发送打开辅助编辑器事件
}
}
}
this.RefreshViewerState();
}
/// <summary>
/// 是否可被展开
@@ -487,6 +512,19 @@ namespace Deedy.Activity
public static readonly DependencyPropertyKey MarginCorrection_TopBottomPropertyKey =
DependencyProperty.RegisterReadOnly("MarginCorrection_TopBottom", typeof(Thickness), typeof(ActionViewer), new PropertyMetadata(new Thickness()));
public static readonly DependencyProperty MarginCorrection_TopBottomProperty = MarginCorrection_TopBottomPropertyKey.DependencyProperty;
/// <summary>
/// 缩进边距修正
/// </summary>
public Thickness MarginCorrection_Indentation
{
get { return (Thickness)GetValue(MarginCorrection_IndentationProperty); }
protected internal set { SetValue(MarginCorrection_IndentationPropertyKey, value); }
}
public static readonly DependencyPropertyKey MarginCorrection_IndentationPropertyKey =
DependencyProperty.RegisterReadOnly("MarginCorrection_Indentation", typeof(Thickness), typeof(ActionViewer), new PropertyMetadata(new Thickness()));
public static readonly DependencyProperty MarginCorrection_IndentationProperty = MarginCorrection_IndentationPropertyKey.DependencyProperty;
/// <summary>
/// 动作节点
/// </summary>
@@ -546,7 +584,7 @@ namespace Deedy.Activity
if (newValue.IsLockedElement)
{
this.IsDraggable = false;
this.IsSelectable = false;
this.IsSelectable = newValue is IContainerForFunction;
}
else
{
@@ -554,45 +592,30 @@ namespace Deedy.Activity
this.IsSelectable = true;
}
if (newValue is ICombinedElement newCombinedElement)
if (newValue is ICombinedElement newCombined)
{
this.IsExpandable = true;
this.ElementCount = newCombinedElement.Elements.Count;
newCombinedElement.Elements.CollectionChanged += Elements_CollectionChanged;
this.ElementCount = newCombined.Elements.Count;
newCombined.Elements.CollectionChanged += Elements_CollectionChanged;
}
else this.IsExpandable = false;
if (newValue is ICriticalZoneManageable criticalZoneManageable)
if (newValue is ICriticalZoneManageable criticalZone)
{
if (criticalZoneManageable.IsLeaveZoneHidden) this.ShowLeaveZone = Visibility.Collapsed;
if (criticalZoneManageable.IsEntryZoneHidden) this.ShowEntryZone = Visibility.Collapsed;
if (criticalZone.IsLeaveZoneHidden) this.ShowLeaveZone = Visibility.Collapsed;
if (criticalZone.IsEntryZoneHidden) this.ShowEntryZone = Visibility.Collapsed;
}
if (newValue is IExitlineManageable exitlinemanageable)
{
if ((exitlinemanageable.ExitlinePosition & ExitlinePosition.LeftLower) == ExitlinePosition.LeftLower)
this.ShowLeftExitline = Visibility.Visible;
else if ((exitlinemanageable.ExitlinePosition & ExitlinePosition.Rightlower) == ExitlinePosition.Rightlower)
this.ShowRightExitline = Visibility.Visible;
else if ((exitlinemanageable.ExitlinePosition & ExitlinePosition.Underline) == ExitlinePosition.Underline)
if (newValue is IContainerWithExitline withExitline)
{
if (withExitline.ExitlinePosition.HasFlag(ExitlinePosition.LeftLower))
this.ShowLeftExitline = Visibility.Visible;
if (withExitline.ExitlinePosition.HasFlag(ExitlinePosition.Rightlower))
this.ShowRightExitline = Visibility.Visible;
// 新元素被托管渲染后调整子元素退出线位置
withExitline.AdjustExitlinePosition();
}
if (exitlinemanageable.ExitlinePosition == ExitlinePosition.LeftLower || exitlinemanageable.ExitlinePosition == ExitlinePosition.Rightlower)
{
//TODO根据退出线方向是否相同的设置项调整子节点的退出线位置
if (exitlinemanageable.IsExitlineAtSamePosition == true)
{
//TODO同向退出线控制
}
if (exitlinemanageable.IsExitlineAtSamePosition == false)
{
//TODO对向退出线控制
}
}
}
if (newValue is ILogicController logicController)
{
switch (logicController.LogicalBehavior)
@@ -602,8 +625,7 @@ namespace Deedy.Activity
case LogicalBehavior.Break: this.ShowBreakHandle = Visibility.Visible; break;
case LogicalBehavior.Continue: this.ShowContinueHandle = Visibility.Visible; break;
case LogicalBehavior.Customize: this.ShowCustomizeHandle = Visibility.Visible; break;
default:
break;
default: break;
}
}
//TODO根据节点的特征与当前工作状态来判定如何处理当前视图的属性
@@ -618,6 +640,8 @@ namespace Deedy.Activity
this.IsExpanded = true;
this.ElementCount = combined.Elements.Count;
}
// 节点集合变更时调整退出线位置
if (this.ActionElement is IContainerWithExitline container) container.AdjustExitlinePosition();
}
protected virtual void ActionElement_PropertyChanged(object? sender, PropertyChangedEventArgs e)
@@ -625,10 +649,15 @@ namespace Deedy.Activity
switch (e.PropertyName)
{
//TODO处理托管的IActionElement节点的属性变更
case nameof(IElement.DepthLevel):
this.MarginCorrection_Indentation = new Thickness(ActionViewer.IndentRuler * this.ActionElement.DepthLevel, 0, 0, 0);
break;
case nameof(IActionElement.InstantInfo):
this.InstantInfo = this.ActionElement.InstantInfo;
break;
case nameof(IExitlineManageable):
case nameof(IContainerWithExitline.ExitlinePosition):
// 自身退出线变更时调整所有子节点退出线位置
(this.ActionElement as IContainerWithExitline)?.AdjustExitlinePosition();
break;
default: break;
}
@@ -713,9 +742,9 @@ namespace Deedy.Activity
base.OnDragLeave(e);
}
private bool _CanDropInParent = false;
private bool _CanDropChild = false;
private DropPlacement _DropPlacement = DropPlacement.Uncertain;
protected internal bool _CanDropInParent = false;
protected internal bool _CanDropChild = false;
protected internal DropPlacement _DropPlacement = DropPlacement.Uncertain;
protected override void OnDragOver(DragEventArgs e)
{
if (this.IsEventNeedToHandle(e.OriginalSource))
@@ -818,8 +847,8 @@ namespace Deedy.Activity
ToolTipService.SetVerticalOffset(this, position.Y + 16);
}
}
private readonly object _DragLock = new();
private Point? _DragStartPoint = null;
protected internal readonly object _DragLock = new();
protected internal Point? _DragStartPoint = null;
protected override void OnPreviewMouseMove(MouseEventArgs e)
{

View File

@@ -55,6 +55,7 @@ namespace Deedy.Activity
/// <returns>字段中的值</returns>
protected virtual T GetField<T>(ref T field, [CallerMemberName] string? propertyName = null)
{
//TODO这里处理内部属性获取逻辑包括运行时参数映射逻辑
return field;
}
/// <summary>
@@ -68,6 +69,7 @@ namespace Deedy.Activity
protected virtual bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
//TODO这里处理内部属性变更逻辑包括运行时参数映射逻辑
field = value;
OnPropertyChanged(propertyName);
return true;

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace Deedy.Activity
{
@@ -10,5 +11,7 @@ namespace Deedy.Activity
{
public DragDropData() { }
public DropPlacement Placement { get; set; }
public DragDropEffects DragEffect { get; set; }
public DragDropEffects DropEffects { get; set; }
}
}

View File

@@ -17,10 +17,18 @@ namespace Deedy.Activity
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);
}
/// <summary>
/// 如果类型上没有组装规则,则认为不允许组装,否则按照组装规则处理
/// </summary>
/// <param name="unit">要进行组装检查的单元实例</param>
/// <param name="element">要进行组装检查的单元实例</param>
/// <returns>是否允许组装</returns>
public bool CombineChecking(IElement element, out DragDropEffects effects)
{

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Activity
{
public interface IContainerForFunction : IContainerElement
{
/// <summary>
/// 是否为嵌入式功能容器
/// <para>True不需要打开独立编辑器选中时展开手动折叠</para>
/// <para>False选中时需要打开独立编辑器手动关闭有多个选项卡可以同时打开多个编辑器</para>
/// </summary>
public bool IsEmbedded { get; set; }
}
}

View File

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Deedy.Activity
{
public interface IExitlineManageable
public interface IContainerWithExitline : IContainerElement, IActionElement
{
ExitlinePosition ExitlinePosition { get; set; }
bool? IsExitlineAtSamePosition { get; set; }

View File

@@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Deedy.Activity
{
public interface IFunctionAction : IElement
{
//TODO这里需要定义信道延迟执行与定时执行等参数
}
}

View File

@@ -0,0 +1,12 @@
<UserControl x:Class="Deedy.Activity.ActionDesigner"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Deedy.Activity"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

View File

@@ -0,0 +1,60 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Deedy.Activity
{
/// <summary>
/// ActionDesigner.xaml 的交互逻辑
/// </summary>
public partial class ActionDesigner : UserControl
{
private bool _PassthroughOpenDesignerEvent;
public ActionDesigner()
{
InitializeComponent();
}
public ActionDesigner(IActionElement actionElement, bool passthroughOpenEvent = false) : this()
{
this.ActionElement = actionElement;
this._PassthroughOpenDesignerEvent = passthroughOpenEvent;
}
/// <summary>
/// 被托管的动作元素
/// </summary>
public IActionElement ActionElement
{
get { return (IActionElement)GetValue(ActionElementProperty); }
set { SetValue(ActionElementProperty, value); }
}
public static readonly DependencyProperty ActionElementProperty =
DependencyProperty.Register("ActionElement", typeof(IActionElement), typeof(ActionDesigner), new PropertyMetadata(null,
(d, e) => (d as ActionDesigner)?.ActionElement_PropertyChangedCallback(e)));
/// <summary>
/// 处理「ActionDesigner.ActionElement」属性变更
/// </summary>
protected virtual void ActionElement_PropertyChangedCallback(DependencyPropertyChangedEventArgs e)
{
if (e.OldValue == e.NewValue) return;
if (e.OldValue is IActionElement oldValue)
{
//TODO解绑事件监听器
}
if (e.NewValue is IActionElement newValue)
{
//TODO绑定事件监听器
}
}
}
}

View File

@@ -0,0 +1,12 @@
<UserControl x:Class="Deedy.Activity.VisualDesigner"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Deedy.Activity"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
</Grid>
</UserControl>

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Deedy.Activity
{
/// <summary>
/// VisualDesigner.xaml 的交互逻辑
/// </summary>
public partial class VisualDesigner : UserControl
{
public VisualDesigner()
{
InitializeComponent();
}
}
}

View File

@@ -212,5 +212,34 @@ namespace Deedy.Activity
return default;
}
public static void AdjustExitlinePosition(this IContainerWithExitline container)
{
if (container != null
&& (container.ExitlinePosition == ExitlinePosition.LeftLower
|| container.ExitlinePosition == ExitlinePosition.Rightlower))
{
var lastChild = container.Elements[container.Elements.Count - 1] as IContainerWithExitline;
if (lastChild != null
&& (lastChild.ExitlinePosition == ExitlinePosition.LeftLower
|| lastChild.ExitlinePosition == ExitlinePosition.Rightlower))
{
if (container.IsExitlineAtSamePosition == true)
{
if (container.ExitlinePosition == ExitlinePosition.LeftLower)
lastChild.ExitlinePosition = ExitlinePosition.LeftLower;
if (container.ExitlinePosition == ExitlinePosition.Rightlower)
lastChild.ExitlinePosition = ExitlinePosition.Rightlower;
}
if (container.IsExitlineAtSamePosition == false)
{
if (container.ExitlinePosition == ExitlinePosition.LeftLower)
lastChild.ExitlinePosition = ExitlinePosition.LeftLower;
if (container.ExitlinePosition == ExitlinePosition.Rightlower)
lastChild.ExitlinePosition = ExitlinePosition.Rightlower;
}
//lastChild.AdjustExitlinePosition();
}
}
}
}
}

View File

@@ -14,6 +14,9 @@ namespace Deedy.Activity
{
public interface IActionViewer : IActivity, INotifyPropertyChanged
{
public static double IndentRuler { get; set; }
public static double LineHeight { get; set; }
[AllowNull]
public IActionElement ActionElement { get; set; }
public Visibility ShowBreakHandle { get; }
@@ -46,6 +49,7 @@ namespace Deedy.Activity
public Thickness MarginCorrection_Top { get; }
public Thickness MarginCorrection_Bottom { get; }
public Thickness MarginCorrection_TopBottom { get; }
public Thickness MarginCorrection_Indentation { get; }
public ImageSource ElementIcon { get; }
[AllowNull]
public StyleSelector StyleSelector { get; set; }