Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/20tab/master'
Browse files Browse the repository at this point in the history
# Conflicts:
#	Source/UnrealEnginePython/Private/UEPyModule.cpp
#	Source/UnrealEnginePython/Public/UnrealEnginePython.h
#	UnrealEnginePython.uplugin
  • Loading branch information
getnamo committed Nov 3, 2017
2 parents 9f56b61 + 360f2e2 commit 8a8a770
Show file tree
Hide file tree
Showing 137 changed files with 14,185 additions and 1,693 deletions.
2 changes: 2 additions & 0 deletions Source/PythonEditor/Private/PythonEditorStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ void FPythonEditorStyle::Initialize()
StyleSet->Set("PythonEditor.Execute.Small", new IMAGE_BRUSH("UI/Excute_x40", Icon16x16));
StyleSet->Set("PythonEditor.ExecuteInSandbox", new IMAGE_BRUSH("UI/Excute_x40", Icon40x40));
StyleSet->Set("PythonEditor.ExecuteInSandbox.Small", new IMAGE_BRUSH("UI/Excute_x40", Icon16x16));
StyleSet->Set("PythonEditor.PEP8ize", new IMAGE_BRUSH("UI/Excute_x40", Icon40x40));
StyleSet->Set("PythonEditor.PEP8ize.Small", new IMAGE_BRUSH("UI/Excute_x40", Icon16x16));
}

const FSlateFontInfo Consolas10 = TTF_FONT("Font/DroidSansMono", 9);
Expand Down
20 changes: 20 additions & 0 deletions Source/PythonEditor/Private/PythonProjectEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ void FPythonProjectEditor::BindCommands()
FCanExecuteAction::CreateSP(this, &FPythonProjectEditor::CanExecute)
);

ToolkitCommands->MapAction(FPythonProjectEditorCommands::Get().PEP8ize,
FExecuteAction::CreateSP(this, &FPythonProjectEditor::PEP8ize_Internal),
FCanExecuteAction::CreateSP(this, &FPythonProjectEditor::CanExecute)
);

}

void FPythonProjectEditor::CloseFileForEditing(UPythonProjectItem* Item)
Expand Down Expand Up @@ -493,6 +498,11 @@ void FPythonProjectEditor::Execute_Internal()
Execute();
}

void FPythonProjectEditor::PEP8ize_Internal()
{
PEP8ize();
}

void FPythonProjectEditor::ExecuteInSandbox_Internal()
{
Execute();
Expand Down Expand Up @@ -521,6 +531,16 @@ bool FPythonProjectEditor::ExecuteInSandbox()
return true;
}

bool FPythonProjectEditor::PEP8ize()
{
if (DocumentManager.IsValid() && DocumentManager->GetActiveTab().IsValid())
{
TSharedRef<SPythonEditor> PythonEditorRef = StaticCastSharedRef<SPythonEditor>(DocumentManager->GetActiveTab()->GetContent());
PythonEditorRef->PEP8ize();
}

return true;
}

bool FPythonProjectEditor::CanSaveAll() const
{
Expand Down
4 changes: 4 additions & 0 deletions Source/PythonEditor/Private/PythonProjectEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class FPythonProjectEditor : public FWorkflowCentricApplication, public FGCObjec

bool ExecuteInSandbox();

bool PEP8ize();

FString GetSafeName(bool IsDirectory);

private:
Expand All @@ -82,6 +84,8 @@ class FPythonProjectEditor : public FWorkflowCentricApplication, public FGCObjec

void ExecuteInSandbox_Internal();

void PEP8ize_Internal();

bool CanNew() const;

bool CanSave() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ void FPythonProjectEditorCommands::RegisterCommands()
UI_COMMAND(SaveAll, "Save All", "Save all open documents.", EUserInterfaceActionType::Button, FInputGesture(EModifierKey::Control | EModifierKey::Shift, EKeys::S));
UI_COMMAND(Execute, "Execute", "Execute Current Python File.", EUserInterfaceActionType::Button, FInputGesture(EModifierKey::Control, EKeys::Enter));
UI_COMMAND(ExecuteInSandbox, "Execute In Sandbox", "Execute Current Python File in a Sandbox.", EUserInterfaceActionType::Button, FInputGesture(EModifierKey::Control | EModifierKey::Shift, EKeys::Enter));
UI_COMMAND(PEP8ize, "PEP8-ize", "Enforce PEP8 to the current code.", EUserInterfaceActionType::Button, FInputGesture(EModifierKey::Control | EModifierKey::Shift, EKeys::P));

}

