Skip to content

Commit

Permalink
search in dropdowns unlocked
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelbaran authored and Fraser Greenroyd committed Mar 23, 2023
1 parent 32942b7 commit e3e2e86
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
51 changes: 51 additions & 0 deletions BHoM_UI/CallerTemplates/MultiChoiceCaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,20 @@
using System.Windows.Forms;
using BH.oM.Base;
using System.Collections;
using BH.UI.Base.Menus;
using BH.Engine.Base;

namespace BH.UI.Base
{
public abstract class MultiChoiceCaller : Caller
{
/*************************************/
/**** Public Events ****/
/*************************************/

public event EventHandler<int> ValueSelected;


/*************************************/
/**** Properties ****/
/*************************************/
Expand Down Expand Up @@ -84,6 +93,48 @@ public override object Run(List<object> inputs)
public abstract List<string> GetChoiceNames();

/*************************************/

public override void AddToMenu(object menu)
{
base.AddToMenu(menu);

if (SelectedItem != null)
{
if (m_EnumSearchMenu == null)
SetEnumSearchMenu();

m_EnumSearchMenu.FillMenu(menu);
}
}


/*************************************/
/**** Private Methods ****/
/*************************************/

private void SetEnumSearchMenu()
{
List<SearchItem> items = Choices.Zip(GetChoiceNames(), (x, y) => new SearchItem { Item = x, Text = y }).ToList();
ItemSelectorMenu_WinForm enumSearchMenu = new ItemSelectorMenu_WinForm(items, null);
enumSearchMenu.ItemSelected += EnumValueSelected;
m_EnumSearchMenu = enumSearchMenu;
}

/*************************************/

private void EnumValueSelected(object sender, object e)
{
ValueSelected?.Invoke(this, Choices.IndexOf(e));
}


/*************************************/
/**** Private Fields ****/
/*************************************/

private IItemSelectorMenu m_EnumSearchMenu = null;

/*************************************/
}
}

Expand Down
3 changes: 2 additions & 1 deletion BHoM_UI/Menus/ItemSelectorMenu_WinForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public ItemSelectorMenu_WinForm(List<SearchItem> itemList, Tree<object> itemTree

protected override void AddTree(ToolStripDropDown menu, Tree<object> itemTree)
{
AppendMenuTree(itemTree, menu);
if (itemTree != null)
AppendMenuTree(itemTree, menu);
}

/*************************************/
Expand Down

0 comments on commit e3e2e86

Please sign in to comment.