From 375b488be2666cd56e70728624f4eadaefee0440 Mon Sep 17 00:00:00 2001
From: chenghaoran <chenghaoran@ipilotwhale.com>
Date: 星期二, 12 三月 2024 17:36:49 +0800
Subject: [PATCH] 优化项目结构;
---
WPFProject/Utils/DdDropHandler.cs | 188 +++++++++++++++++++++++-----------------------
1 files changed, 94 insertions(+), 94 deletions(-)
diff --git a/Utils/DdDropHandler.cs b/WPFProject/Utils/DdDropHandler.cs
similarity index 99%
rename from Utils/DdDropHandler.cs
rename to WPFProject/Utils/DdDropHandler.cs
index 6722c5c..6b60a8d 100644
--- a/Utils/DdDropHandler.cs
+++ b/WPFProject/Utils/DdDropHandler.cs
@@ -1,94 +1,94 @@
-锘縰sing GongSolutions.Wpf.DragDrop;
-using GongSolutions.Wpf.DragDrop.Utilities;
-using System.Collections.Generic;
-using System.ComponentModel;
-using System;
-using System.Windows;
-using System.Windows.Controls;
-using System.Windows.Markup;
-using System.Linq;
-using System.Collections;
-using WPFProject.Models;
-
-namespace WPFProject.Utils
-{
- public class DdDropHandler : DefaultDropHandler
- {
- public bool CanConvert(IDropInfo dropInfo)
- {
- bool InterfaceFilter(Type t, object o) => (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>));
- Type[] enumerableInterfaces = dropInfo.TargetCollection.GetType().FindInterfaces(InterfaceFilter, null);
- var enumerableTypes = from i in enumerableInterfaces
- select i.GetGenericArguments().Single();
-
- if (enumerableTypes.Any())
- {
- Type dataType = TypeUtilities.GetCommonBaseClass(ExtractData(dropInfo.Data));
- return dataType == typeof(FuncModel) && enumerableTypes.Any(t => t==typeof(Step));
- }
-
- return false;
- }
-
- public Step ConvertFunc2Step(FuncModel func) {
- return new Step
- {
- Name = func.Name
- };
- }
-
-
-
- public override void DragOver(IDropInfo dropInfo)
- {
- if (CanAcceptData(dropInfo))
- {
- base.DragOver(dropInfo);
- }
- else if (CanConvert(dropInfo))
- {
- // 鍥哄畾Copy
- dropInfo.Effects = DragDropEffects.Copy;
- var isTreeViewItem = dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter) && dropInfo.VisualTargetItem is TreeViewItem;
- dropInfo.DropTargetAdorner = isTreeViewItem ? DropTargetAdorners.Highlight : DropTargetAdorners.Insert;
- }
- }
-
- public override void Drop(IDropInfo dropInfo)
- {
- if (CanAcceptData(dropInfo))
- {
- base.Drop(dropInfo);
- }
- else if (CanConvert(dropInfo))
- {
- int insertIndex = GetInsertIndex(dropInfo);
- var destinationList = dropInfo.TargetCollection.TryGetList();
- var data = ExtractData(dropInfo.Data).OfType<object>().ToList();
-
- if (destinationList != null)
- {
- var objects2Insert = new List<object>();
-
- foreach (var o in data)
- {
- var obj2Insert = ConvertFunc2Step(o as FuncModel);
-
- objects2Insert.Add(obj2Insert);
-
- destinationList.Insert(insertIndex++, obj2Insert);
- // 涓嬫柟瀵硅薄濡傛灉瀹炵幇浜� IDragItemSource 鎺ュ彛锛屼細鍦ㄨ繖閲岃皟鐢� ItemDropped 鏂规硶锛岀畻鏄悗缃鐞�
- if (obj2Insert is IDragItemSource dragItemSource)
- {
- dragItemSource.ItemDropped(dropInfo);
- }
- }
-
- SelectDroppedItems(dropInfo, objects2Insert);
- }
- }
-
- }
-
- }
-}
+锘縰sing GongSolutions.Wpf.DragDrop;
+using GongSolutions.Wpf.DragDrop.Utilities;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Markup;
+using System.Linq;
+using System.Collections;
+using WPFProject.Models;
+
+namespace WPFProject.Utils
+{
+ public class DdDropHandler : DefaultDropHandler
+ {
+ public bool CanConvert(IDropInfo dropInfo)
+ {
+ bool InterfaceFilter(Type t, object o) => (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(IEnumerable<>));
+ Type[] enumerableInterfaces = dropInfo.TargetCollection.GetType().FindInterfaces(InterfaceFilter, null);
+ var enumerableTypes = from i in enumerableInterfaces
+ select i.GetGenericArguments().Single();
+
+ if (enumerableTypes.Any())
+ {
+ Type dataType = TypeUtilities.GetCommonBaseClass(ExtractData(dropInfo.Data));
+ return dataType == typeof(FuncModel) && enumerableTypes.Any(t => t==typeof(Step));
+ }
+
+ return false;
+ }
+
+ public Step ConvertFunc2Step(FuncModel func) {
+ return new Step
+ {
+ Name = func.Name
+ };
+ }
+
+
+
+ public override void DragOver(IDropInfo dropInfo)
+ {
+ if (CanAcceptData(dropInfo))
+ {
+ base.DragOver(dropInfo);
+ }
+ else if (CanConvert(dropInfo))
+ {
+ // 鍥哄畾Copy
+ dropInfo.Effects = DragDropEffects.Copy;
+ var isTreeViewItem = dropInfo.InsertPosition.HasFlag(RelativeInsertPosition.TargetItemCenter) && dropInfo.VisualTargetItem is TreeViewItem;
+ dropInfo.DropTargetAdorner = isTreeViewItem ? DropTargetAdorners.Highlight : DropTargetAdorners.Insert;
+ }
+ }
+
+ public override void Drop(IDropInfo dropInfo)
+ {
+ if (CanAcceptData(dropInfo))
+ {
+ base.Drop(dropInfo);
+ }
+ else if (CanConvert(dropInfo))
+ {
+ int insertIndex = GetInsertIndex(dropInfo);
+ var destinationList = dropInfo.TargetCollection.TryGetList();
+ var data = ExtractData(dropInfo.Data).OfType<object>().ToList();
+
+ if (destinationList != null)
+ {
+ var objects2Insert = new List<object>();
+
+ foreach (var o in data)
+ {
+ var obj2Insert = ConvertFunc2Step(o as FuncModel);
+
+ objects2Insert.Add(obj2Insert);
+
+ destinationList.Insert(insertIndex++, obj2Insert);
+ // 涓嬫柟瀵硅薄濡傛灉瀹炵幇浜� IDragItemSource 鎺ュ彛锛屼細鍦ㄨ繖閲岃皟鐢� ItemDropped 鏂规硶锛岀畻鏄悗缃鐞�
+ if (obj2Insert is IDragItemSource dragItemSource)
+ {
+ dragItemSource.ItemDropped(dropInfo);
+ }
+ }
+
+ SelectDroppedItems(dropInfo, objects2Insert);
+ }
+ }
+
+ }
+
+ }
+}
--
Gitblit v1.9.1