定义核心接口契约
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Deedy.Design
|
||||
{
|
||||
public class DeedyElementCollection : ObservableCollection<IDeedyElement>
|
||||
{
|
||||
public DeedyElementCollection() : this(false) { }
|
||||
public DeedyElementCollection(bool needDistinct = false)
|
||||
{
|
||||
this._needDistinct = needDistinct;
|
||||
}
|
||||
private bool _needDistinct = false;
|
||||
public void AddRange(params IDeedyElement[] elements)
|
||||
{
|
||||
foreach (var element in elements) this.Add(element);
|
||||
}
|
||||
public void AddRange([AllowNull] IEnumerable<IDeedyElement> elements)
|
||||
{
|
||||
if (elements != null) foreach (var element in elements) this.Add(element);
|
||||
}
|
||||
public new void Add([AllowNull] IDeedyElement element)
|
||||
{
|
||||
if (element == null) return;
|
||||
if (this._needDistinct)
|
||||
{
|
||||
foreach (var item in this.Items)
|
||||
{
|
||||
if (element.DEClass == item.DEClass && element.DETitle == item.DETitle) return;
|
||||
}
|
||||
}
|
||||
base.Add(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
54
DeedyDesigner/Deedy.Design/DeedyAction.cs
Normal file
54
DeedyDesigner/Deedy.Design/DeedyAction.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Deedy.Design
|
||||
{
|
||||
public abstract class DeedyAction : IDeedyAction
|
||||
{
|
||||
public string DEClass { get; protected internal set; } = "";
|
||||
public string DETitle { get; set; } = "";
|
||||
public string DERemark { get; set; } = "";
|
||||
public string DEIdentify { get; set; } = "";
|
||||
public IDeedyElement? DeedyParent { get; protected internal set; }
|
||||
public IDeedyViewer? DeedyViewer { get; protected internal set; }
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 发送属性变更通知
|
||||
/// </summary>
|
||||
/// <param name="propertyName">发生变更的属性</param>
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
/// <summary>
|
||||
/// 读取一个字段的值
|
||||
/// </summary>
|
||||
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
|
||||
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
|
||||
/// <param name="propertyName">属性名称;如果在属性的读取访问器中调用可以自动注入</param>
|
||||
/// <returns>字段中的值</returns>
|
||||
protected virtual T GetField<T>(ref T field, [CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
return field;
|
||||
}
|
||||
/// <summary>
|
||||
/// 检查新值是否与原值相等,如果不相等便赋值并发出通知
|
||||
/// </summary>
|
||||
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
|
||||
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
|
||||
/// <param name="value">字段的新值</param>
|
||||
/// <param name="propertyName">要进行变更通知的属性名称;如果在属性的设置访问器中调用可以自动注入</param>
|
||||
/// <returns>值是否有变更</returns>
|
||||
protected virtual bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
|
||||
field = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
12
DeedyDesigner/Deedy.Design/DeedyHelper.cs
Normal file
12
DeedyDesigner/Deedy.Design/DeedyHelper.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Deedy.Design
|
||||
{
|
||||
public static class DeedyHelper
|
||||
{
|
||||
}
|
||||
}
|
||||
57
DeedyDesigner/Deedy.Design/DeedyUIProxy.cs
Normal file
57
DeedyDesigner/Deedy.Design/DeedyUIProxy.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Deedy.Design
|
||||
{
|
||||
public class DeedyUIProxy : IDeedyVisual
|
||||
{
|
||||
private readonly IDeedyVisual _Visual;
|
||||
public DeedyUIProxy(IDeedyVisual visual) { this._Visual = visual; }
|
||||
public string DEClass { get; protected internal set; } = "";
|
||||
public string DETitle { get; set; } = "";
|
||||
public string DERemark { get; set; } = "";
|
||||
public string DEIdentify { get; set; } = "";
|
||||
public IDeedyElement? DeedyParent { get; protected internal set; }
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 发送属性变更通知
|
||||
/// </summary>
|
||||
/// <param name="propertyName">发生变更的属性</param>
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
/// <summary>
|
||||
/// 读取一个字段的值
|
||||
/// </summary>
|
||||
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
|
||||
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
|
||||
/// <param name="propertyName">属性名称;如果在属性的读取访问器中调用可以自动注入</param>
|
||||
/// <returns>字段中的值</returns>
|
||||
protected virtual T GetField<T>(ref T field, [CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
//TODO:这里处理内部属性获取逻辑(包括运行时参数映射逻辑)
|
||||
return field;
|
||||
}
|
||||
/// <summary>
|
||||
/// 检查新值是否与原值相等,如果不相等便赋值并发出通知
|
||||
/// </summary>
|
||||
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
|
||||
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
|
||||
/// <param name="value">字段的新值</param>
|
||||
/// <param name="propertyName">要进行变更通知的属性名称;如果在属性的设置访问器中调用可以自动注入</param>
|
||||
/// <returns>值是否有变更</returns>
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows;
|
||||
@@ -44,11 +47,65 @@ namespace Deedy.Design
|
||||
/// <MyNamespace:DeedyViewer/>
|
||||
///
|
||||
/// </summary>
|
||||
public class DeedyViewer : Control
|
||||
public class DeedyViewer : Control, IDeedyViewer
|
||||
{
|
||||
static DeedyViewer()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(typeof(DeedyViewer), new FrameworkPropertyMetadata(typeof(DeedyViewer)));
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
/// <summary>
|
||||
/// 发送属性变更通知
|
||||
/// </summary>
|
||||
/// <param name="propertyName">发生变更的属性</param>
|
||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
/// <summary>
|
||||
/// 读取一个字段的值
|
||||
/// </summary>
|
||||
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
|
||||
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
|
||||
/// <param name="propertyName">属性名称;如果在属性的读取访问器中调用可以自动注入</param>
|
||||
/// <returns>字段中的值</returns>
|
||||
protected virtual T GetField<T>(ref T field, [CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
return field;
|
||||
}
|
||||
/// <summary>
|
||||
/// 检查新值是否与原值相等,如果不相等便赋值并发出通知
|
||||
/// </summary>
|
||||
/// <typeparam name="T">值的类型,可以通过参数进行自动判定</typeparam>
|
||||
/// <param name="field">字段的引用【注意:此参数通过引用传递】</param>
|
||||
/// <param name="value">字段的新值</param>
|
||||
/// <param name="propertyName">要进行变更通知的属性名称;如果在属性的设置访问器中调用可以自动注入</param>
|
||||
/// <returns>值是否有变更</returns>
|
||||
protected virtual bool SetField<T>(ref T field, T value, [CallerMemberName] string? propertyName = null)
|
||||
{
|
||||
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
|
||||
field = value;
|
||||
OnPropertyChanged(propertyName);
|
||||
return true;
|
||||
}
|
||||
|
||||
[AllowNull, DefaultValue(null)]
|
||||
/// <summary>
|
||||
/// 动作节点
|
||||
/// </summary>
|
||||
public IDeedyAction DeedyAction
|
||||
{
|
||||
get { return (IDeedyAction)GetValue(DeedyActionProperty); }
|
||||
set { SetValue(DeedyActionProperty, value); }
|
||||
}
|
||||
public static readonly DependencyProperty DeedyActionProperty =
|
||||
DependencyProperty.Register("DeedyAction", typeof(IDeedyAction), typeof(DeedyViewer), new PropertyMetadata(null,
|
||||
(d, e) => (d as DeedyViewer)?.DeedyAction_PropertyChangedCallback(d, e)));
|
||||
/// <summary>
|
||||
/// 处理「DeedyActionViewer.DeedyAction」属性变更
|
||||
/// </summary>
|
||||
protected virtual void DeedyAction_PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
13
DeedyDesigner/Deedy.Design/IDeedyAction.cs
Normal file
13
DeedyDesigner/Deedy.Design/IDeedyAction.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Deedy.Design
|
||||
{
|
||||
public interface IDeedyAction : IDeedyElement
|
||||
{
|
||||
public IDeedyViewer? DeedyViewer { get; }
|
||||
}
|
||||
}
|
||||
20
DeedyDesigner/Deedy.Design/IDeedyElement.cs
Normal file
20
DeedyDesigner/Deedy.Design/IDeedyElement.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Deedy.Design
|
||||
{
|
||||
public interface IDeedyElement : INotifyPropertyChanged
|
||||
{
|
||||
public string DEClass { get; }
|
||||
public string DETitle { get; set; }
|
||||
public string DERemark { get; set; }
|
||||
public string DEIdentify { get; set; }
|
||||
public IDeedyElement? DeedyParent { get; }
|
||||
|
||||
}
|
||||
}
|
||||
16
DeedyDesigner/Deedy.Design/IDeedyViewer.cs
Normal file
16
DeedyDesigner/Deedy.Design/IDeedyViewer.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Deedy.Design
|
||||
{
|
||||
public interface IDeedyViewer : INotifyPropertyChanged
|
||||
{
|
||||
[AllowNull]
|
||||
public IDeedyAction DeedyAction { get; set; }
|
||||
}
|
||||
}
|
||||
12
DeedyDesigner/Deedy.Design/IDeedyVisual.cs
Normal file
12
DeedyDesigner/Deedy.Design/IDeedyVisual.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Deedy.Design
|
||||
{
|
||||
public interface IDeedyVisual : IDeedyElement
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user