IApplication.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. using System.Collections.Concurrent;
  2. using System.Diagnostics.CodeAnalysis;
  3. namespace Terminal.Gui.App;
  4. /// <summary>
  5. /// Interface for instances that provide backing functionality to static
  6. /// gateway class <see cref="Application"/>.
  7. /// </summary>
  8. public interface IApplication
  9. {
  10. #region Keyboard
  11. /// <summary>
  12. /// Handles keyboard input and key bindings at the Application level.
  13. /// </summary>
  14. /// <remarks>
  15. /// <para>
  16. /// Provides access to keyboard state, key bindings, and keyboard event handling. Set during <see cref="Init"/>.
  17. /// </para>
  18. /// </remarks>
  19. IKeyboard Keyboard { get; set; }
  20. #endregion Keyboard
  21. #region Mouse
  22. /// <summary>
  23. /// Handles mouse event state and processing.
  24. /// </summary>
  25. /// <remarks>
  26. /// <para>
  27. /// Provides access to mouse state, mouse grabbing, and mouse event handling. Set during <see cref="Init"/>.
  28. /// </para>
  29. /// </remarks>
  30. IMouse Mouse { get; set; }
  31. #endregion Mouse
  32. #region Initialization and Shutdown
  33. /// <summary>Initializes a new instance of <see cref="Terminal.Gui"/> Application.</summary>
  34. /// <param name="driverName">
  35. /// The short name (e.g. "dotnet", "windows", "unix", or "fake") of the
  36. /// <see cref="IDriver"/> to use. If not specified the default driver for the platform will be used.
  37. /// </param>
  38. /// <remarks>
  39. /// <para>Call this method once per instance (or after <see cref="Shutdown"/> has been called).</para>
  40. /// <para>
  41. /// This function loads the right <see cref="IDriver"/> for the platform, creates a main loop coordinator,
  42. /// initializes keyboard and mouse handlers, and subscribes to driver events.
  43. /// </para>
  44. /// <para>
  45. /// <see cref="Shutdown"/> must be called when the application is closing (typically after
  46. /// <see cref="Run{T}"/> has returned) to ensure resources are cleaned up and terminal settings restored.
  47. /// </para>
  48. /// <para>
  49. /// The <see cref="Run{T}"/> function combines <see cref="Init(string)"/> and
  50. /// <see cref="Run(Toplevel, Func{Exception, bool})"/> into a single call. An application can use
  51. /// <see cref="Run{T}"/> without explicitly calling <see cref="Init(string)"/>.
  52. /// </para>
  53. /// </remarks>
  54. [RequiresUnreferencedCode ("AOT")]
  55. [RequiresDynamicCode ("AOT")]
  56. public void Init (string? driverName = null);
  57. /// <summary>
  58. /// This event is raised after the <see cref="Init"/> and <see cref="Shutdown"/> methods have been called.
  59. /// </summary>
  60. /// <remarks>
  61. /// Intended to support unit tests that need to know when the application has been initialized.
  62. /// </remarks>
  63. public event EventHandler<EventArgs<bool>>? InitializedChanged;
  64. /// <summary>Gets or sets whether the application has been initialized.</summary>
  65. bool Initialized { get; set; }
  66. /// <summary>Shutdown an application initialized with <see cref="Init"/>.</summary>
  67. /// <remarks>
  68. /// Shutdown must be called for every call to <see cref="Init"/> or
  69. /// <see cref="Application.Run(Toplevel, Func{Exception, bool})"/> to ensure all resources are cleaned
  70. /// up (Disposed) and terminal settings are restored.
  71. /// </remarks>
  72. public void Shutdown ();
  73. /// <summary>
  74. /// Resets the state of this instance.
  75. /// </summary>
  76. /// <param name="ignoreDisposed">If true, ignores disposed state checks during reset.</param>
  77. /// <remarks>
  78. /// <para>
  79. /// Encapsulates all setting of initial state for Application; having this in a function like this ensures we
  80. /// don't make mistakes in guaranteeing that the state of this singleton is deterministic when <see cref="Init"/>
  81. /// starts running and after <see cref="Shutdown"/> returns.
  82. /// </para>
  83. /// <para>
  84. /// IMPORTANT: Ensure all property/fields are reset here. See Init_ResetState_Resets_Properties unit test.
  85. /// </para>
  86. /// </remarks>
  87. public void ResetState (bool ignoreDisposed = false);
  88. #endregion Initialization and Shutdown
  89. #region Begin->Run->Iteration->Stop->End
  90. /// <summary>
  91. /// Building block API: Creates a <see cref="SessionToken"/> and prepares the provided <see cref="Toplevel"/> for
  92. /// execution. Not usually called directly by applications. Use <see cref="Run(Toplevel, Func{Exception, bool})"/>
  93. /// instead.
  94. /// </summary>
  95. /// <returns>
  96. /// The <see cref="SessionToken"/> that needs to be passed to the <see cref="End(SessionToken)"/> method upon
  97. /// completion.
  98. /// </returns>
  99. /// <param name="toplevel">The <see cref="Toplevel"/> to prepare execution for.</param>
  100. /// <remarks>
  101. /// <para>
  102. /// This method prepares the provided <see cref="Toplevel"/> for running. It adds this to the
  103. /// list of <see cref="Toplevel"/>s, lays out the SubViews, focuses the first element, and draws the
  104. /// <see cref="Toplevel"/> on the screen. This is usually followed by starting the main loop, and then the
  105. /// <see cref="End(SessionToken)"/> method upon termination which will undo these changes.
  106. /// </para>
  107. /// <para>
  108. /// Raises the <see cref="SessionBegun"/> event before returning.
  109. /// </para>
  110. /// </remarks>
  111. public SessionToken Begin (Toplevel toplevel);
  112. /// <summary>
  113. /// Runs a new Session creating a <see cref="Toplevel"/> and calling <see cref="Begin(Toplevel)"/>. When the session is
  114. /// stopped, <see cref="End(SessionToken)"/> will be called.
  115. /// </summary>
  116. /// <param name="errorHandler">Handler for any unhandled exceptions (resumes when returns true, rethrows when null).</param>
  117. /// <param name="driverName">
  118. /// The driver name. If not specified the default driver for the platform will be used. Must be
  119. /// <see langword="null"/> if <see cref="Init"/> has already been called.
  120. /// </param>
  121. /// <returns>The created <see cref="Toplevel"/>. The caller is responsible for disposing this object.</returns>
  122. /// <remarks>
  123. /// <para>Calling <see cref="Init"/> first is not needed as this function will initialize the application.</para>
  124. /// <para>
  125. /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run has returned) to
  126. /// ensure resources are cleaned up and terminal settings restored.
  127. /// </para>
  128. /// <para>
  129. /// The caller is responsible for disposing the object returned by this method.
  130. /// </para>
  131. /// </remarks>
  132. [RequiresUnreferencedCode ("AOT")]
  133. [RequiresDynamicCode ("AOT")]
  134. public Toplevel Run (Func<Exception, bool>? errorHandler = null, string? driverName = null);
  135. /// <summary>
  136. /// Runs a new Session creating a <see cref="Toplevel"/>-derived object of type <typeparamref name="TView"/>
  137. /// and calling <see cref="Run(Toplevel, Func{Exception, bool})"/>. When the session is stopped,
  138. /// <see cref="End(SessionToken)"/> will be called.
  139. /// </summary>
  140. /// <typeparam name="TView">The type of <see cref="Toplevel"/> to create and run.</typeparam>
  141. /// <param name="errorHandler">Handler for any unhandled exceptions (resumes when returns true, rethrows when null).</param>
  142. /// <param name="driverName">
  143. /// The driver name. If not specified the default driver for the platform will be used. Must be
  144. /// <see langword="null"/> if <see cref="Init"/> has already been called.
  145. /// </param>
  146. /// <returns>The created <typeparamref name="TView"/> object. The caller is responsible for disposing this object.</returns>
  147. /// <remarks>
  148. /// <para>
  149. /// This method is used to start processing events for the main application, but it is also used to run other
  150. /// modal <see cref="View"/>s such as <see cref="Dialog"/> boxes.
  151. /// </para>
  152. /// <para>
  153. /// To make <see cref="Run(Toplevel, Func{Exception, bool})"/> stop execution, call
  154. /// <see cref="RequestStop()"/> or <see cref="RequestStop(Toplevel)"/>.
  155. /// </para>
  156. /// <para>
  157. /// Calling <see cref="Run(Toplevel, Func{Exception, bool})"/> is equivalent to calling
  158. /// <see cref="Begin(Toplevel)"/>, followed by starting the main loop, and then calling
  159. /// <see cref="End(SessionToken)"/>.
  160. /// </para>
  161. /// <para>
  162. /// When using <see cref="Run{T}"/> or <see cref="Run(Func{Exception, bool}, string)"/>,
  163. /// <see cref="Init"/> will be called automatically.
  164. /// </para>
  165. /// <para>
  166. /// In RELEASE builds: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
  167. /// rethrown. Otherwise, <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
  168. /// returns <see langword="true"/> the main loop will resume; otherwise this method will exit.
  169. /// </para>
  170. /// <para>
  171. /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run has returned) to
  172. /// ensure resources are cleaned up and terminal settings restored.
  173. /// </para>
  174. /// <para>
  175. /// In RELEASE builds: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
  176. /// rethrown. Otherwise, <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
  177. /// returns <see langword="true"/> the main loop will resume; otherwise this method will exit.
  178. /// </para>
  179. /// <para>
  180. /// The caller is responsible for disposing the object returned by this method.
  181. /// </para>
  182. /// </remarks>
  183. [RequiresUnreferencedCode ("AOT")]
  184. [RequiresDynamicCode ("AOT")]
  185. public TView Run<TView> (Func<Exception, bool>? errorHandler = null, string? driverName = null)
  186. where TView : Toplevel, new ();
  187. /// <summary>
  188. /// Runs a new Session using the provided <see cref="Toplevel"/> view and calling
  189. /// <see cref="Run(Toplevel, Func{Exception, bool})"/>.
  190. /// When the session is stopped, <see cref="End(SessionToken)"/> will be called..
  191. /// </summary>
  192. /// <param name="view">The <see cref="Toplevel"/> to run as a modal.</param>
  193. /// <param name="errorHandler">Handler for any unhandled exceptions (resumes when returns true, rethrows when null).</param>
  194. /// <remarks>
  195. /// <para>
  196. /// This method is used to start processing events for the main application, but it is also used to run other
  197. /// modal <see cref="View"/>s such as <see cref="Dialog"/> boxes.
  198. /// </para>
  199. /// <para>
  200. /// To make <see cref="Run(Toplevel, Func{Exception, bool})"/> stop execution, call
  201. /// <see cref="RequestStop()"/> or <see cref="RequestStop(Toplevel)"/>.
  202. /// </para>
  203. /// <para>
  204. /// Calling <see cref="Run(Toplevel, Func{Exception, bool})"/> is equivalent to calling
  205. /// <see cref="Begin(Toplevel)"/>, followed by starting the main loop, and then calling
  206. /// <see cref="End(SessionToken)"/>.
  207. /// </para>
  208. /// <para>
  209. /// When using <see cref="Run{T}"/> or <see cref="Run(Func{Exception, bool}, string)"/>,
  210. /// <see cref="Init"/> will be called automatically.
  211. /// </para>
  212. /// <para>
  213. /// <see cref="Shutdown"/> must be called when the application is closing (typically after Run has returned) to
  214. /// ensure resources are cleaned up and terminal settings restored.
  215. /// </para>
  216. /// <para>
  217. /// In RELEASE builds: When <paramref name="errorHandler"/> is <see langword="null"/> any exceptions will be
  218. /// rethrown. Otherwise, <paramref name="errorHandler"/> will be called. If <paramref name="errorHandler"/>
  219. /// returns <see langword="true"/> the main loop will resume; otherwise this method will exit.
  220. /// </para>
  221. /// <para>
  222. /// The caller is responsible for disposing the object returned by this method.
  223. /// </para>
  224. /// </remarks>
  225. public void Run (Toplevel view, Func<Exception, bool>? errorHandler = null);
  226. /// <summary>
  227. /// Raises the <see cref="Iteration"/> event.
  228. /// </summary>
  229. /// <remarks>
  230. /// This is called once per main loop iteration, before processing input, timeouts, or rendering.
  231. /// </remarks>
  232. public void RaiseIteration ();
  233. /// <summary>This event is raised on each iteration of the main loop.</summary>
  234. /// <remarks>
  235. /// <para>
  236. /// This event is raised before input processing, timeout callbacks, and rendering occur each iteration.
  237. /// </para>
  238. /// <para>See also <see cref="AddTimeout"/> and <see cref="TimedEvents"/>.</para>
  239. /// </remarks>
  240. public event EventHandler<IterationEventArgs>? Iteration;
  241. /// <summary>Runs <paramref name="action"/> on the main UI loop thread.</summary>
  242. /// <param name="action">The action to be invoked on the main processing thread.</param>
  243. /// <remarks>
  244. /// <para>
  245. /// If called from the main thread, the action is executed immediately. Otherwise, it is queued via
  246. /// <see cref="AddTimeout"/> with <see cref="TimeSpan.Zero"/> and will be executed on the next main loop
  247. /// iteration.
  248. /// </para>
  249. /// </remarks>
  250. void Invoke (Action<IApplication>? action);
  251. /// <summary>Runs <paramref name="action"/> on the main UI loop thread.</summary>
  252. /// <param name="action">The action to be invoked on the main processing thread.</param>
  253. /// <remarks>
  254. /// <para>
  255. /// If called from the main thread, the action is executed immediately. Otherwise, it is queued via
  256. /// <see cref="AddTimeout"/> with <see cref="TimeSpan.Zero"/> and will be executed on the next main loop
  257. /// iteration.
  258. /// </para>
  259. /// </remarks>
  260. void Invoke (Action action);
  261. /// <summary>
  262. /// Building block API: Ends a Session and completes the execution of a <see cref="Toplevel"/> that was started with
  263. /// <see cref="Begin(Toplevel)"/>. Not usually called directly by applications.
  264. /// <see cref="Run(Toplevel, Func{Exception, bool})"/>
  265. /// will automatically call this method when the session is stopped.
  266. /// </summary>
  267. /// <param name="sessionToken">The <see cref="SessionToken"/> returned by the <see cref="Begin(Toplevel)"/> method.</param>
  268. /// <remarks>
  269. /// <para>
  270. /// This method removes the <see cref="Toplevel"/> from the stack, raises the <see cref="SessionEnded"/>
  271. /// event, and disposes the <paramref name="sessionToken"/>.
  272. /// </para>
  273. /// </remarks>
  274. public void End (SessionToken sessionToken);
  275. /// <summary>Requests that the currently running Session stop. The Session will stop after the current iteration completes.</summary>
  276. /// <remarks>
  277. /// <para>This will cause <see cref="Run(Toplevel, Func{Exception, bool})"/> to return.</para>
  278. /// <para>
  279. /// This is equivalent to calling <see cref="RequestStop(Toplevel)"/> with <see cref="Current"/> as the parameter.
  280. /// </para>
  281. /// </remarks>
  282. void RequestStop ();
  283. /// <summary>Requests that the currently running Session stop. The Session will stop after the current iteration completes.</summary>
  284. /// <param name="top">
  285. /// The <see cref="Toplevel"/> to stop. If <see langword="null"/>, stops the currently running <see cref="Current"/>.
  286. /// </param>
  287. /// <remarks>
  288. /// <para>This will cause <see cref="Run(Toplevel, Func{Exception, bool})"/> to return.</para>
  289. /// <para>
  290. /// Calling <see cref="RequestStop(Toplevel)"/> is equivalent to setting the <see cref="Toplevel.Running"/>
  291. /// property on the specified <see cref="Toplevel"/> to <see langword="false"/>.
  292. /// </para>
  293. /// </remarks>
  294. void RequestStop (Toplevel? top);
  295. /// <summary>
  296. /// Set to <see langword="true"/> to cause the session to stop running after first iteration.
  297. /// </summary>
  298. /// <remarks>
  299. /// <para>
  300. /// Used primarily for unit testing. When <see langword="true"/>, <see cref="End"/> will be called
  301. /// automatically after the first main loop iteration.
  302. /// </para>
  303. /// </remarks>
  304. bool StopAfterFirstIteration { get; set; }
  305. /// <summary>
  306. /// Raised when <see cref="Begin(Toplevel)"/> has been called and has created a new <see cref="SessionToken"/>.
  307. /// </summary>
  308. /// <remarks>
  309. /// If <see cref="StopAfterFirstIteration"/> is <see langword="true"/>, callers to <see cref="Begin(Toplevel)"/>
  310. /// must also subscribe to <see cref="SessionEnded"/> and manually dispose of the <see cref="SessionToken"/> token
  311. /// when the application is done.
  312. /// </remarks>
  313. public event EventHandler<SessionTokenEventArgs>? SessionBegun;
  314. /// <summary>
  315. /// Raised when <see cref="End(SessionToken)"/> was called and the session is stopping. The event args contain a
  316. /// reference to the <see cref="Toplevel"/>
  317. /// that was active during the session. This can be used to ensure the Toplevel is disposed of properly.
  318. /// </summary>
  319. /// <remarks>
  320. /// If <see cref="StopAfterFirstIteration"/> is <see langword="true"/>, callers to <see cref="Begin(Toplevel)"/>
  321. /// must also subscribe to <see cref="SessionEnded"/> and manually dispose of the <see cref="SessionToken"/> token
  322. /// when the application is done.
  323. /// </remarks>
  324. public event EventHandler<ToplevelEventArgs>? SessionEnded;
  325. #endregion Begin->Run->Iteration->Stop->End
  326. #region Toplevel Management
  327. /// <summary>Gets or sets the currently active Toplevel.</summary>
  328. /// <remarks>
  329. /// <para>
  330. /// This is set by <see cref="Begin(Toplevel)"/> and cleared by <see cref="End(SessionToken)"/>.
  331. /// </para>
  332. /// </remarks>
  333. Toplevel? Current { get; set; }
  334. /// <summary>Gets the stack of all active Toplevel sessions.</summary>
  335. /// <remarks>
  336. /// <para>
  337. /// Toplevels are added to this stack by <see cref="Begin(Toplevel)"/> and removed by
  338. /// <see cref="End(SessionToken)"/>.
  339. /// </para>
  340. /// </remarks>
  341. ConcurrentStack<Toplevel> SessionStack { get; }
  342. /// <summary>
  343. /// Caches the Toplevel associated with the current Session.
  344. /// </summary>
  345. /// <remarks>
  346. /// Used internally to optimize Toplevel state transitions.
  347. /// </remarks>
  348. Toplevel? CachedSessionTokenToplevel { get; set; }
  349. #endregion Toplevel Management
  350. #region Screen and Driver
  351. /// <summary>Gets or sets the console driver being used.</summary>
  352. /// <remarks>
  353. /// <para>
  354. /// Set by <see cref="Init"/> based on the driver parameter or platform default.
  355. /// </para>
  356. /// </remarks>
  357. IDriver? Driver { get; set; }
  358. /// <summary>
  359. /// Gets or sets whether <see cref="Driver"/> will be forced to output only the 16 colors defined in
  360. /// <see cref="ColorName16"/>. The default is <see langword="false"/>, meaning 24-bit (TrueColor) colors will be
  361. /// output as long as the selected <see cref="IDriver"/> supports TrueColor.
  362. /// </summary>
  363. bool Force16Colors { get; set; }
  364. /// <summary>
  365. /// Forces the use of the specified driver (one of "fake", "dotnet", "windows", or "unix"). If not
  366. /// specified, the driver is selected based on the platform.
  367. /// </summary>
  368. string ForceDriver { get; set; }
  369. /// <summary>
  370. /// Gets or sets the size of the screen. By default, this is the size of the screen as reported by the
  371. /// <see cref="IDriver"/>.
  372. /// </summary>
  373. /// <remarks>
  374. /// <para>
  375. /// If the <see cref="IDriver"/> has not been initialized, this will return a default size of 2048x2048; useful
  376. /// for unit tests.
  377. /// </para>
  378. /// </remarks>
  379. Rectangle Screen { get; set; }
  380. /// <summary>Raised when the terminal's size changed. The new size of the terminal is provided.</summary>
  381. /// <remarks>
  382. /// <para>
  383. /// This event is raised when the driver detects a screen size change. The event provides the new screen
  384. /// rectangle.
  385. /// </para>
  386. /// </remarks>
  387. public event EventHandler<EventArgs<Rectangle>>? ScreenChanged;
  388. /// <summary>
  389. /// Gets or sets whether the screen will be cleared, and all Views redrawn, during the next Application iteration.
  390. /// </summary>
  391. /// <remarks>
  392. /// <para>
  393. /// This is typically set to <see langword="true"/> when a View's <see cref="View.Frame"/> changes and that view
  394. /// has no SuperView (e.g. when <see cref="Current"/> is moved or resized).
  395. /// </para>
  396. /// <para>
  397. /// Automatically reset to <see langword="false"/> after <see cref="LayoutAndDraw"/> processes it.
  398. /// </para>
  399. /// </remarks>
  400. bool ClearScreenNextIteration { get; set; }
  401. /// <summary>
  402. /// Collection of sixel images to write out to screen when updating.
  403. /// Only add to this collection if you are sure terminal supports sixel format.
  404. /// </summary>
  405. List<SixelToRender> Sixel { get; }
  406. #endregion Screen and Driver
  407. #region Layout and Drawing
  408. /// <summary>
  409. /// Causes any Toplevels that need layout to be laid out, then draws any Toplevels that need display. Only Views
  410. /// that need to be laid out (see <see cref="View.NeedsLayout"/>) will be laid out. Only Views that need to be drawn
  411. /// (see <see cref="View.NeedsDraw"/>) will be drawn.
  412. /// </summary>
  413. /// <param name="forceRedraw">
  414. /// If <see langword="true"/> the entire View hierarchy will be redrawn. The default is <see langword="false"/> and
  415. /// should only be overridden for testing.
  416. /// </param>
  417. /// <remarks>
  418. /// <para>
  419. /// This method is called automatically each main loop iteration when any views need layout or drawing.
  420. /// </para>
  421. /// <para>
  422. /// If <see cref="ClearScreenNextIteration"/> is <see langword="true"/>, the screen will be cleared before
  423. /// drawing and the flag will be reset to <see langword="false"/>.
  424. /// </para>
  425. /// </remarks>
  426. public void LayoutAndDraw (bool forceRedraw = false);
  427. /// <summary>
  428. /// Calls <see cref="View.PositionCursor"/> on the most focused view.
  429. /// </summary>
  430. /// <remarks>
  431. /// <para>Does nothing if there is no most focused view.</para>
  432. /// <para>
  433. /// If the most focused view is not visible within its superview, the cursor will be hidden.
  434. /// </para>
  435. /// </remarks>
  436. /// <returns><see langword="true"/> if a view positioned the cursor and the position is visible.</returns>
  437. public bool PositionCursor ();
  438. #endregion Layout and Drawing
  439. #region Navigation and Popover
  440. /// <summary>Gets or sets the popover manager.</summary>
  441. /// <remarks>
  442. /// <para>
  443. /// Manages application-level popover views. Initialized during <see cref="Init"/>.
  444. /// </para>
  445. /// </remarks>
  446. ApplicationPopover? Popover { get; set; }
  447. /// <summary>Gets or sets the navigation manager.</summary>
  448. /// <remarks>
  449. /// <para>
  450. /// Manages focus navigation and tracking of the most focused view. Initialized during <see cref="Init"/>.
  451. /// </para>
  452. /// </remarks>
  453. ApplicationNavigation? Navigation { get; set; }
  454. #endregion Navigation and Popover
  455. #region Timeouts
  456. /// <summary>Adds a timeout to the application.</summary>
  457. /// <param name="time">The time span to wait before invoking the callback.</param>
  458. /// <param name="callback">
  459. /// The callback to invoke. If it returns <see langword="true"/>, the timeout will be reset and repeat. If it
  460. /// returns <see langword="false"/>, the timeout will stop and be removed.
  461. /// </param>
  462. /// <returns>
  463. /// Call <see cref="RemoveTimeout(object)"/> with the returned value to stop the timeout.
  464. /// </returns>
  465. /// <remarks>
  466. /// <para>
  467. /// When the time specified passes, the callback will be invoked on the main UI thread.
  468. /// </para>
  469. /// <para>
  470. /// <see cref="IApplication.Shutdown"/> calls StopAll on <see cref="TimedEvents"/> to remove all timeouts.
  471. /// </para>
  472. /// </remarks>
  473. object AddTimeout (TimeSpan time, Func<bool> callback);
  474. /// <summary>Removes a previously scheduled timeout.</summary>
  475. /// <param name="token">The token returned by <see cref="AddTimeout"/>.</param>
  476. /// <returns>
  477. /// <see langword="true"/> if the timeout is successfully removed; otherwise, <see langword="false"/>.
  478. /// This method also returns <see langword="false"/> if the timeout is not found.
  479. /// </returns>
  480. bool RemoveTimeout (object token);
  481. /// <summary>
  482. /// Handles recurring events. These are invoked on the main UI thread - allowing for
  483. /// safe updates to <see cref="View"/> instances.
  484. /// </summary>
  485. /// <remarks>
  486. /// <para>
  487. /// Provides low-level access to the timeout management system. Most applications should use
  488. /// <see cref="AddTimeout"/> and <see cref="RemoveTimeout"/> instead.
  489. /// </para>
  490. /// </remarks>
  491. ITimedEvents? TimedEvents { get; }
  492. #endregion Timeouts
  493. /// <summary>
  494. /// Gets a string representation of the Application as rendered by <see cref="Driver"/>.
  495. /// </summary>
  496. /// <returns>A string representation of the Application </returns>
  497. public string ToString ();
  498. }