|
@@ -32,6 +32,77 @@ namespace Terminal.Gui;
|
|
/// TODO: Flush this out.
|
|
/// TODO: Flush this out.
|
|
/// </remarks>
|
|
/// </remarks>
|
|
public static partial class Application {
|
|
public static partial class Application {
|
|
|
|
+
|
|
|
|
+ // IMPORTANT: Ensure all property/fields are reset here. See Init_ResetState_Resets_Properties unit test.
|
|
|
|
+ // Encapsulate all setting of initial state for Application; Having
|
|
|
|
+ // this in a function like this ensures we don't make mistakes in
|
|
|
|
+ // guaranteeing that the state of this singleton is deterministic when Init
|
|
|
|
+ // starts running and after Shutdown returns.
|
|
|
|
+ internal static void ResetState ()
|
|
|
|
+ {
|
|
|
|
+ // Shutdown is the bookend for Init. As such it needs to clean up all resources
|
|
|
|
+ // Init created. Apps that do any threading will need to code defensively for this.
|
|
|
|
+ // e.g. see Issue #537
|
|
|
|
+ foreach (var t in _topLevels) {
|
|
|
|
+ t.Running = false;
|
|
|
|
+ t.Dispose ();
|
|
|
|
+ }
|
|
|
|
+ _topLevels.Clear ();
|
|
|
|
+ Current = null;
|
|
|
|
+ Top?.Dispose ();
|
|
|
|
+ Top = null;
|
|
|
|
+
|
|
|
|
+ // MainLoop stuff
|
|
|
|
+ MainLoop?.Dispose ();
|
|
|
|
+ MainLoop = null;
|
|
|
|
+ _mainThreadId = -1;
|
|
|
|
+ Iteration = null;
|
|
|
|
+ EndAfterFirstIteration = false;
|
|
|
|
+
|
|
|
|
+ // Driver stuff
|
|
|
|
+ if (Driver != null) {
|
|
|
|
+ Driver.SizeChanged -= Driver_SizeChanged;
|
|
|
|
+ Driver.KeyDown -= Driver_KeyDown;
|
|
|
|
+ Driver.KeyUp -= Driver_KeyUp;
|
|
|
|
+ Driver.MouseEvent -= Driver_MouseEvent;
|
|
|
|
+ Driver?.End ();
|
|
|
|
+ Driver = null;
|
|
|
|
+ }
|
|
|
|
+ // Don't reset ForceDriver; it needs to be set before Init is called.
|
|
|
|
+ //ForceDriver = string.Empty;
|
|
|
|
+ Force16Colors = false;
|
|
|
|
+ _forceFakeConsole = false;
|
|
|
|
+
|
|
|
|
+ // Run State stuff
|
|
|
|
+ NotifyNewRunState = null;
|
|
|
|
+ NotifyStopRunState = null;
|
|
|
|
+ MouseGrabView = null;
|
|
|
|
+ _initialized = false;
|
|
|
|
+
|
|
|
|
+ // Mouse
|
|
|
|
+ _mouseEnteredView = null;
|
|
|
|
+ WantContinuousButtonPressedView = null;
|
|
|
|
+ MouseEvent = null;
|
|
|
|
+ GrabbedMouse = null;
|
|
|
|
+ UnGrabbingMouse = null;
|
|
|
|
+ GrabbedMouse = null;
|
|
|
|
+ UnGrabbedMouse = null;
|
|
|
|
+
|
|
|
|
+ // Keyboard
|
|
|
|
+ AlternateBackwardKey = Key.Empty;
|
|
|
|
+ AlternateForwardKey = Key.Empty;
|
|
|
|
+ QuitKey = Key.Empty;
|
|
|
|
+ KeyDown = null;
|
|
|
|
+ KeyUp = null;
|
|
|
|
+ SizeChanging = null;
|
|
|
|
+
|
|
|
|
+ // Reset synchronization context to allow the user to run async/await,
|
|
|
|
+ // as the main loop has been ended, the synchronization context from
|
|
|
|
+ // gui.cs does no longer process any callbacks. See #1084 for more details:
|
|
|
|
+ // (https://github.com/gui-cs/Terminal.Gui/issues/1084).
|
|
|
|
+ SynchronizationContext.SetSynchronizationContext (syncContext: null);
|
|
|
|
+ }
|
|
|
|
+
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets the <see cref="ConsoleDriver"/> that has been selected. See also <see cref="ForceDriver"/>.
|
|
/// Gets the <see cref="ConsoleDriver"/> that has been selected. See also <see cref="ForceDriver"/>.
|
|
/// </summary>
|
|
/// </summary>
|
|
@@ -66,7 +137,7 @@ public static partial class Application {
|
|
/// </summary>
|
|
/// </summary>
|
|
public static List<CultureInfo> SupportedCultures => _cachedSupportedCultures;
|
|
public static List<CultureInfo> SupportedCultures => _cachedSupportedCultures;
|
|
|
|
|
|
- static List<CultureInfo> GetSupportedCultures ()
|
|
|
|
|
|
+ internal static List<CultureInfo> GetSupportedCultures ()
|
|
{
|
|
{
|
|
var culture = CultureInfo.GetCultures (CultureTypes.AllCultures);
|
|
var culture = CultureInfo.GetCultures (CultureTypes.AllCultures);
|
|
|
|
|
|
@@ -241,55 +312,6 @@ public static partial class Application {
|
|
ResetState ();
|
|
ResetState ();
|
|
PrintJsonErrors ();
|
|
PrintJsonErrors ();
|
|
}
|
|
}
|
|
-
|
|
|
|
- // Encapsulate all setting of initial state for Application; Having
|
|
|
|
- // this in a function like this ensures we don't make mistakes in
|
|
|
|
- // guaranteeing that the state of this singleton is deterministic when Init
|
|
|
|
- // starts running and after Shutdown returns.
|
|
|
|
- static void ResetState ()
|
|
|
|
- {
|
|
|
|
- // Shutdown is the bookend for Init. As such it needs to clean up all resources
|
|
|
|
- // Init created. Apps that do any threading will need to code defensively for this.
|
|
|
|
- // e.g. see Issue #537
|
|
|
|
- foreach (var t in _topLevels) {
|
|
|
|
- t.Running = false;
|
|
|
|
- t.Dispose ();
|
|
|
|
- }
|
|
|
|
- _topLevels.Clear ();
|
|
|
|
- Current = null;
|
|
|
|
- Top?.Dispose ();
|
|
|
|
- Top = null;
|
|
|
|
-
|
|
|
|
- // BUGBUG: OverlappedTop is not cleared here, but it should be?
|
|
|
|
-
|
|
|
|
- MainLoop?.Dispose ();
|
|
|
|
- MainLoop = null;
|
|
|
|
- if (Driver != null) {
|
|
|
|
- Driver.SizeChanged -= Driver_SizeChanged;
|
|
|
|
- Driver.KeyDown -= Driver_KeyDown;
|
|
|
|
- Driver.KeyUp -= Driver_KeyUp;
|
|
|
|
- Driver.MouseEvent -= Driver_MouseEvent;
|
|
|
|
- Driver?.End ();
|
|
|
|
- Driver = null;
|
|
|
|
- }
|
|
|
|
- Iteration = null;
|
|
|
|
- MouseEvent = null;
|
|
|
|
- KeyDown = null;
|
|
|
|
- KeyUp = null;
|
|
|
|
- SizeChanging = null;
|
|
|
|
- _mainThreadId = -1;
|
|
|
|
- NotifyNewRunState = null;
|
|
|
|
- NotifyStopRunState = null;
|
|
|
|
- _initialized = false;
|
|
|
|
- MouseGrabView = null;
|
|
|
|
- _mouseEnteredView = null;
|
|
|
|
-
|
|
|
|
- // Reset synchronization context to allow the user to run async/await,
|
|
|
|
- // as the main loop has been ended, the synchronization context from
|
|
|
|
- // gui.cs does no longer process any callbacks. See #1084 for more details:
|
|
|
|
- // (https://github.com/gui-cs/Terminal.Gui/issues/1084).
|
|
|
|
- SynchronizationContext.SetSynchronizationContext (syncContext: null);
|
|
|
|
- }
|
|
|
|
#endregion Initialization (Init/Shutdown)
|
|
#endregion Initialization (Init/Shutdown)
|
|
|
|
|
|
#region Run (Begin, Run, End, Stop)
|
|
#region Run (Begin, Run, End, Stop)
|
|
@@ -881,7 +903,7 @@ public static partial class Application {
|
|
/// </summary>
|
|
/// </summary>
|
|
// BUGBUG: Techncally, this is not the full lst of TopLevels. THere be dragons hwre. E.g. see how Toplevel.Id is used. What
|
|
// BUGBUG: Techncally, this is not the full lst of TopLevels. THere be dragons hwre. E.g. see how Toplevel.Id is used. What
|
|
// about TopLevels that are just a SubView of another View?
|
|
// about TopLevels that are just a SubView of another View?
|
|
- static readonly Stack<Toplevel> _topLevels = new Stack<Toplevel> ();
|
|
|
|
|
|
+ internal static readonly Stack<Toplevel> _topLevels = new Stack<Toplevel> ();
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// The <see cref="Toplevel"/> object used for the application on startup (<seealso cref="Application.Top"/>)
|
|
/// The <see cref="Toplevel"/> object used for the application on startup (<seealso cref="Application.Top"/>)
|
|
@@ -1141,7 +1163,7 @@ public static partial class Application {
|
|
}
|
|
}
|
|
|
|
|
|
// Used by OnMouseEvent to track the last view that was clicked on.
|
|
// Used by OnMouseEvent to track the last view that was clicked on.
|
|
- static View _mouseEnteredView;
|
|
|
|
|
|
+ internal static View _mouseEnteredView;
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Event fired when a mouse move or click occurs. Coordinates are screen relative.
|
|
/// Event fired when a mouse move or click occurs. Coordinates are screen relative.
|
|
@@ -1333,7 +1355,7 @@ public static partial class Application {
|
|
#endregion Mouse handling
|
|
#endregion Mouse handling
|
|
|
|
|
|
#region Keyboard handling
|
|
#region Keyboard handling
|
|
- static Key _alternateForwardKey = new Key (KeyCode.PageDown | KeyCode.CtrlMask);
|
|
|
|
|
|
+ static Key _alternateForwardKey = Key.Empty; // Defined in config.json
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Alternative key to navigate forwards through views. Ctrl+Tab is the primary key.
|
|
/// Alternative key to navigate forwards through views. Ctrl+Tab is the primary key.
|
|
@@ -1358,7 +1380,7 @@ public static partial class Application {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- static Key _alternateBackwardKey = new Key (KeyCode.PageUp | KeyCode.CtrlMask);
|
|
|
|
|
|
+ static Key _alternateBackwardKey = Key.Empty; // Defined in config.json
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Alternative key to navigate backwards through views. Shift+Ctrl+Tab is the primary key.
|
|
/// Alternative key to navigate backwards through views. Shift+Ctrl+Tab is the primary key.
|
|
@@ -1383,7 +1405,7 @@ public static partial class Application {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- static Key _quitKey = new Key (KeyCode.Q | KeyCode.CtrlMask);
|
|
|
|
|
|
+ static Key _quitKey = Key.Empty; // Defined in config.json
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Gets or sets the key to quit the application.
|
|
/// Gets or sets the key to quit the application.
|