Agrarsense
DragAndDropWidget.cpp
Go to the documentation of this file.
1// Copyright (c) 2024 FrostBit Software Lab at the Lapland University of Applied Sciences
2//
3// This work is licensed under the terms of the MIT license.
4// For a copy, see <https://opensource.org/licenses/MIT>.
5
6#include "DragAndDropWidget.h"
7
9
10void SDragAndDropWidget::Construct(const FArguments& InArgs)
11{
12
13}
14
15FReply SDragAndDropWidget::OnDragOver(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent)
16{
17 TSharedPtr<FExternalDragOperation> DragDropOp = DragDropEvent.GetOperationAs<FExternalDragOperation>();
18 if (DragDropOp.IsValid() && DragDropOp->HasFiles())
19 {
20 // For below OnDrop to work, Handled must be returned here.
21 return FReply::Handled();
22 }
23
24 return FReply::Unhandled();
25}
26
27FReply SDragAndDropWidget::OnDrop(const FGeometry& MyGeometry, const FDragDropEvent& DragDropEvent)
28{
29 SCompoundWidget::OnDrop(MyGeometry, DragDropEvent);
30
31 TSharedPtr<FExternalDragOperation> DragDropOp = DragDropEvent.GetOperationAs<FExternalDragOperation>();
32 if (DragDropOp.IsValid() && DragDropOp->HasFiles())
33 {
34 const TArray<FString>& Files = DragDropOp->GetFiles();
35 for (const FString& File : Files)
36 {
37#if WITH_EDITOR
38 UE_LOG(LogTemp, Log, TEXT("Dropped file to window. Path: %s"), *File);
39#endif
40
41 if (FPaths::GetExtension(File).Equals(TEXT("json"), ESearchCase::IgnoreCase))
42 {
43 // Attempt to spawn objects defined in .json file using USimulatorJsonParser
45 }
46 }
47
48 return FReply::Handled();
49 }
50
51 return FReply::Unhandled();
52}
FReply OnDrop(const FGeometry &MyGeometry, const FDragDropEvent &DragDropEvent) override
void Construct(const FArguments &InArgs)
FReply OnDragOver(const FGeometry &MyGeometry, const FDragDropEvent &DragDropEvent) override
static void ParseAndOperateJSONFile(const FString &Path)