DynamicEditorPage.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Collections.Generic;
  4. using System.Diagnostics.CodeAnalysis;
  5. using System.Linq;
  6. using System.Windows;
  7. using InABox.Core;
  8. namespace InABox.DynamicGrid;
  9. public enum PageType
  10. {
  11. Editor,
  12. Other
  13. }
  14. public interface IDynamicEditorPage
  15. {
  16. DynamicEditorGrid EditorGrid { get; set; }
  17. PageType PageType { get; }
  18. bool Ready { get; set; }
  19. bool ReadOnly { get; set; }
  20. int Order { get; set; }
  21. void Load(object item, Func<Type, CoreTable?>? PageDataHandler);
  22. /// <summary>
  23. /// Called when the "OK" button is clicked on an editor, and before the item is saved.
  24. /// </summary>
  25. /// <param name="item"></param>
  26. void BeforeSave(object item);
  27. /// <summary>
  28. /// Called when the "OK" button is clicked on an editor, and after the item is saved.
  29. /// </summary>
  30. /// <remarks>
  31. /// Generally used to save any child entities that need to be saved, since now the parent has a valid <see cref="Entity.ID"/>.
  32. /// </remarks>
  33. /// <param name="item"></param>
  34. void AfterSave(object item);
  35. event EventHandler OnChanged;
  36. void DoChanged();
  37. Size MinimumSize();
  38. string Caption();
  39. }
  40. public class DynamicEditorPages : List<IDynamicEditorPage>
  41. {
  42. public DynamicEditorPages() : base()
  43. {
  44. }
  45. public DynamicEditorPages(IEnumerable<IDynamicEditorPage> pages) : this()
  46. {
  47. foreach (var page in pages)
  48. Add(page);
  49. }
  50. public bool TryGetPage<T>([NotNullWhen(true)] out T? page)
  51. where T : IDynamicEditorPage
  52. {
  53. page = this.OfType<T>().FirstOrDefault();
  54. return page is not null;
  55. }
  56. }