Skip to content

Commit

Permalink
Merge branch 'develop' into v1_showcase
Browse files Browse the repository at this point in the history
  • Loading branch information
tig authored Sep 29, 2023
2 parents 7a0e0d7 + 2b47162 commit fc9ddc2
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 14 deletions.
1 change: 1 addition & 0 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/CursesDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public override void Refresh ()
Curses.raw ();
Curses.noecho ();
Curses.refresh ();
ProcessWinChange ();
}

private void ProcessWinChange ()
Expand Down
17 changes: 14 additions & 3 deletions Terminal.Gui/ConsoleDrivers/CursesDriver/UnixMainLoop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 [1], ignore, (IntPtr)1);
return true;
});
}
Expand Down Expand Up @@ -176,6 +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 < 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
Expand Down
34 changes: 24 additions & 10 deletions Terminal.Gui/Views/ComboBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// Ross Ferguson ([email protected])
//

using NStack;
using System;
using System.Collections;
using System.Collections.Generic;
using NStack;

namespace Terminal.Gui {
/// <summary>
Expand Down Expand Up @@ -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 (nameof(container), "ComboBox container cannot be null.");
HideDropdownListOnClick = hideDropdownListOnClick;
}

Expand Down Expand Up @@ -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;

/// <summary>
/// Public constructor
Expand Down Expand Up @@ -721,7 +718,19 @@ public virtual bool Expand ()
return text;
}
set {
search.Text = text = value;
SetSearchText (value);
}
}

/// <summary>
/// Current search text
/// </summary>
public ustring SearchText {
get {
return search.Text;
}
set {
SetSearchText (value);
}
}

Expand Down Expand Up @@ -775,7 +784,7 @@ private int GetSelectedItemFromSource (ustring value)
private void Reset (bool keepSearchText = false)
{
if (!keepSearchText) {
search.Text = text = "";
SetSearchText (string.Empty);
}

ResetSearchSet ();
Expand All @@ -788,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 ();
Expand Down Expand Up @@ -843,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);
}

/// <summary>
Expand All @@ -857,7 +871,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);
Expand Down
2 changes: 1 addition & 1 deletion UICatalog/Scenarios/Threading.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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!");
}
Expand Down

0 comments on commit fc9ddc2

Please sign in to comment.