From 6da3324a0c4cbbbf83fce90dc225975881667137 Mon Sep 17 00:00:00 2001 From: Taehyub Kim Date: Tue, 10 Sep 2024 21:32:09 +0900 Subject: [PATCH] Apply clean code for Drag and Drop --- .../src/public/DragAndDrop/DragAndDrop.cs | 22 +++---------------- test/NUIDnDMultiWindow/NUIDnDMultiWindow.cs | 2 +- test/NUIDnDSource/NUIDnDSource.cs | 2 +- 3 files changed, 5 insertions(+), 21 deletions(-) diff --git a/src/Tizen.NUI/src/public/DragAndDrop/DragAndDrop.cs b/src/Tizen.NUI/src/public/DragAndDrop/DragAndDrop.cs index c1fd54e9594..e85174325d1 100755 --- a/src/Tizen.NUI/src/public/DragAndDrop/DragAndDrop.cs +++ b/src/Tizen.NUI/src/public/DragAndDrop/DragAndDrop.cs @@ -257,7 +257,7 @@ public void StartDragAndDrop(View sourceView, View shadowView, DragData dragData string [] mimeTypes; string [] dataSet; - if (string.IsNullOrEmpty(dragData.MimeType)) + if (string.IsNullOrEmpty(dragData.MimeType) && dragData.DataMap != null) { mimeTypes = dragData.DataMap.Keys.ToArray(); dataSet = dragData.DataMap.Values.ToArray(); @@ -287,15 +287,7 @@ public void StartDragAndDrop(View sourceView, View shadowView, DragData dragData /// 10 public void AddListener(View targetView, DragAndDropEventHandler callback) { - InternalDragAndDropEventHandler cb = (navtiveDragEvent) => ProcessDragEventTargetCallback(navtiveDragEvent, targetView, callback); - - targetEventDictionary.Add(targetView, cb); - - if (!Interop.DragAndDrop.AddListener(SwigCPtr, View.getCPtr(targetView), "*/*", - new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate(cb)))) - { - throw new InvalidOperationException("Fail to AddListener for View"); - } + AddListener(targetView, "*/*", callback); } /// @@ -348,15 +340,7 @@ public void RemoveListener(View targetView, DragAndDropEventHandler _) [EditorBrowsable(EditorBrowsableState.Never)] public void AddListener(Window targetWindow, DragAndDropWindowEventHandler callback) { - InternalDragAndDropEventHandler cb = (navtiveDragEvent) => ProcessDragEventWindowCallback(navtiveDragEvent, targetWindow, callback); - - targetWindowEventDictionary.Add(targetWindow, cb); - - if (!Interop.DragAndDrop.WindowAddListener(SwigCPtr, Window.getCPtr(targetWindow), "*/*", - new global::System.Runtime.InteropServices.HandleRef(this, Marshal.GetFunctionPointerForDelegate(cb)))) - { - throw new InvalidOperationException("Fail to AddListener for Window"); - } + AddListener(targetWindow, "*/*", callback); } /// diff --git a/test/NUIDnDMultiWindow/NUIDnDMultiWindow.cs b/test/NUIDnDMultiWindow/NUIDnDMultiWindow.cs index 3d95b347b28..dec31805f78 100644 --- a/test/NUIDnDMultiWindow/NUIDnDMultiWindow.cs +++ b/test/NUIDnDMultiWindow/NUIDnDMultiWindow.cs @@ -89,7 +89,7 @@ void Initialize() Tizen.Log.Debug("NUIDnDMultiWindow", "StartDragAndDrop"); shadowView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png"); shadowView.Size = new Size(150, 150); - DragData dragData; + DragData dragData = new DragData(); dragData.MimeType = "text/uri-list"; dragData.Data = Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png"; dnd.StartDragAndDrop(sourceView, shadowView, dragData, OnSourceApp_SourceFunc); diff --git a/test/NUIDnDSource/NUIDnDSource.cs b/test/NUIDnDSource/NUIDnDSource.cs index 7bceebef55c..ae242037a8a 100644 --- a/test/NUIDnDSource/NUIDnDSource.cs +++ b/test/NUIDnDSource/NUIDnDSource.cs @@ -91,7 +91,7 @@ void Initialize() Tizen.Log.Debug("NUIDnDSource", "StartDragAndDrop"); shadowView = new ImageView(Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png"); shadowView.Size = new Size(150, 150); - DragData dragData; + DragData dragData = new DragData(); dragData.MimeType = "text/uri-list"; dragData.Data = Tizen.Applications.Application.Current.DirectoryInfo.SharedResource + "dragsource.png"; dnd.StartDragAndDrop(sourceView, shadowView, dragData, OnSourceEventFunc);