mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 07:47:54 +01:00
Changes before error encountered
Co-authored-by: tig <585482+tig@users.noreply.github.com>
This commit is contained in:
@@ -398,7 +398,11 @@ public static partial class Application // Run (Begin -> Run -> Layout/Draw -> E
|
||||
/// Set to true to cause <see cref="End"/> to be called after the first iteration. Set to false (the default) to
|
||||
/// cause the application to continue running until Application.RequestStop () is called.
|
||||
/// </summary>
|
||||
public static bool EndAfterFirstIteration { get; set; }
|
||||
public static bool EndAfterFirstIteration
|
||||
{
|
||||
get => ApplicationImpl.Instance.EndAfterFirstIteration;
|
||||
set => ApplicationImpl.Instance.EndAfterFirstIteration = value;
|
||||
}
|
||||
|
||||
/// <summary>Building block API: Runs the main loop for the created <see cref="Toplevel"/>.</summary>
|
||||
/// <param name="state">The state returned by the <see cref="Begin(Toplevel)"/> method.</param>
|
||||
|
||||
@@ -23,12 +23,31 @@ public static partial class Application // Screen related stuff; intended to hid
|
||||
/// Event handlers can set <see cref="SizeChangedEventArgs.Cancel"/> to <see langword="true"/> to prevent
|
||||
/// <see cref="Application"/> from changing it's size to match the new terminal size.
|
||||
/// </remarks>
|
||||
public static event EventHandler<SizeChangedEventArgs>? SizeChanging;
|
||||
public static event EventHandler<SizeChangedEventArgs>? SizeChanging
|
||||
{
|
||||
add
|
||||
{
|
||||
if (ApplicationImpl.Instance is ApplicationImpl impl)
|
||||
{
|
||||
impl.SizeChanging += value;
|
||||
}
|
||||
}
|
||||
remove
|
||||
{
|
||||
if (ApplicationImpl.Instance is ApplicationImpl impl)
|
||||
{
|
||||
impl.SizeChanging -= value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Internal helper method for ApplicationImpl.ResetState to clear this event
|
||||
internal static void ClearSizeChangingEvent ()
|
||||
{
|
||||
SizeChanging = null;
|
||||
if (ApplicationImpl.Instance is ApplicationImpl impl)
|
||||
{
|
||||
impl.SizeChanging = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -39,24 +58,7 @@ public static partial class Application // Screen related stuff; intended to hid
|
||||
/// <returns><see lanword="true"/>if the size was changed.</returns>
|
||||
public static bool OnSizeChanging (SizeChangedEventArgs args)
|
||||
{
|
||||
SizeChanging?.Invoke (null, args);
|
||||
|
||||
if (args.Cancel || args.Size is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Screen = new (Point.Empty, args.Size.Value);
|
||||
|
||||
foreach (Toplevel t in TopLevels)
|
||||
{
|
||||
t.OnSizeChanging (new (args.Size));
|
||||
t.SetNeedsLayout ();
|
||||
}
|
||||
|
||||
LayoutAndDraw (true);
|
||||
|
||||
return true;
|
||||
return ApplicationImpl.Instance.OnSizeChanging (args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -128,6 +128,9 @@ public class ApplicationImpl : IApplication
|
||||
/// <inheritdoc/>
|
||||
public bool ClearScreenNextIteration { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool EndAfterFirstIteration { get; set; }
|
||||
|
||||
/// <inheritdoc/>
|
||||
public ApplicationPopover? Popover { get; set; }
|
||||
|
||||
@@ -157,6 +160,11 @@ public class ApplicationImpl : IApplication
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This event is raised when the application's size changes.
|
||||
/// </summary>
|
||||
public event EventHandler<SizeChangedEventArgs>? SizeChanging;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void RequestStop () { RequestStop (null); }
|
||||
|
||||
@@ -421,6 +429,29 @@ public class ApplicationImpl : IApplication
|
||||
_driver?.Refresh ();
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public bool OnSizeChanging (SizeChangedEventArgs args)
|
||||
{
|
||||
SizeChanging?.Invoke (null, args);
|
||||
|
||||
if (args.Cancel || args.Size is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Screen = new (Point.Empty, args.Size.Value);
|
||||
|
||||
foreach (Toplevel t in TopLevels)
|
||||
{
|
||||
t.OnSizeChanging (new (args.Size));
|
||||
t.SetNeedsLayout ();
|
||||
}
|
||||
|
||||
LayoutAndDraw (true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public void ResetState (bool ignoreDisposed = false)
|
||||
{
|
||||
@@ -463,9 +494,9 @@ public class ApplicationImpl : IApplication
|
||||
|
||||
MainThreadId = -1;
|
||||
|
||||
// These static properties need to be reset
|
||||
Application.EndAfterFirstIteration = false;
|
||||
Application.ClearScreenNextIteration = false;
|
||||
// Reset iteration flags
|
||||
EndAfterFirstIteration = false;
|
||||
ClearScreenNextIteration = false;
|
||||
|
||||
// Driver stuff
|
||||
if (_driver is { })
|
||||
@@ -488,12 +519,12 @@ public class ApplicationImpl : IApplication
|
||||
// Do not clear _lastMousePosition; Popovers require it to stay set with
|
||||
// last mouse pos.
|
||||
//_lastMousePosition = null;
|
||||
Application.CachedViewsUnderMouse.Clear ();
|
||||
Application.ResetMouseState ();
|
||||
Mouse.CachedViewsUnderMouse.Clear ();
|
||||
Mouse.ResetState ();
|
||||
|
||||
// Keyboard events and bindings are now managed by the Keyboard instance
|
||||
|
||||
Application.ClearSizeChangingEvent ();
|
||||
SizeChanging = null;
|
||||
|
||||
Navigation = null;
|
||||
|
||||
@@ -623,11 +654,11 @@ public class ApplicationImpl : IApplication
|
||||
return new MainLoopCoordinator<T> (_timedEvents, inputBuffer, loop, cf);
|
||||
}
|
||||
|
||||
private void Driver_KeyDown (object? sender, Key e) { Application.RaiseKeyDownEvent (e); }
|
||||
private void Driver_KeyUp (object? sender, Key e) { Application.RaiseKeyUpEvent (e); }
|
||||
private void Driver_MouseEvent (object? sender, MouseEventArgs e) { Application.RaiseMouseEvent (e); }
|
||||
private void Driver_KeyDown (object? sender, Key e) { Keyboard.RaiseKeyDownEvent (e); }
|
||||
private void Driver_KeyUp (object? sender, Key e) { Keyboard.RaiseKeyUpEvent (e); }
|
||||
private void Driver_MouseEvent (object? sender, MouseEventArgs e) { Mouse.RaiseMouseEvent (e); }
|
||||
|
||||
private void Driver_SizeChanged (object? sender, SizeChangedEventArgs e) { Application.OnSizeChanging (e); }
|
||||
private void Driver_SizeChanged (object? sender, SizeChangedEventArgs e) { OnSizeChanging (e); }
|
||||
|
||||
private static List<CultureInfo> GetAvailableCulturesFromEmbeddedResources ()
|
||||
{
|
||||
|
||||
@@ -27,6 +27,14 @@ public interface IApplication
|
||||
/// <summary>Gets or sets the console driver being used.</summary>
|
||||
IConsoleDriver? Driver { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This is intended for unit tests and won't stop the <see cref="Application.RunLoop"/> if set to <see langword="true"/>
|
||||
/// If the caller calls <see cref="Application.RunLoop"/> with the returned token from <see cref="Application.Begin"/>, setting
|
||||
/// this property to <see langword="true"/> will cause only one iteration of the main loop to execute. The default is
|
||||
/// <see langword="false"/>, which will cause the application to continue running until Application.RequestStop () is called.
|
||||
/// </summary>
|
||||
bool EndAfterFirstIteration { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets whether <see cref="Driver"/> will be forced to output only the 16 colors defined in
|
||||
/// <see cref="ColorName16"/>. The default is <see langword="false"/>, meaning 24-bit (TrueColor) colors will be output
|
||||
@@ -101,6 +109,14 @@ public interface IApplication
|
||||
/// </param>
|
||||
public void LayoutAndDraw (bool forceRedraw = false);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the application's size changes. Sets the size of all <see cref="Toplevel"/>s and fires the
|
||||
/// SizeChanging event.
|
||||
/// </summary>
|
||||
/// <param name="args">The new size.</param>
|
||||
/// <returns><see langword="true"/> if the size was changed.</returns>
|
||||
bool OnSizeChanging (SizeChangedEventArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// Maximum number of iterations of the main loop (and hence draws)
|
||||
/// to allow to occur per second. Defaults to <see cref="Application.DEFAULT_MAXIMUM_ITERATIONS_PER_SECOND"/> which is
|
||||
|
||||
Reference in New Issue
Block a user