Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,39 @@ public TypeMenu (IEnumerable<Type> types)

}

private sealed class SelectionSession : AdvancedDropdown
{
private readonly AdvancedTypePopup owner;
private Action<AdvancedTypePopupItem> callback;

internal SelectionSession (AdvancedTypePopup owner, AdvancedDropdownState state, Action<AdvancedTypePopupItem> callback) : base(state)
{
this.owner = owner;
this.callback = callback;
minimumSize = owner.minimumSize;
}

protected override AdvancedDropdownItem BuildRoot ()
{
return owner.BuildRoot();
}

protected override void ItemSelected (AdvancedDropdownItem item)
{
try
{
if (item is AdvancedTypePopupItem typeItem)
{
callback?.Invoke(typeItem);
}
}
finally
{
callback = null;
}
}
}

private static bool HasSingleNamespace (TypeMenuItem[] items)
{
// Flatten an unbranched namespace unless an explicit menu requests a category.
Expand Down Expand Up @@ -171,11 +204,13 @@ private static AdvancedDropdownItem GetItem (AdvancedDropdownItem parent, string

private Type[] types;
private TypeMenu menu;
private readonly AdvancedDropdownState state;

public event Action<AdvancedTypePopupItem> OnItemSelected;

public AdvancedTypePopup (IEnumerable<Type> types, int maxLineCount, AdvancedDropdownState state) : base(state)
{
this.state = state;
SetTypes(types);
minimumSize = new Vector2(minimumSize.x, EditorGUIUtility.singleLineHeight * maxLineCount + HeaderHeight);
}
Expand All @@ -186,6 +221,12 @@ public void SetTypes (IEnumerable<Type> types)
menu = null;
}

internal void ShowForSelection (Rect position, Action<AdvancedTypePopupItem> callback)
{
// Only the native window owns this session. The cached metadata owner retains no target callback.
new SelectionSession(this, state, callback).Show(position);
}

protected override AdvancedDropdownItem BuildRoot ()
{
var root = new AdvancedDropdownItem("Select Type");
Expand Down
Loading
Loading