Application.Run.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. using System.Diagnostics.CodeAnalysis;
  2. namespace Terminal.Gui.App;
  3. public static partial class Application // Run (Begin -> Run -> Layout/Draw -> End -> Stop)
  4. {
  5. private static Key _quitKey = Key.Esc; // Resources/config.json overrides
  6. /// <summary>Gets or sets the key to quit the application.</summary>
  7. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  8. public static Key QuitKey
  9. {
  10. get => _quitKey;
  11. set
  12. {
  13. Key oldValue = _quitKey;
  14. _quitKey = value;
  15. QuitKeyChanged?.Invoke (null, new ValueChangedEventArgs<Key> (oldValue, _quitKey));
  16. }
  17. }
  18. /// <summary>Raised when <see cref="QuitKey"/> changes.</summary>
  19. public static event EventHandler<ValueChangedEventArgs<Key>>? QuitKeyChanged;
  20. private static Key _arrangeKey = Key.F5.WithCtrl; // Resources/config.json overrides
  21. /// <summary>Gets or sets the key to activate arranging views using the keyboard.</summary>
  22. [ConfigurationProperty (Scope = typeof (SettingsScope))]
  23. public static Key ArrangeKey
  24. {
  25. get => _arrangeKey;
  26. set
  27. {
  28. Key oldValue = _arrangeKey;
  29. _arrangeKey = value;
  30. ArrangeKeyChanged?.Invoke (null, new ValueChangedEventArgs<Key> (oldValue, _arrangeKey));
  31. }
  32. }
  33. /// <summary>Raised when <see cref="ArrangeKey"/> changes.</summary>
  34. public static event EventHandler<ValueChangedEventArgs<Key>>? ArrangeKeyChanged;
  35. /// <inheritdoc cref="IApplication.Begin(IRunnable)"/>
  36. [Obsolete ("The legacy static Application object is going away.")]
  37. public static SessionToken Begin (Toplevel toplevel) => ApplicationImpl.Instance.Begin (toplevel);
  38. /// <inheritdoc cref="IApplication.PositionCursor"/>
  39. [Obsolete ("The legacy static Application object is going away.")]
  40. public static bool PositionCursor () => ApplicationImpl.Instance.PositionCursor ();
  41. /// <inheritdoc cref="IApplication.Run(Func{Exception, bool}, string)"/>
  42. [RequiresUnreferencedCode ("AOT")]
  43. [RequiresDynamicCode ("AOT")]
  44. [Obsolete ("The legacy static Application object is going away.")]
  45. public static Toplevel Run (Func<Exception, bool>? errorHandler = null, string? driverName = null) => ApplicationImpl.Instance.Run (errorHandler, driverName);
  46. /// <inheritdoc cref="IApplication.Run{TView}(Func{Exception, bool}, string)"/>
  47. [RequiresUnreferencedCode ("AOT")]
  48. [RequiresDynamicCode ("AOT")]
  49. [Obsolete ("The legacy static Application object is going away.")]
  50. public static TView Run<TView> (Func<Exception, bool>? errorHandler = null, string? driverName = null)
  51. where TView : Toplevel, new() => ApplicationImpl.Instance.Run<TView> (errorHandler, driverName);
  52. /// <inheritdoc cref="IApplication.Run(Toplevel, Func{Exception, bool})"/>
  53. [Obsolete ("The legacy static Application object is going away.")]
  54. public static void Run (Toplevel view, Func<Exception, bool>? errorHandler = null) => ApplicationImpl.Instance.Run (view, errorHandler);
  55. /// <inheritdoc cref="IApplication.AddTimeout"/>
  56. [Obsolete ("The legacy static Application object is going away.")]
  57. public static object? AddTimeout (TimeSpan time, Func<bool> callback) => ApplicationImpl.Instance.AddTimeout (time, callback);
  58. /// <inheritdoc cref="IApplication.RemoveTimeout"/>
  59. [Obsolete ("The legacy static Application object is going away.")]
  60. public static bool RemoveTimeout (object token) => ApplicationImpl.Instance.RemoveTimeout (token);
  61. /// <inheritdoc cref="IApplication.TimedEvents"/>
  62. ///
  63. [Obsolete ("The legacy static Application object is going away.")]
  64. public static ITimedEvents? TimedEvents => ApplicationImpl.Instance?.TimedEvents;
  65. /// <inheritdoc cref="IApplication.Invoke(Action{IApplication})"/>
  66. [Obsolete ("The legacy static Application object is going away.")]
  67. public static void Invoke (Action<IApplication> action) => ApplicationImpl.Instance.Invoke (action);
  68. /// <inheritdoc cref="IApplication.Invoke(Action)"/>
  69. [Obsolete ("The legacy static Application object is going away.")]
  70. public static void Invoke (Action action) => ApplicationImpl.Instance.Invoke (action);
  71. /// <inheritdoc cref="IApplication.LayoutAndDraw"/>
  72. [Obsolete ("The legacy static Application object is going away.")]
  73. public static void LayoutAndDraw (bool forceRedraw = false) => ApplicationImpl.Instance.LayoutAndDraw (forceRedraw);
  74. /// <inheritdoc cref="IApplication.StopAfterFirstIteration"/>
  75. [Obsolete ("The legacy static Application object is going away.")]
  76. public static bool StopAfterFirstIteration
  77. {
  78. get => ApplicationImpl.Instance.StopAfterFirstIteration;
  79. set => ApplicationImpl.Instance.StopAfterFirstIteration = value;
  80. }
  81. /// <inheritdoc cref="IApplication.RequestStop(Toplevel)"/>
  82. [Obsolete ("The legacy static Application object is going away.")]
  83. public static void RequestStop (Toplevel? top = null) => ApplicationImpl.Instance.RequestStop (top);
  84. /// <inheritdoc cref="IApplication.End(RunnableSessionToken)"/>
  85. [Obsolete ("The legacy static Application object is going away.")]
  86. public static void End (SessionToken sessionToken) => ApplicationImpl.Instance.End (sessionToken);
  87. /// <inheritdoc cref="IApplication.Iteration"/>
  88. [Obsolete ("The legacy static Application object is going away.")]
  89. public static event EventHandler<EventArgs<IApplication?>>? Iteration
  90. {
  91. add => ApplicationImpl.Instance.Iteration += value;
  92. remove => ApplicationImpl.Instance.Iteration -= value;
  93. }
  94. /// <inheritdoc cref="IApplication.SessionBegun"/>
  95. [Obsolete ("The legacy static Application object is going away.")]
  96. public static event EventHandler<SessionTokenEventArgs>? SessionBegun
  97. {
  98. add => ApplicationImpl.Instance.SessionBegun += value;
  99. remove => ApplicationImpl.Instance.SessionBegun -= value;
  100. }
  101. /// <inheritdoc cref="IApplication.SessionEnded"/>
  102. [Obsolete ("The legacy static Application object is going away.")]
  103. public static event EventHandler<ToplevelEventArgs>? SessionEnded
  104. {
  105. add => ApplicationImpl.Instance.SessionEnded += value;
  106. remove => ApplicationImpl.Instance.SessionEnded -= value;
  107. }
  108. }