Application.Run.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 (IRunnable runnable) => ApplicationImpl.Instance.Begin (runnable)!;
  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{TRunnable}(Func{Exception, bool}, string)"/>
  42. [RequiresUnreferencedCode ("AOT")]
  43. [RequiresDynamicCode ("AOT")]
  44. [Obsolete ("The legacy static Application object is going away.")]
  45. public static IApplication Run<TRunnable> (Func<Exception, bool>? errorHandler = null, string? driverName = null)
  46. where TRunnable : IRunnable, new() => ApplicationImpl.Instance.Run<TRunnable> (errorHandler, driverName);
  47. /// <inheritdoc cref="IApplication.Run(IRunnable, Func{Exception, bool})"/>
  48. [Obsolete ("The legacy static Application object is going away.")]
  49. public static void Run (IRunnable runnable, Func<Exception, bool>? errorHandler = null) => ApplicationImpl.Instance.Run (runnable, errorHandler);
  50. /// <inheritdoc cref="IApplication.AddTimeout"/>
  51. [Obsolete ("The legacy static Application object is going away.")]
  52. public static object? AddTimeout (TimeSpan time, Func<bool> callback) => ApplicationImpl.Instance.AddTimeout (time, callback);
  53. /// <inheritdoc cref="IApplication.RemoveTimeout"/>
  54. [Obsolete ("The legacy static Application object is going away.")]
  55. public static bool RemoveTimeout (object token) => ApplicationImpl.Instance.RemoveTimeout (token);
  56. /// <inheritdoc cref="IApplication.TimedEvents"/>
  57. ///
  58. [Obsolete ("The legacy static Application object is going away.")]
  59. public static ITimedEvents? TimedEvents => ApplicationImpl.Instance.TimedEvents;
  60. /// <inheritdoc cref="IApplication.Invoke(Action{IApplication})"/>
  61. [Obsolete ("The legacy static Application object is going away.")]
  62. public static void Invoke (Action<IApplication> action) => ApplicationImpl.Instance.Invoke (action);
  63. /// <inheritdoc cref="IApplication.Invoke(Action)"/>
  64. [Obsolete ("The legacy static Application object is going away.")]
  65. public static void Invoke (Action action) => ApplicationImpl.Instance.Invoke (action);
  66. /// <inheritdoc cref="IApplication.LayoutAndDraw"/>
  67. [Obsolete ("The legacy static Application object is going away.")]
  68. public static void LayoutAndDraw (bool forceRedraw = false) => ApplicationImpl.Instance.LayoutAndDraw (forceRedraw);
  69. /// <inheritdoc cref="IApplication.StopAfterFirstIteration"/>
  70. [Obsolete ("The legacy static Application object is going away.")]
  71. public static bool StopAfterFirstIteration
  72. {
  73. get => ApplicationImpl.Instance.StopAfterFirstIteration;
  74. set => ApplicationImpl.Instance.StopAfterFirstIteration = value;
  75. }
  76. /// <inheritdoc cref="IApplication.RequestStop(IRunnable)"/>
  77. [Obsolete ("The legacy static Application object is going away.")]
  78. public static void RequestStop (IRunnable? runnable = null) => ApplicationImpl.Instance.RequestStop (runnable);
  79. /// <inheritdoc cref="IApplication.End(SessionToken)"/>
  80. [Obsolete ("The legacy static Application object is going away.")]
  81. public static void End (SessionToken sessionToken) => ApplicationImpl.Instance.End (sessionToken);
  82. /// <inheritdoc cref="IApplication.Iteration"/>
  83. [Obsolete ("The legacy static Application object is going away.")]
  84. public static event EventHandler<EventArgs<IApplication?>>? Iteration
  85. {
  86. add => ApplicationImpl.Instance.Iteration += value;
  87. remove => ApplicationImpl.Instance.Iteration -= value;
  88. }
  89. /// <inheritdoc cref="IApplication.SessionBegun"/>
  90. [Obsolete ("The legacy static Application object is going away.")]
  91. public static event EventHandler<SessionTokenEventArgs>? SessionBegun
  92. {
  93. add => ApplicationImpl.Instance.SessionBegun += value;
  94. remove => ApplicationImpl.Instance.SessionBegun -= value;
  95. }
  96. /// <inheritdoc cref="IApplication.SessionEnded"/>
  97. [Obsolete ("The legacy static Application object is going away.")]
  98. public static event EventHandler<SessionTokenEventArgs>? SessionEnded
  99. {
  100. add => ApplicationImpl.Instance.SessionEnded += value;
  101. remove => ApplicationImpl.Instance.SessionEnded -= value;
  102. }
  103. }