Skip to content

Commit e71d405

Browse files
author
Roberto De Ioris
committed
refactored slate delegates [2]
1 parent 14c1c13 commit e71d405

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

Source/UnrealEnginePython/Private/Slate/UEPyFMenuBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static PyObject *py_ue_fmenu_builder_add_menu_entry(ue_PyFMenuBuilder *self, PyO
5353

5454

5555
FExecuteAction handler;
56-
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, py_callable);
56+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewStaticSlateDelegate(py_callable);
5757

5858
if (py_obj)
5959
{

Source/UnrealEnginePython/Private/Slate/UEPyFToolBarBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static PyObject *py_ue_ftool_bar_builder_add_tool_bar_button(ue_PyFToolBarBuilde
4747
}
4848

4949
FExecuteAction handler;
50-
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, py_callable);
50+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewStaticSlateDelegate(py_callable);
5151

5252
if (py_obj)
5353
{

Source/UnrealEnginePython/Private/Slate/UEPySPythonShelf.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ static int ue_py_spython_shelf_init(ue_PySPythonShelf *self, PyObject *args, PyO
146146
if (py_callable_double_clicked)
147147
{
148148
FOnAssetDoubleClicked handler;
149-
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, py_callable_double_clicked);
149+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewStaticSlateDelegate(py_callable_double_clicked);
150150
handler.BindSP(py_delegate, &FPythonSlateDelegate::OnAssetDoubleClicked);
151151

152152

@@ -156,7 +156,7 @@ static int ue_py_spython_shelf_init(ue_PySPythonShelf *self, PyObject *args, PyO
156156
if (py_callable_get_context_menu)
157157
{
158158
FOnGetAssetContextMenu handler;
159-
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, py_callable_get_context_menu);
159+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewStaticSlateDelegate(py_callable_get_context_menu);
160160

161161
handler.BindSP(py_delegate, &FPythonSlateDelegate::OnGetAssetContextMenu);
162162

@@ -166,7 +166,7 @@ static int ue_py_spython_shelf_init(ue_PySPythonShelf *self, PyObject *args, PyO
166166
if (py_callable_asset_selected)
167167
{
168168
FOnAssetSelected handler;
169-
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, py_callable_asset_selected);
169+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewStaticSlateDelegate(py_callable_asset_selected);
170170

171171
handler.BindSP(py_delegate, &FPythonSlateDelegate::OnAssetSelected);
172172

Source/UnrealEnginePython/Private/Slate/UEPySWindow.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static int ue_py_swindow_init(ue_PySWindow *self, PyObject *args, PyObject *kwar
243243
if (on_closed && PyCalllable_Check_Extended(on_closed))
244244
{
245245
FOnWindowClosed handler;
246-
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, on_closed);
246+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_compound_widget.s_widget.s_widget, on_closed);
247247
handler.BindSP(py_delegate, &FPythonSlateDelegate::OnWindowClosed);
248248

249249
sw_window->SetOnWindowClosed(handler);

Source/UnrealEnginePython/Private/Slate/UEPySlate.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ PyObject *py_unreal_engine_add_asset_view_context_menu_extension(PyObject * self
13261326
TArray<FContentBrowserMenuExtender_SelectedAssets> &Extenders = ContentBrowser.GetAllAssetViewContextMenuExtenders();
13271327

13281328
FContentBrowserMenuExtender_SelectedAssets handler;
1329-
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, py_callable);
1329+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewStaticSlateDelegate(py_callable);
13301330
handler.BindSP(py_delegate, &FPythonSlateDelegate::OnExtendContentBrowserMenu);
13311331

13321332
Extenders.Add(handler);
@@ -1349,7 +1349,7 @@ PyObject *py_unreal_engine_register_nomad_tab_spawner(PyObject * self, PyObject
13491349
return PyErr_Format(PyExc_Exception, "argument is not callable");
13501350

13511351
FOnSpawnTab spawn_tab;
1352-
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, py_callable);
1352+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewStaticSlateDelegate(py_callable);
13531353
spawn_tab.BindSP(py_delegate, &FPythonSlateDelegate::SpawnPythonTab);
13541354

13551355
FTabSpawnerEntry *spawner_entry = &FGlobalTabmanager::Get()->RegisterNomadTabSpawner(UTF8_TO_TCHAR(name), spawn_tab)
@@ -1454,7 +1454,7 @@ PyObject *py_unreal_engine_open_color_picker(PyObject *self, PyObject *args, PyO
14541454
return PyErr_Format(PyExc_Exception, "on_color_committed must be a callable");
14551455
}
14561456

1457-
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewSlateDelegate(self->s_widget, py_callable);
1457+
TSharedRef<FPythonSlateDelegate> py_delegate = FUnrealEnginePythonHouseKeeper::Get()->NewStaticSlateDelegate(py_callable);
14581458
FColorPickerArgs color_args;
14591459
color_args.OnColorCommitted.BindSP(py_delegate, &FPythonSlateDelegate::OnLinearColorChanged);
14601460

Source/UnrealEnginePython/Public/PythonHouseKeeper.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,11 +218,22 @@ class FUnrealEnginePythonHouseKeeper
218218
return Delegate;
219219
}
220220

221+
TSharedRef<FPythonSlateDelegate> NewStaticSlateDelegate(PyObject *PyCallable)
222+
{
223+
TSharedRef<FPythonSlateDelegate> Delegate = MakeShareable(new FPythonSlateDelegate());
224+
Delegate->SetPyCallable(PyCallable);
225+
226+
PyStaticSlateDelegatesTracker.Add(Delegate);
227+
228+
return Delegate;
229+
}
230+
221231
private:
222232
TMap<UObject *, FPythonUOjectTracker> UObjectPyMapping;
223233
TArray<FPythonDelegateTracker> PyDelegatesTracker;
224234

225235

226236
TArray<FPythonSWidgetTracker> PySlateTracker;
227237
TArray<FPythonSWidgetDelegateTracker> PySlateDelegatesTracker;
238+
TArray<TSharedRef<FPythonSlateDelegate>> PyStaticSlateDelegatesTracker;
228239
};

0 commit comments

Comments
 (0)