Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search in dropdowns unlocked #450

Merged
merged 1 commit into from
Feb 16, 2023
Merged
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
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