From 4fc50aae903de8b04ca7534886533640f242f139 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 2 Jul 2020 23:53:32 +0100 Subject: [PATCH 1/3] Allowing multi-thread toplevels. --- Terminal.Gui/Core/Application.cs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/Core/Application.cs b/Terminal.Gui/Core/Application.cs index 4ca0d9907..a54b9bcf4 100644 --- a/Terminal.Gui/Core/Application.cs +++ b/Terminal.Gui/Core/Application.cs @@ -586,16 +586,23 @@ namespace Terminal.Gui { MainLoop.MainIteration (); Iteration?.Invoke (); - } else if (wait == false) + } else if (wait == false) { return; - if (state.Toplevel.NeedDisplay != null && (!state.Toplevel.NeedDisplay.IsEmpty || state.Toplevel.childNeedsDisplay)) { + } + if (state.Toplevel != Top && (!Top.NeedDisplay.IsEmpty || Top.childNeedsDisplay)) { + Top.Redraw (Top.Bounds); + state.Toplevel.SetNeedsDisplay (state.Toplevel.Bounds); + } + if (!state.Toplevel.NeedDisplay.IsEmpty || state.Toplevel.childNeedsDisplay) { state.Toplevel.Redraw (state.Toplevel.Bounds); - if (DebugDrawBounds) + if (DebugDrawBounds) { DrawBounds (state.Toplevel); + } state.Toplevel.PositionCursor (); Driver.Refresh (); - } else + } else { Driver.UpdateCursor (); + } } } From aa51de0bf0fc99af99d8e7634634d908f366b7d4 Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 2 Jul 2020 23:57:50 +0100 Subject: [PATCH 2/3] Improvement the Application.Top in Demo. --- Example/demo.cs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/Example/demo.cs b/Example/demo.cs index a845c9088..87f29b0e1 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -237,12 +237,13 @@ static class Demo { // static void Editor () { - var tframe = Application.Top.Frame; - Application.Top.RemoveAll (); + Application.Init (); + var ntop = Application.Top; + var menu = new MenuBar (new MenuBarItem [] { new MenuBarItem ("_File", new MenuItem [] { - new MenuItem ("_Close", "", () => { if (Quit ()) {Application.RequestStop (); } }), + new MenuItem ("_Close", "", () => { if (Quit ()) { running = MainApp; Application.RequestStop (); } }), }), new MenuBarItem ("_Edit", new MenuItem [] { new MenuItem ("_Copy", "", null), @@ -267,15 +268,13 @@ static class Demo { }; ntop.Add (win); - var text = new TextView (new Rect (0, 0, tframe.Width - 2, tframe.Height - 3)); + var text = new TextView () { X = 0, Y = 0, Width = Dim.Fill (), Height = Dim.Fill () }; if (fname != null) text.Text = System.IO.File.ReadAllText (fname); win.Add (text); Application.Run (ntop, false); - Application.Top.RemoveAll (); - Main (); } static bool Quit () @@ -534,11 +533,19 @@ static class Demo { } #endregion + public static Action running = MainApp; + static void Main () + { + while (running != null) { + running.Invoke (); + } + } + public static Label ml; public static MenuBar menu; public static CheckBox menuKeysStyle; public static CheckBox menuAutoMouseNav; - static void Main () + static void MainApp () { if (Debugger.IsAttached) CultureInfo.DefaultThreadCurrentUICulture = CultureInfo.GetCultureInfo ("en-US"); @@ -578,14 +585,14 @@ static class Demo { menu = new MenuBar (new MenuBarItem [] { new MenuBarItem ("_File", new MenuItem [] { - new MenuItem ("Text _Editor Demo", "", () => { Editor (); }), + new MenuItem ("Text _Editor Demo", "", () => { running = Editor; Application.RequestStop (); }), new MenuItem ("_New", "Creates new file", NewFile), new MenuItem ("_Open", "", Open), new MenuItem ("_Hex", "", () => ShowHex (top)), new MenuItem ("_Close", "", () => Close ()), new MenuItem ("_Disabled", "", () => { }, () => false), null, - new MenuItem ("_Quit", "", () => { if (Quit ()) top.Running = false; }) + new MenuItem ("_Quit", "", () => { if (Quit ()) { running = null; top.Running = false; } }) }), new MenuBarItem ("_Edit", new MenuItem [] { new MenuItem ("_Copy", "", Copy), @@ -648,9 +655,8 @@ static class Demo { new StatusItem(Key.F1, "~F1~ Help", () => Help()), new StatusItem(Key.F2, "~F2~ Load", Load), new StatusItem(Key.F3, "~F3~ Save", Save), - new StatusItem(Key.ControlQ, "~^Q~ Quit", () => { if (Quit ()) top.Running = false; }), - }) { - }; + new StatusItem(Key.ControlQ, "~^Q~ Quit", () => { if (Quit ()) { running = null; top.Running = false; } }) + }); win.Add (drag, dragText); @@ -671,7 +677,7 @@ static class Demo { top.Add (win); //top.Add (menu); top.Add (menu, statusBar); - Application.Run (); + Application.Run (top, false); } private static void Win_KeyPress (View.KeyEventEventArgs e) From 67785f7e7f0ea6595d3ff163bd688edaadc16306 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 3 Jul 2020 01:04:18 +0100 Subject: [PATCH 3/3] Forgot shutdown the driver at exit. --- Example/demo.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Example/demo.cs b/Example/demo.cs index 87f29b0e1..1ce10262c 100644 --- a/Example/demo.cs +++ b/Example/demo.cs @@ -539,6 +539,7 @@ static class Demo { while (running != null) { running.Invoke (); } + Application.Shutdown (); } public static Label ml;