CoreMenu.cs 971 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading.Tasks;
  4. namespace InABox.Core
  5. {
  6. public class CoreMenu<T> where T : class
  7. {
  8. public List<ICoreMenuItem> Items { get; } = new List<ICoreMenuItem>();
  9. public CoreMenu<T> AddItem(string header, T? image, Func<Task<bool>> action)
  10. {
  11. var result = new CoreMenuItem<T>(header, image, action);
  12. Items.Add(result);
  13. return this;
  14. }
  15. public CoreMenu<T> AddItem(string header, Func<Task<bool>> action)
  16. {
  17. var result = new CoreMenuItem<T>(header, null, action);
  18. Items.Add(result);
  19. return this;
  20. }
  21. public CoreMenu<T> AddSeparator()
  22. {
  23. Items.Add(new CoreMenuSeparator());
  24. return this;
  25. }
  26. public CoreMenu<T> AddHeader(CoreMenuHeader<T> header)
  27. {
  28. Items.Add(header);
  29. return this;
  30. }
  31. }
  32. }