IModalRunnable.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. namespace Terminal.Gui.App;
  2. /// <summary>
  3. /// Defines a runnable view that captures exclusive input (modal behavior) and returns a result.
  4. /// </summary>
  5. /// <typeparam name="TResult">
  6. /// The type of result data returned when the modal is accepted.
  7. /// Common types: <see cref="int"/> for button indices, <see cref="string"/> for file paths,
  8. /// custom types for complex form data.
  9. /// </typeparam>
  10. /// <remarks>
  11. /// <para>
  12. /// Modal runnables block execution of <see cref="IApplication.Run"/> until stopped,
  13. /// capture all keyboard and mouse input exclusively, and typically have elevated Z-order.
  14. /// </para>
  15. /// <para>
  16. /// When <see cref="Result"/> is <c>null</c>, the modal was stopped without being accepted
  17. /// (e.g., ESC key pressed, window closed). When non-<c>null</c>, it contains the result data
  18. /// that was extracted from the Accept command before the modal's subviews were disposed.
  19. /// </para>
  20. /// <para>
  21. /// Common implementations include <see cref="Dialog"/>, <see cref="MessageBox"/>, and <see cref="Wizard"/>.
  22. /// </para>
  23. /// <para>
  24. /// For modals that need to provide additional context or data upon completion, populate the result
  25. /// before setting it. By default (except for <see cref="Button"/>s with <see cref="Button.IsDefault"/> set),
  26. /// if a modal does not handle the Accept command, <see cref="Result"/> will be null (canceled).
  27. /// </para>
  28. /// </remarks>
  29. public interface IModalRunnable<TResult> : IRunnable
  30. {
  31. /// <summary>
  32. /// Gets or sets the result data from the modal operation.
  33. /// </summary>
  34. /// <remarks>
  35. /// <para>
  36. /// Implementations should set this property when the modal is accepted (e.g., OK button clicked,
  37. /// file selected). The result should be extracted from the modal's state before views are disposed.
  38. /// </para>
  39. /// <para>
  40. /// For value types (like <see cref="int"/>), implementations should use a nullable type (e.g., <c>int?</c>)
  41. /// where <c>null</c> indicates the modal was stopped without accepting.
  42. /// For reference types, <c>null</c> similarly indicates cancellation.
  43. /// </para>
  44. /// <para>
  45. /// Examples:
  46. /// - <see cref="Dialog"/>: Implement with <c>IModalRunnable&lt;int?&gt;</c>, returns button index or null
  47. /// - <see cref="MessageBox"/>: Implement with <c>IModalRunnable&lt;int?&gt;</c>, returns button index or null
  48. /// - <see cref="FileDialog"/>: Implement with <c>IModalRunnable&lt;string?&gt;</c>, returns file path or null
  49. /// </para>
  50. /// </remarks>
  51. TResult Result { get; set; }
  52. }