-
Notifications
You must be signed in to change notification settings - Fork 765
Expand file tree
/
Copy pathSPythonProjectEditor.cpp
More file actions
138 lines (123 loc) · 3.79 KB
/
SPythonProjectEditor.cpp
File metadata and controls
138 lines (123 loc) · 3.79 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "SPythonProjectEditor.h"
#include "PythonEditorPrivatePCH.h"
#include "SProjectViewItem.h"
#include "DirectoryScanner.h"
#include "SThrobber.h"
#define LOCTEXT_NAMESPACE "PythonProjectEditor"
void SPythonProjectEditor::Construct(const FArguments& InArgs, UPythonProject* InPythonProject)
{
check(InPythonProject);
PythonProject = InPythonProject;
ChildSlot
[
SNew(SBorder)
.BorderImage(FPythonEditorStyle::Get().GetBrush("ProjectEditor.Border"))
[
SNew(SOverlay)
+ SOverlay::Slot()
[
SAssignNew(ProjectTree, STreeView<UPythonProjectItem*>)
.TreeItemsSource(&PythonProject->Children)
.OnGenerateRow(this, &SPythonProjectEditor::OnGenerateRow)
.OnGetChildren(this, &SPythonProjectEditor::OnGetChildren)
.OnMouseButtonDoubleClick(this, &SPythonProjectEditor::HandleMouseButtonDoubleClick)
.ClearSelectionOnClick(false)
]
+ SOverlay::Slot()
.VAlign(VAlign_Bottom)
.Padding(10.0f)
[
SNew(SThrobber)
.Visibility(this, &SPythonProjectEditor::GetThrobberVisibility)
]
]
];
InPythonProject->RescanChildren();
}
void SPythonProjectEditor::Tick(const FGeometry& AllottedGeometry, const double InCurrentTime, const float InDeltaTime)
{
if (FDirectoryScanner::Tick())
{
ProjectTree->SetTreeItemsSource(&PythonProject->Children);
}
SCompoundWidget::Tick(AllottedGeometry, InCurrentTime, InDeltaTime);
}
FName SPythonProjectEditor::GetIconForItem(UPythonProjectItem* Item) const
{
switch (Item->Type)
{
case EPythonProjectItemType::Project:
return "ProjectEditor.Icon.Project";
case EPythonProjectItemType::Folder:
return "ProjectEditor.Icon.Folder";
case EPythonProjectItemType::File:
return "ProjectEditor.Icon.File";
default:
return "ProjectEditor.Icon.GenericFile";
}
}
TSharedRef<class ITableRow> SPythonProjectEditor::OnGenerateRow(UPythonProjectItem* Item, const TSharedRef<STableViewBase >& OwnerTable)
{
return
SNew(STableRow<UPythonProjectItem*>, OwnerTable)
[
SNew(SProjectViewItem)
.TreeItem(Item)
.Text(FText::FromString(Item->Name))
.IconName(GetIconForItem(Item))
.IsSelected(this, &SPythonProjectEditor::IsTreeItemSelected, Item)
.OnNameChanged(this, &SPythonProjectEditor::FolderNameChanged)
];
}
UPythonProjectItem* SPythonProjectEditor::SelectByPath(FString path)
{
ProjectTree->SetTreeItemsSource(&PythonProject->Children);
UPythonProjectItem* Item = PythonProject->GetItemByPath(path);
if (Item != NULL) {
ProjectTree->ClearSelection();
ProjectTree->SetItemSelection(Item, true);
}
return Item;
}
void SPythonProjectEditor::RequestTreeRefresh()
{
ProjectTree->RequestTreeRefresh();
}
bool SPythonProjectEditor::HasSelectionItem()
{
int32 selNum = ProjectTree->GetNumItemsSelected();
return selNum > 0;
}
TArray<UPythonProjectItem*> SPythonProjectEditor::GetSelectedItems()
{
TArray<UPythonProjectItem*> selItemList = ProjectTree->GetSelectedItems();
return selItemList;
}
void SPythonProjectEditor::FolderNameChanged(UPythonProjectItem* Item)
{
if (Item->Type == EPythonProjectItemType::File) {
FPythonProjectEditor::Get()->CloseFileForEditing(Item);
FPythonProjectEditor::Get()->OpenFileForEditing(Item);
}
}
bool SPythonProjectEditor::IsTreeItemSelected(UPythonProjectItem* Item) const
{
return ProjectTree->IsItemSelected(Item);
}
void SPythonProjectEditor::OnGetChildren(UPythonProjectItem* Item, TArray<UPythonProjectItem*>& OutChildItems)
{
OutChildItems = Item->Children;
}
EVisibility SPythonProjectEditor::GetThrobberVisibility() const
{
return FDirectoryScanner::IsScanning() ? EVisibility::Visible : EVisibility::Hidden;
}
void SPythonProjectEditor::HandleMouseButtonDoubleClick(UPythonProjectItem* Item) const
{
if (Item->Type == EPythonProjectItemType::File)
{
FPythonProjectEditor::Get()->OpenFileForEditing(Item);
}
}
#undef LOCTEXT_NAMESPACE