mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
IsInitialized->Initialized
This commit is contained in:
@@ -39,15 +39,6 @@ public static partial class Application // Initialization (Init/Shutdown)
|
||||
[RequiresDynamicCode ("AOT")]
|
||||
public static void Init (ConsoleDriver? driver = null, string? driverName = null) { InternalInit (driver, driverName); }
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the application has been initialized with <see cref="Init"/> and not yet shutdown with <see cref="Shutdown"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The <see cref="InitializedChanged"/> event is raised after the <see cref="Init"/> and <see cref="Shutdown"/> methods have been called.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static bool IsInitialized { get; private set; }
|
||||
internal static int MainThreadId { get; set; } = -1;
|
||||
|
||||
// INTERNAL function for initializing an app with a Toplevel factory object, driver, and mainloop.
|
||||
@@ -67,12 +58,12 @@ public static partial class Application // Initialization (Init/Shutdown)
|
||||
bool calledViaRunT = false
|
||||
)
|
||||
{
|
||||
if (IsInitialized && driver is null)
|
||||
if (Initialized && driver is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsInitialized)
|
||||
if (Initialized)
|
||||
{
|
||||
throw new InvalidOperationException ("Init has already been called and must be bracketed by Shutdown.");
|
||||
}
|
||||
@@ -181,7 +172,7 @@ public static partial class Application // Initialization (Init/Shutdown)
|
||||
|
||||
SupportedCultures = GetSupportedCultures ();
|
||||
MainThreadId = Thread.CurrentThread.ManagedThreadId;
|
||||
bool init = IsInitialized = true;
|
||||
bool init = Initialized = true;
|
||||
InitializedChanged?.Invoke (null, new (init));
|
||||
}
|
||||
|
||||
@@ -223,17 +214,27 @@ public static partial class Application // Initialization (Init/Shutdown)
|
||||
{
|
||||
// TODO: Throw an exception if Init hasn't been called.
|
||||
|
||||
bool wasInitialized = IsInitialized;
|
||||
bool wasInitialized = Initialized;
|
||||
ResetState ();
|
||||
PrintJsonErrors ();
|
||||
|
||||
if (wasInitialized)
|
||||
{
|
||||
bool init = IsInitialized;
|
||||
bool init = Initialized;
|
||||
InitializedChanged?.Invoke (null, new (in init));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the application has been initialized with <see cref="Init"/> and not yet shutdown with <see cref="Shutdown"/>.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// The <see cref="InitializedChanged"/> event is raised after the <see cref="Init"/> and <see cref="Shutdown"/> methods have been called.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public static bool Initialized { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// This event is raised after the <see cref="Init"/> and <see cref="Shutdown"/> methods have been called.
|
||||
/// </summary>
|
||||
|
||||
@@ -120,7 +120,7 @@ public static partial class Application // Keyboard handling
|
||||
/// <returns><see langword="true"/> if the key was handled.</returns>
|
||||
public static bool RaiseKeyUpEvent (Key key)
|
||||
{
|
||||
if (!IsInitialized)
|
||||
if (!Initialized)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -328,7 +328,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
|
||||
public static T Run<T> (Func<Exception, bool>? errorHandler = null, ConsoleDriver? driver = null)
|
||||
where T : Toplevel, new()
|
||||
{
|
||||
if (!IsInitialized)
|
||||
if (!Initialized)
|
||||
{
|
||||
// Init() has NOT been called.
|
||||
InternalInit (driver, null, true);
|
||||
@@ -383,7 +383,7 @@ public static partial class Application // Run (Begin, Run, End, Stop)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull (view);
|
||||
|
||||
if (IsInitialized)
|
||||
if (Initialized)
|
||||
{
|
||||
if (Driver is null)
|
||||
{
|
||||
|
||||
@@ -196,7 +196,7 @@ public static partial class Application
|
||||
NotifyNewRunState = null;
|
||||
NotifyStopRunState = null;
|
||||
MouseGrabView = null;
|
||||
IsInitialized = false;
|
||||
Initialized = false;
|
||||
|
||||
// Mouse
|
||||
_lastMousePosition = null;
|
||||
|
||||
@@ -4,9 +4,6 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Reflection.Metadata;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using Terminal.Gui;
|
||||
|
||||
namespace UICatalog;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
@@ -16,7 +17,7 @@ namespace UICatalog.Scenarios;
|
||||
[ScenarioCategory ("Drawing")]
|
||||
public class AnimationScenario : Scenario
|
||||
{
|
||||
private ImageView _imageView;
|
||||
private ImageView? _imageView;
|
||||
|
||||
public override void Main ()
|
||||
{
|
||||
@@ -50,11 +51,11 @@ public class AnimationScenario : Scenario
|
||||
Application.Run (win);
|
||||
win.Dispose ();
|
||||
Application.Shutdown ();
|
||||
Debug.Assert (!Application.IsInitialized);
|
||||
Debug.Assert (!Application.Initialized);
|
||||
}
|
||||
|
||||
|
||||
private void OnWinOnInitialized (object sender, EventArgs args)
|
||||
private void OnWinOnInitialized (object? sender, EventArgs args)
|
||||
{
|
||||
DirectoryInfo dir;
|
||||
|
||||
@@ -81,12 +82,12 @@ public class AnimationScenario : Scenario
|
||||
return;
|
||||
}
|
||||
|
||||
_imageView.SetImage (Image.Load<Rgba32> (File.ReadAllBytes (f.FullName)));
|
||||
_imageView!.SetImage (Image.Load<Rgba32> (File.ReadAllBytes (f.FullName)));
|
||||
|
||||
Task.Run (
|
||||
() =>
|
||||
{
|
||||
while (Application.IsInitialized)
|
||||
while (Application.Initialized)
|
||||
{
|
||||
// When updating from a Thread/Task always use Invoke
|
||||
Application.Invoke (
|
||||
|
||||
@@ -131,7 +131,7 @@ public class ApplicationTests
|
||||
Thread.Sleep ((int)timeoutTime / 10);
|
||||
|
||||
// Worst case scenario - something went wrong
|
||||
if (Application.IsInitialized && iteration > 25)
|
||||
if (Application.Initialized && iteration > 25)
|
||||
{
|
||||
_output.WriteLine ($"Too many iterations ({iteration}): Calling Application.RequestStop.");
|
||||
Application.RequestStop ();
|
||||
@@ -279,7 +279,7 @@ public class ApplicationTests
|
||||
// Set some values
|
||||
|
||||
Application.Init (driverName: driverType.Name);
|
||||
Application.IsInitialized = true;
|
||||
// Application.IsInitialized = true;
|
||||
|
||||
// Reset
|
||||
Application.ResetState ();
|
||||
@@ -307,7 +307,7 @@ public class ApplicationTests
|
||||
Assert.Equal (Key.Esc, Application.QuitKey);
|
||||
|
||||
// Internal properties
|
||||
Assert.False (Application.IsInitialized);
|
||||
Assert.False (Application.Initialized);
|
||||
Assert.Equal (Application.GetSupportedCultures (), Application.SupportedCultures);
|
||||
Assert.Equal (Application.GetAvailableCulturesFromEmbeddedResources (), Application.SupportedCultures);
|
||||
Assert.False (Application._forceFakeConsole);
|
||||
@@ -341,7 +341,7 @@ public class ApplicationTests
|
||||
CheckReset ();
|
||||
|
||||
// Set the values that can be set
|
||||
Application.IsInitialized = true;
|
||||
Application.Initialized = true;
|
||||
Application._forceFakeConsole = true;
|
||||
Application.MainThreadId = 1;
|
||||
|
||||
@@ -524,7 +524,7 @@ public class ApplicationTests
|
||||
[AutoInitShutdown (verifyShutdown: true)]
|
||||
public void Internal_Properties_Correct ()
|
||||
{
|
||||
Assert.True (Application.IsInitialized);
|
||||
Assert.True (Application.Initialized);
|
||||
Assert.Null (Application.Top);
|
||||
RunState rs = Application.Begin (new ());
|
||||
Assert.Equal (Application.Top, rs.Toplevel);
|
||||
|
||||
@@ -725,7 +725,7 @@ public class KeyboardTests
|
||||
iteration++;
|
||||
Assert.True (iteration < 2, "Too many iterations, something is wrong.");
|
||||
|
||||
if (Application.IsInitialized)
|
||||
if (Application.Initialized)
|
||||
{
|
||||
_output.WriteLine (" Pressing QuitKey");
|
||||
Application.RaiseKeyDownEvent (Application.QuitKey);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class AutoInitShutdownAttribute : BeforeAfterTestAttribute
|
||||
/// <see cref="ConsoleDriver"/> == <see cref="FakeDriver"/> and <paramref name="autoInit"/> is true.
|
||||
/// </param>
|
||||
/// <param name="configLocation">Determines what config file locations <see cref="ConfigurationManager"/> will load from.</param>
|
||||
/// <param name="verifyShutdown">If true and <see cref="Application.IsInitialized"/> is true, the test will fail.</param>
|
||||
/// <param name="verifyShutdown">If true and <see cref="Application.Initialized"/> is true, the test will fail.</param>
|
||||
public AutoInitShutdownAttribute (
|
||||
bool autoInit = true,
|
||||
Type consoleDriverType = null,
|
||||
|
||||
@@ -128,7 +128,7 @@ public class ScenarioTests : TestsAllViews
|
||||
void OnApplicationOnIteration (object s, IterationEventArgs a)
|
||||
{
|
||||
iterationCount++;
|
||||
if (Application.IsInitialized)
|
||||
if (Application.Initialized)
|
||||
{
|
||||
// Press QuitKey
|
||||
_output.WriteLine ($"Attempting to quit with {Application.QuitKey}");
|
||||
|
||||
Reference in New Issue
Block a user