Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes for the WebConsole support. #1865

Merged
merged 3 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions Terminal.Gui/Core/Application.cs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,8 @@ static void ResetState ()
RootMouseEvent = null;
RootKeyEvent = null;
Resized = null;
NotifyNewRunState = null;
NotifyStopRunState = null;
_initialized = false;
mouseGrabView = null;

Expand Down Expand Up @@ -1202,7 +1204,9 @@ public static void RequestStop (Toplevel top = null)
return;
}
Current.Running = false;
OnNotifyStopRunState (Current);
top.Running = false;
OnNotifyStopRunState (top);
} else if ((MdiTop != null && top != MdiTop && top != Current && Current?.Modal == false
&& Current?.Running == true && !top.Running)
|| (MdiTop != null && top != MdiTop && top != Current && Current?.Modal == false
Expand All @@ -1213,11 +1217,13 @@ public static void RequestStop (Toplevel top = null)
&& Current?.Modal == true && top.Modal) {
// The Current and the top are both modal so needed to set the Current.Running to false too.
Current.Running = false;
OnNotifyStopRunState (Current);
} else if (MdiTop != null && Current == top && MdiTop?.Running == true && Current?.Running == true && top.Running
&& Current?.Modal == true && top.Modal) {
// The MdiTop was requested to stop inside a modal toplevel which is the Current and top,
// both are the same, so needed to set the Current.Running to false too.
Current.Running = false;
OnNotifyStopRunState (Current);
} else {
Toplevel currentTop;
if (top == Current || (Current?.Modal == true && !top.Modal)) {
Expand All @@ -1234,11 +1240,16 @@ public static void RequestStop (Toplevel top = null)
return;
}
currentTop.Running = false;
if (ExitRunLoopAfterFirstIteration)
NotifyStopRunState?.Invoke (currentTop);
OnNotifyStopRunState (currentTop);
}
}

static void OnNotifyStopRunState (Toplevel top)
{
if (ExitRunLoopAfterFirstIteration)
NotifyStopRunState?.Invoke (top);
}

/// <summary>
/// Event arguments for the <see cref="Application.Resized"/> event.
/// </summary>
Expand Down
12 changes: 9 additions & 3 deletions Terminal.Gui/Windows/MessageBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,12 @@ static int QueryFull (bool useErrorColors, int width, int height, ustring title,
d.Width = msgboxWidth;

// Setup actions
int clicked = -1;
Clicked = -1;
for (int n = 0; n < buttonList.Count; n++) {
int buttonId = n;
var b = buttonList [n];
b.Clicked += () => {
clicked = buttonId;
Clicked = buttonId;
Application.RequestStop ();
};
if (b.IsDefault) {
Expand All @@ -307,7 +307,13 @@ static int QueryFull (bool useErrorColors, int width, int height, ustring title,

// Run the modal; do not shutdown the mainloop driver when done
Application.Run (d);
return clicked;
return Clicked;
}

/// <summary>
/// The index of the selected button, or -1 if the user pressed ESC to close the dialog.
/// This is useful for web based console where by default there is no SynchronizationContext or TaskScheduler.
/// </summary>
public static int Clicked { get; private set; } = -1;
}
}
2 changes: 1 addition & 1 deletion UICatalog/Scenarios/BackgroundWorkerCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public void CancelWorker ()
public void WriteLog (string msg)
{
log.Add (msg);
listLog.MoveEnd ();
listLog.MoveDown ();
}
}

Expand Down