-
Notifications
You must be signed in to change notification settings - Fork 765
Expand file tree
/
Copy pathPythonProjectItem.cpp
More file actions
124 lines (110 loc) · 2.85 KB
/
PythonProjectItem.cpp
File metadata and controls
124 lines (110 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "PythonProjectItem.h"
#include "PythonEditorPrivatePCH.h"
#include "DirectoryScanner.h"
#include "Developer/DirectoryWatcher/Public/IDirectoryWatcher.h"
UPythonProjectItem::UPythonProjectItem(const FObjectInitializer& ObjectInitializer)
: Super(ObjectInitializer)
{
}
void UPythonProjectItem::RescanChildren()
{
if (Path.Len() > 0)
{
TArray<UPythonProjectItem*> DeleteChildren;
for (const auto& Child : Children)
{
if (!FPaths::FileExists(Child->Path)) {
DeleteChildren.Add(Child);
}
}
for (const auto& Child : DeleteChildren)
{
Children.Remove(Child);
}
DeleteChildren.Empty();
FDirectoryScanner::AddDirectory(Path, FOnDirectoryScanned::CreateUObject(this, &UPythonProjectItem::HandleDirectoryScanned));
if (FDirectoryScanner::IsScanning()) {
FDirectoryScanner::Tick();
}
}
}
UPythonProjectItem* UPythonProjectItem::GetItemByPath(FString FullPath)
{
for (const auto& Child : Children)
{
if (Child->Type == EPythonProjectItemType::File && Child->Path == FullPath)
{
return Child;
}
}
return NULL;
}
void UPythonProjectItem::HandleDirectoryScanned(const FString& InPathName, EPythonProjectItemType::Type InType)
{
// check for a child that already exists
bool bCreateNew = true;
for (const auto& Child : Children)
{
if (Child->Type == InType && Child->Path == InPathName)
{
bCreateNew = false;
break;
}
}
// create children now & kick off their scan
if (bCreateNew)
{
if (InType == EPythonProjectItemType::File && FPaths::GetExtension(InPathName) != TEXT("py")) {
return;
}
UPythonProjectItem* NewItem = NewObject<UPythonProjectItem>(GetOutermost(), UPythonProjectItem::StaticClass());
NewItem->Type = InType;
NewItem->Path = InPathName;
NewItem->Name = FPaths::GetBaseFilename(InPathName);
if (InType != EPythonProjectItemType::Folder)
{
NewItem->Extension = FPaths::GetExtension(InPathName);
}
Children.Add(NewItem);
Children.Sort(
[](const UPythonProjectItem& ItemA, const UPythonProjectItem& ItemB) -> bool
{
if (ItemA.Type != ItemB.Type)
{
return ItemA.Type < ItemB.Type;
}
return ItemA.Name.Compare(ItemB.Name) < 0;
}
);
if (InType == EPythonProjectItemType::Folder)
{
FDirectoryScanner::AddDirectory(InPathName, FOnDirectoryScanned::CreateUObject(NewItem, &UPythonProjectItem::HandleDirectoryScanned));
}
}
}
void UPythonProjectItem::HandleDirectoryChanged(const TArray<FFileChangeData>& FileChanges)
{
// @TODO: dynamical update directory watchers so we can update the view in real-time
for (const auto& Change : FileChanges)
{
switch (Change.Action)
{
default:
case FFileChangeData::FCA_Unknown:
break;
case FFileChangeData::FCA_Added:
{
}
break;
case FFileChangeData::FCA_Modified:
{
}
break;
case FFileChangeData::FCA_Removed:
{
}
break;
}
}
}