Expand Down
1 change: 1 addition & 0 deletions Source/PythonEditor/Private/PythonProjectEditorCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FPythonProjectEditorCommands : public TCommands<FPythonProjectEditorComman
TSharedPtr<FUICommandInfo> SaveAll;
TSharedPtr<FUICommandInfo> Execute;
TSharedPtr<FUICommandInfo> ExecuteInSandbox;
TSharedPtr<FUICommandInfo> PEP8ize;
/** Initialize commands */
virtual void RegisterCommands() override;
};
1 change: 1 addition & 0 deletions Source/PythonEditor/Private/PythonProjectEditorToolbar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void FPythonProjectEditorToolbar::FillEditorToolbar(FToolBarBuilder& ToolbarBuil
{
ToolbarBuilder.AddToolBarButton(FPythonProjectEditorCommands::Get().Execute);
ToolbarBuilder.AddToolBarButton(FPythonProjectEditorCommands::Get().ExecuteInSandbox);
ToolbarBuilder.AddToolBarButton(FPythonProjectEditorCommands::Get().PEP8ize);
}
ToolbarBuilder.EndSection();

Expand Down
10 changes: 8 additions & 2 deletions Source/PythonEditor/Private/SPythonEditableText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

void SPythonEditableText::Construct(const FArguments& InArgs)
{

SMultiLineEditableText::Construct(
SMultiLineEditableText::FArguments()
.Font(FPythonEditorStyle::Get().GetWidgetStyle<FTextBlockStyle>("TextEditor.NormalText").Font)
Expand All @@ -18,7 +17,8 @@ void SPythonEditableText::Construct(const FArguments& InArgs)
.HScrollBar(InArgs._HScrollBar)
.VScrollBar(InArgs._VScrollBar)
.OnTextChanged(InArgs._OnTextChanged)
);
.OnCursorMoved(this, &SPythonEditableText::OnCursorMoved)
);
OnExecuted = InArgs._OnExecuted;
}

Expand Down Expand Up @@ -92,3 +92,9 @@ FReply SPythonEditableText::OnKeyDown(const FGeometry& MyGeometry, const FKeyEve
return Reply;
}

void SPythonEditableText::GetLineAndColumn(int32 & Line, int32 & Column)
{
Line = CurrentLine;
Column = CurrentColumn;
}

10 changes: 10 additions & 0 deletions Source/PythonEditor/Private/SPythonEditableText.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,19 @@ class SPythonEditableText : public SMultiLineEditableText

void Construct( const FArguments& InArgs );

void GetLineAndColumn(int32 & Line, int32 & Column);

void OnCursorMoved(const FTextLocation & Location) {
CurrentLine = Location.GetLineIndex();
CurrentColumn = Location.GetOffset();
}

private:
virtual FReply OnKeyChar(const FGeometry& MyGeometry,const FCharacterEvent& InCharacterEvent) override;
virtual FReply OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& InKeyEvent) override;

FOnExecuted OnExecuted;

int32 CurrentLine;
int32 CurrentColumn;
};
32 changes: 31 additions & 1 deletion Source/PythonEditor/Private/SPythonEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void SPythonEditor::Construct(const FArguments& InArgs, UPythonProjectItem* InPy
[
SNew(SGridPanel)
.FillColumn(0, 1.0f)
.FillRow(0, 1.0f)
.FillRow(0, 2.0f)
+SGridPanel::Slot(0, 0)
[
SAssignNew(PythonEditableText, SPythonEditableText)
Expand All @@ -59,7 +59,16 @@ void SPythonEditor::Construct(const FArguments& InArgs, UPythonProjectItem* InPy
[
HorizontalScrollbar.ToSharedRef()
]
+ SGridPanel::Slot(0, 2)
[
SNew(SBorder).HAlign(EHorizontalAlignment::HAlign_Right)
[
SNew(STextBlock)
.Text(this, &SPythonEditor::GetLineAndColumn)
]
]
]

];
}

Expand Down Expand Up @@ -111,6 +120,16 @@ void SPythonEditor::ExecuteInSandbox() const
PythonModule.RunStringSandboxed(TCHAR_TO_UTF8(*SelectionString));
}

void SPythonEditor::PEP8ize() const
{
Save();
FUnrealEnginePythonModule &PythonModule = FModuleManager::GetModuleChecked<FUnrealEnginePythonModule>("UnrealEnginePython");

FString CleanedCode = PythonModule.Pep8ize(PythonEditableText->GetText().ToString());

PythonEditableText->SetText(FText::FromString(CleanedCode));
}


void SPythonEditor::GotoLineAndColumn(int32 LineNumber, int32 ColumnNumber)
{
Expand All @@ -119,4 +138,15 @@ void SPythonEditor::GotoLineAndColumn(int32 LineNumber, int32 ColumnNumber)
PythonEditableText->ScrollTo(Location);
}

FText SPythonEditor::GetLineAndColumn() const
{
int32 Line;
int32 Column;
PythonEditableText->GetLineAndColumn(Line, Column);

FString LineAndColumn = FString::Printf(TEXT("Line: %d Column: %d"), Line, Column);

return FText::FromString(LineAndColumn);
}

#undef LOCTEXT_NAMESPACE
3 changes: 3 additions & 0 deletions Source/PythonEditor/Private/SPythonEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@ class SPythonEditor : public SCompoundWidget

void GotoLineAndColumn(int32 LineNumber, int32 ColumnNumber);

void PEP8ize() const;

private:
void OnTextChanged(const FText& NewText);
FText GetLineAndColumn() const;

protected:
class UPythonProjectItem* PythonProjectItem;
Expand Down

0 comments on commit 8a8a770

Please sign in to comment.