From 7157e36712e79b9aeea9eb5c3ebb5b14d4c341e0 Mon Sep 17 00:00:00 2001 From: Maciej Winnik Date: Sat, 19 Aug 2023 12:50:03 +0200 Subject: [PATCH 1/9] Add SearchText field --- Terminal.Gui/Views/ComboBox.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 4fb87d7e5b..dfc625f636 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -5,10 +5,10 @@ // Ross Ferguson (ross.c.ferguson@btinternet.com) // +using NStack; using System; using System.Collections; using System.Collections.Generic; -using NStack; namespace Terminal.Gui { /// @@ -725,6 +725,18 @@ public virtual bool Expand () } } + /// + /// Current search text + /// + public ustring SearchText { + get { + return search.Text; + } + set { + search.Text = text = value; + } + } + private void SetValue (object text, bool isFromSelectedItem = false) { search.TextChanged -= Search_Changed; From c542b811351c65fd095eec6eeeeb11dac159185f Mon Sep 17 00:00:00 2001 From: Maciej Winnik Date: Sat, 19 Aug 2023 13:08:22 +0200 Subject: [PATCH 2/9] Prevent reseting text search --- Terminal.Gui/Views/ComboBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index dfc625f636..896af0dbb8 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -869,7 +869,7 @@ private void HideList () OnOpenSelectedItem (); } var rect = listview.ViewToScreen (listview.Bounds); - Reset (SelectedItem > -1); + Reset (keepSearchText: true); listview.Clear (rect); listview.TabStop = false; SuperView?.SendSubviewToBack (this); From 78e2fc01c9fac6c607806929b098a8ed8569ab90 Mon Sep 17 00:00:00 2001 From: Maciej Winnik Date: Sat, 19 Aug 2023 13:13:29 +0200 Subject: [PATCH 3/9] Code cleanup --- Terminal.Gui/Views/ComboBox.cs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 896af0dbb8..08225e05ed 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -39,10 +39,7 @@ public ComboListView (ComboBox container, IList source, bool hideDropdownListOnC private void Initialize (ComboBox container, bool hideDropdownListOnClick) { - if (container == null) - throw new ArgumentNullException ("ComboBox container cannot be null.", nameof (container)); - - this.container = container; + this.container = container ?? throw new ArgumentNullException ("ComboBox container cannot be null.", nameof (container)); HideDropdownListOnClick = hideDropdownListOnClick; } @@ -236,7 +233,7 @@ public void SetSource (IList source) readonly TextField search; readonly ComboListView listview; bool autoHide = true; - int minimumHeight = 2; + readonly int minimumHeight = 2; /// /// Public constructor @@ -721,7 +718,7 @@ public virtual bool Expand () return text; } set { - search.Text = text = value; + SetSearchText (value); } } @@ -733,7 +730,7 @@ public ustring SearchText { return search.Text; } set { - search.Text = text = value; + SetSearchText (value); } } @@ -787,7 +784,7 @@ private int GetSelectedItemFromSource (ustring value) private void Reset (bool keepSearchText = false) { if (!keepSearchText) { - search.Text = text = ""; + SetSearchText (string.Empty); } ResetSearchSet (); @@ -800,6 +797,11 @@ private void Reset (bool keepSearchText = false) } } + private void SetSearchText (ustring value) + { + search.Text = text = value; + } + private void ResetSearchSet (bool noCopy = false) { searchset.Clear (); @@ -855,7 +857,7 @@ private void ShowList () listview.SetSource (searchset); listview.Clear (); // Ensure list shrinks in Dialog as you type listview.Height = CalculatetHeight (); - this.SuperView?.BringSubviewToFront (this); + SuperView?.BringSubviewToFront (this); } /// From cc88e33ffe99448bb99968861144443643c287d4 Mon Sep 17 00:00:00 2001 From: maciekwin3 Date: Wed, 30 Aug 2023 19:59:14 +0200 Subject: [PATCH 4/9] Fix order of parameters --- Terminal.Gui/Views/ComboBox.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/Views/ComboBox.cs b/Terminal.Gui/Views/ComboBox.cs index 08225e05ed..0483d82e78 100644 --- a/Terminal.Gui/Views/ComboBox.cs +++ b/Terminal.Gui/Views/ComboBox.cs @@ -39,7 +39,7 @@ public ComboListView (ComboBox container, IList source, bool hideDropdownListOnC private void Initialize (ComboBox container, bool hideDropdownListOnClick) { - this.container = container ?? throw new ArgumentNullException ("ComboBox container cannot be null.", nameof (container)); + this.container = container ?? throw new ArgumentNullException (nameof(container), "ComboBox container cannot be null."); HideDropdownListOnClick = hideDropdownListOnClick; } From a45d65bbdd4514b2434b58ab868fd300b25c320a Mon Sep 17 00:00:00 2001 From: BDisp Date: Thu, 31 Aug 2023 19:03:05 +0100 Subject: [PATCH 5/9] Fixes #2847. CursesDriver doesn't processing response from task threading. --- Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs | 5 ++--- UICatalog/Scenarios/Threading.cs | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index f0c7cb9df9..df53595428 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -82,7 +82,6 @@ class Watch { bool poll_dirty = true; int [] wakeupPipes = new int [2]; static IntPtr ignore = Marshal.AllocHGlobal (1); - static IntPtr readHandle = Marshal.AllocHGlobal (1); MainLoop mainLoop; bool winChanged; @@ -97,8 +96,8 @@ void IMainLoopDriver.Setup (MainLoop mainLoop) { this.mainLoop = mainLoop; pipe (wakeupPipes); - AddWatch (wakeupPipes [1], Condition.PollIn, ml => { - read (wakeupPipes [1], ignore, readHandle); + AddWatch (wakeupPipes [0], Condition.PollIn, ml => { + read (wakeupPipes [0], ignore, (IntPtr)1); return true; }); } diff --git a/UICatalog/Scenarios/Threading.cs b/UICatalog/Scenarios/Threading.cs index 6bd159497e..fe2c15f42d 100644 --- a/UICatalog/Scenarios/Threading.cs +++ b/UICatalog/Scenarios/Threading.cs @@ -157,7 +157,7 @@ private async void CallLoadItemsAsync () LogJob ($"Returned from task Thread:{Thread.CurrentThread.ManagedThreadId} {DateTime.Now}"); _itemsList.SetSource (items); LogJob ($"Finished populate list view Thread:{Thread.CurrentThread.ManagedThreadId} {DateTime.Now}"); - _btnActionCancel.Text = "Load Items"; + _btnActionCancel.Text = "Cancelable Load Items"; } else { LogJob ("Task was canceled!"); } From c90366a03d986d786eaa09c107bb0da466838958 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 22 Sep 2023 14:00:09 +0100 Subject: [PATCH 6/9] Fixes #2860. Application views do not refresh when the cursor is moved with CursesDriver. --- Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index df53595428..3736990719 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -175,6 +175,10 @@ bool CheckTimers (bool wait, out int pollTimeout) if (mainLoop.timeouts.Count > 0) { pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond); if (pollTimeout < 0) { + // This avoids poll waiting infinitely if pollTimeout=-1 until some action is detected + if (pollTimeout == -1) { + pollTimeout = 0; + } return true; } } else From 1262d236e55b26ca5a32b6daf404f24c84d70f70 Mon Sep 17 00:00:00 2001 From: BDisp Date: Fri, 22 Sep 2023 20:08:46 +0100 Subject: [PATCH 7/9] The pollTimeout must be set to zero if less than zero. --- .../ConsoleDrivers/CursesDriver/UnixMainLoop.cs | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index 3736990719..7ffa43eea7 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -175,10 +175,18 @@ bool CheckTimers (bool wait, out int pollTimeout) if (mainLoop.timeouts.Count > 0) { pollTimeout = (int)((mainLoop.timeouts.Keys [0] - now) / TimeSpan.TicksPerMillisecond); if (pollTimeout < 0) { - // This avoids poll waiting infinitely if pollTimeout=-1 until some action is detected - if (pollTimeout == -1) { - pollTimeout = 0; - } + // This avoids 'poll' waiting infinitely if 'pollTimeout < 0' until some action is detected + // This can occur after IMainLoopDriver.Wakeup is executed where the pollTimeout is less than 0 + // and no event occurred in elapsed time when the 'poll' is start running again. + /* + The 'poll' function in the C standard library uses a signed integer as the timeout argument, where: + + - A positive value specifies a timeout in milliseconds. + - A value of 0 means the poll function will return immediately, checking for events and not waiting. + - A value of -1 means the poll function will wait indefinitely until an event occurs or an error occurs. + - A negative value other than -1 typically indicates an error. + */ + pollTimeout = 0; return true; } } else From e86687ee0baeb27dd3791fd4f06956bd47ef1ed1 Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 23 Sep 2023 21:38:45 +0100 Subject: [PATCH 8/9] Ensures always resizing if needed on macOS. --- Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs index 986a1b0120..8a9f0d2a6b 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs @@ -142,6 +142,7 @@ public override void Refresh () Curses.raw (); Curses.noecho (); Curses.refresh (); + ProcessWinChange (); } private void ProcessWinChange () From 8a779505b3d6ecd88fc3280b1d883ad8a433f33b Mon Sep 17 00:00:00 2001 From: BDisp Date: Sat, 23 Sep 2023 21:44:51 +0100 Subject: [PATCH 9/9] Fixes freezing on resizing when read function is executed and many Wakeup calls are done. --- Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs index 7ffa43eea7..3e23b78a56 100644 --- a/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs +++ b/Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs @@ -97,7 +97,7 @@ void IMainLoopDriver.Setup (MainLoop mainLoop) this.mainLoop = mainLoop; pipe (wakeupPipes); AddWatch (wakeupPipes [0], Condition.PollIn, ml => { - read (wakeupPipes [0], ignore, (IntPtr)1); + read (wakeupPipes [1], ignore, (IntPtr)1); return true; }); }