Skip to content

Commit 3aca204

Browse files
committed
Fix rcol group pasting
1 parent 59c3642 commit 3aca204

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

ContentEditor.App/AppImguiHelpers.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,26 +201,35 @@ public static bool JsonCopyableTreeNode<T>(UIContext context, JsonSerializerOpti
201201
}
202202

203203
public static bool CopyableTreeNode<T>(UIContext context) where T : class
204+
{
205+
return CopyableTreeNode<T>(context, out _);
206+
}
207+
208+
public static bool CopyableTreeNode<T>(UIContext context, out bool didPaste) where T : class
204209
{
205210
var instance = context.Get<T>()!;
206211
var show = ImguiHelpers.TreeNodeSuffix(context.label, instance.ToString() ?? "NULL");
207212
if (ImGui.BeginPopupContextItem(context.label)) {
208-
ShowVirtualCopyPopupButtons<T>(instance, context);
213+
didPaste = ShowVirtualCopyPopupButtons<T>(instance, context);
209214
ImGui.EndPopup();
215+
} else {
216+
didPaste = false;
210217
}
211218
return show;
212219
}
213220

214-
public static void ShowVirtualCopyPopupButtons<T>(UIContext context) where T : class => ShowVirtualCopyPopupButtons<T>(context.Get<T>(), context);
215-
public static void ShowVirtualCopyPopupButtons<T>(T target, UIContext context) where T : class
221+
public static bool ShowVirtualCopyPopupButtons<T>(UIContext context) where T : class => ShowVirtualCopyPopupButtons<T>(context.Get<T>(), context);
222+
public static bool ShowVirtualCopyPopupButtons<T>(T target, UIContext context) where T : class
216223
{
217224
if (ImGui.Selectable("Copy")) {
218225
VirtualClipboard.CopyToClipboard(target.DeepCloneGeneric<T>());
219226
}
220227
if (VirtualClipboard.TryGetFromClipboard<T>(out var newClip) && ImGui.Selectable("Paste (replace)")) {
221228
UndoRedo.RecordSet(context, newClip.DeepCloneGeneric<T>());
222229
context.ClearChildren();
230+
return true;
223231
}
232+
return false;
224233
}
225234

226235
private static IList? _dragDropSourceList;

ContentEditor.App/Imgui/Editors/RcolEditor.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,10 +303,18 @@ public void OnIMGUI(UIContext context)
303303
context.AddChild<RcolGroup, List<RcolShape>>("ExtraShapes", group, new ListHandler(typeof(RcolShape)) { CanCreateRemoveElements = true }, getter: (i) => i!.ExtraShapes);
304304
}
305305

306-
if (AppImguiHelpers.CopyableTreeNode<RcolGroup>(context)) {
306+
if (AppImguiHelpers.CopyableTreeNode<RcolGroup>(context, out var pasted)) {
307307
context.ShowChildrenUI();
308308
ImGui.TreePop();
309309
}
310+
311+
if (pasted) {
312+
var group = context.Get<RcolGroup>();
313+
var rcol = context.FindHandlerInParents<RcolEditor>();
314+
if (rcol != null && !rcol.File.Groups.Contains(group)) {
315+
rcol.File.Groups.Add(group);
316+
}
317+
}
310318
}
311319
}
312320

RE-Engine-Lib

0 commit comments

Comments
 (0)