This is a new phenomenon. I pulled the latest version from master today, and it doesn't work any more. Two weeks ago or so it did work.
Scenario:
NETCore 3.1 console app, running on Windows.
Start the console app, do some normal console logging.
Press a hotkey to launch gui.cs application (works, UI is showing).
Press a Quit command (wired up in a StatusBar) which calls Application.RequestStop();
Application.Run(toplevel) returns as expected.
Problem: The UI is still there. Expected and previously working was that I am taken back to the original console view.
Any help is appreciated...
Can you please post some code that illustrates? Thanks.
I think I know what's the problem. First now is needed to call Application.Shutdown but its needed to reset the Init. I will submit a fix as soon it's possible. Thanks
@BDisp very cool that's awesome, I'll test the fix asap and report! The code I am using basically this:
https://github.com/xds-messaging/xds-terminalchat/blob/master/src/XDS.TerminalChat/App.cs
After Application.Run(toplevel); returns (reacting to Application.RequestStop();), the UI is not disappearing.
_mainView.Stop(); is doing nothin UI related and it also does not hang or so.
For now it still hang but I know what is the issue but I am not on pc now.
Done. Don't forget that now is needed to call Application.Shutdown () explicitly after Application.Run (). This is for to allow to create another toplevel while the older one is disposing.
@BDisp hi, thanks, I tested it! I use it like this:
Application.Init();
var topLevel = Application.Top;
// ... add a Window, lots of stuff...
Application.Run(topLevel);
Application.Shutdown(); // maybe add that to the documentation...?
// ...this is now working! Original console is restored :-)
But when I want to enter the UI a second time, just like before:
Application.Init();
var topLevel = Application.Top;
// ... topLevel is now null!
... and what is not working is this:
if(Application.Top == null)
Application.Top = new Toplevel(); // Top has no setter
tldr; exiting works now fine but re-entry not, because Application.Top is null then.
You must have a loop to do that. See this sample.
class Program {
static void Main ()
{
while (true) {
Console.WriteLine ("type anything");
Console.ReadKey ();
ApplicationData applicationData = new ApplicationData () {
Title = "Application-Data",
PassThru = true
};
ConsoleGui consoleGui = new ConsoleGui ();
consoleGui.Start (applicationData);
Console.Clear ();
}
}
public class ApplicationData {
public string Title { get; set; }
public bool PassThru { get; set; }
}
internal class ConsoleGui {
private const string ACCEPT_TEXT = "Are you sure you want to select\nthese items to send down the pipeline?";
private const string CANCEL_TEXT = "Are you sure you want to cancel?\nNothing will be emitted to the pipeline.";
private const string CLOSE_TEXT = "Are you sure you want to close?";
private bool _cancelled;
public void Start (ApplicationData applicationData)
{
Application.Init ();
var top = Application.Top;
// Creates the top-level window to show
var win = new Window (applicationData.Title ?? "Out-ConsoleGridView") {
X = 0,
Y = 1, // Leave one row for the toplevel menu
// By using Dim.Fill(), it will automatically resize without manual intervention
Width = Dim.Fill (),
Height = Dim.Fill ()
};
top.Add (win);
// Creates a menubar, the item "New" has a help menu.
var menu = new MenuBar (new MenuBarItem []
{
new MenuBarItem("_Actions (F9)",
applicationData.PassThru
? new MenuItem []
{
new MenuItem("_Accept", "", () => { if (Quit("Accept", ACCEPT_TEXT)) Application.RequestStop(); }),
new MenuItem("_Cancel", "", () =>{ if (Quit("Cancel", CANCEL_TEXT)) _cancelled = true; Application.RequestStop(); })
}
: new MenuItem []
{
new MenuItem("_Close", "", () =>{ if (Quit("Close", CLOSE_TEXT)) Application.RequestStop(); })
})
});
top.Add (menu);
// add more stuff to win...
Application.Run ();
Application.Shutdown ();
}
}
private static bool Quit (string v, string aCCEPT_TEXT)
{
MessageBox.Query (50, 7, v, aCCEPT_TEXT, "Ok");
return true;
}
}
yes, and the second time the loop calls ConsoleGui.Start(), Application.Top is null :-)
yes, and the second time the loop calls ConsoleGui.Start(), Application.Top is null :-)
No. After call Application.Init the Application.Top is re-created.
@BDisp no, it is not recreated after ShutDown. The bug is in this field:
internal static bool _initialized = false;
If that is true, then no new TopLevel is created.
I guess you need to reset it to false in the ShutDown method.
You haven't not understood what I said. You only use the Application.Shutdown if you really want to completely exit Gui. If you want to create another toplevel you have to use like the Editormethod in the Demo.cs from the Exampleproject.
@BDisp no, it is not recreated after ShutDown. The bug is in this field:
internal static bool _initialized = false;
If that is true, then no new TopLevel is created.
I guess you need to reset it to false in the ShutDown method.
Yes I know that is already fixed in my PR #828. Checkout it and try please.
@BDisp brilliant! I looked at the PR code and that's exactly what I thought! Will test if another surprise comes up but I don't think so!
After merging the PR, you can
That's an amazing feature, because you can flip back and forth between logging and the real gui!