DynamicEditorPage.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. void Cancel();
  38. Size MinimumSize();
  39. string Caption();
  40. }
  41. public class DynamicEditorPages : List<IDynamicEditorPage>
  42. {
  43. public DynamicEditorPages() : base()
  44. {
  45. }
  46. public DynamicEditorPages(IEnumerable<IDynamicEditorPage> pages) : this()
  47. {
  48. foreach (var page in pages)
  49. Add(page);
  50. }
  51. public bool TryGetPage<T>([NotNullWhen(true)] out T? page)
  52. where T : IDynamicEditorPage
  53. {
  54. page = this.OfType<T>().FirstOrDefault();
  55. return page is not null;
  56. }
  57. }