DynamicEditorPage.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. /// <summary>
  20. /// Is this page visible?
  21. /// </summary>
  22. /// <remarks>
  23. /// Based on security tokens and the likes.
  24. /// </remarks>
  25. bool Visible { get; }
  26. bool ReadOnly { get; set; }
  27. int Order { get; set; }
  28. void Load(object item, Func<Type, CoreTable?>? PageDataHandler);
  29. /// <summary>
  30. /// Called when the "OK" button is clicked on an editor, and before the item is saved.
  31. /// </summary>
  32. /// <param name="item"></param>
  33. void BeforeSave(object item);
  34. /// <summary>
  35. /// Called when the "OK" button is clicked on an editor, and after the item is saved.
  36. /// </summary>
  37. /// <remarks>
  38. /// Generally used to save any child entities that need to be saved, since now the parent has a valid <see cref="Entity.ID"/>.
  39. /// </remarks>
  40. /// <param name="item"></param>
  41. void AfterSave(object item);
  42. event EventHandler OnChanged;
  43. void DoChanged();
  44. void Cancel();
  45. Size MinimumSize();
  46. string Caption();
  47. }
  48. public class DynamicEditorPages : List<IDynamicEditorPage>
  49. {
  50. public DynamicEditorPages() : base()
  51. {
  52. }
  53. public DynamicEditorPages(IEnumerable<IDynamicEditorPage> pages) : this()
  54. {
  55. foreach (var page in pages)
  56. Add(page);
  57. }
  58. public bool TryGetPage<T>([NotNullWhen(true)] out T? page)
  59. where T : IDynamicEditorPage
  60. {
  61. page = this.OfType<T>().FirstOrDefault();
  62. return page is not null;
  63. }
  64. }