-
Notifications
You must be signed in to change notification settings - Fork 765
Expand file tree
/
Copy pathSProjectViewItem.cpp
More file actions
62 lines (53 loc) · 1.66 KB
/
SProjectViewItem.cpp
File metadata and controls
62 lines (53 loc) · 1.66 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
// Copyright 1998-2016 Epic Games, Inc. All Rights Reserved.
#include "SProjectViewItem.h"
#include "Runtime/Slate/Public/Widgets/Text/SInlineEditableTextBlock.h"
#include "Runtime/Core/Public/Internationalization/BreakIterator.h"
#include "PythonEditorStyle.h"
#define LOCTEXT_NAMESPACE "ProjectViewItem"
void SProjectViewItem::Construct(const FArguments& InArgs)
{
TreeItem = InArgs._TreeItem;
OnNameChanged = InArgs._OnNameChanged;
ChildSlot
[
SNew(SHorizontalBox)
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Center)
.Padding(1.0f)
.AutoWidth()
[
SNew(SImage)
.Image(FPythonEditorStyle::Get().GetBrush(InArgs._IconName))
]
+ SHorizontalBox::Slot()
.HAlign(HAlign_Left)
.VAlign(VAlign_Center)
.Padding(1.0f)
.FillWidth(1.0f)
[
SAssignNew(InlineRenameWidget, SInlineEditableTextBlock)
.Text(InArgs._Text)
.OnTextCommitted(this, &SProjectViewItem::HandleNameCommitted)
.IsSelected(InArgs._IsSelected)
]
];
}
void SProjectViewItem::HandleNameCommitted(const FText& NewText, ETextCommit::Type)
{
IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
const FString OldPath = TreeItem->Path;
FString Path;
TreeItem->Path.Split(TEXT("/"), &Path, NULL, ESearchCase::CaseSensitive, ESearchDir::FromEnd);
FString NewPath = Path + TEXT("/") + NewText.ToString() + TEXT(".py");
if (!FPaths::FileExists(NewPath)) {
int Result = rename(TCHAR_TO_ANSI(*OldPath), TCHAR_TO_ANSI(*NewPath));
if (Result == 0) {
TreeItem->Name = NewText.ToString();
TreeItem->Path = NewPath;
InlineRenameWidget->SetText(TreeItem->Name);
OnNameChanged.ExecuteIfBound(TreeItem);
}
}
}
#undef LOCTEXT_NAMESPACE