Skip to content

Commit c705b63

Browse files
committed
Sort entries in BigListBox alphabetically by default
1 parent 50323c6 commit c705b63

File tree

4 files changed

+15
-35
lines changed

4 files changed

+15
-35
lines changed

src/UI/ValueFactory.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ private static bool GetNewColorSchemeValue(Design design, out object? newValue)
305305
// add the option to jump to custom colors
306306
offer.Add(custom);
307307

308-
if (Modals.Get("Color Scheme", "Ok", offer.ToArray(), design.View.ColorScheme, out var selected))
308+
if (Modals.Get("Color Scheme", "Ok", offer.ToArray(), design.View.ColorScheme, out var selected,false))
309309
{
310310
// if user clicked "Custom..."
311311
if (selected is string s && string.Equals(s, custom))

src/UI/Windows/BigListBox.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,23 @@ public class BigListBox<T>
4747
/// <param name="displayMember">What to display in the list box (defaults to <see cref="object.ToString"/>.</param>
4848
/// <param name="addNull">Creates a selection option "Null" that returns a null selection.</param>
4949
/// <param name="currentSelection">The optional existing value, if present it should be selected in the list.</param>
50-
public BigListBox(
51-
string prompt,
50+
/// <param name="sort"></param>
51+
public BigListBox(string prompt,
5252
string okText,
5353
in bool addSearch,
5454
IList<T> collection,
5555
Func<T?, string> displayMember,
5656
bool addNull,
57-
T? currentSelection)
57+
T? currentSelection, bool sort = true)
5858
{
5959
this.AspectGetter = displayMember ?? (arg => arg?.ToString() ?? string.Empty);
6060

61+
// Sort alphabetically according to display member
62+
if (sort)
63+
{
64+
collection = collection.OrderBy(e => AspectGetter(e)).ToList();
65+
}
66+
6167
this.publicCollection = collection ?? throw new ArgumentNullException( nameof( collection ) );
6268
this.addNull = addNull;
6369

src/UI/Windows/ChoicesDialog.cs

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -94,34 +94,8 @@ public ChoicesDialog(string title, string message, params string[] options) {
9494

9595
Width = Math.Min(Math.Max(maxWidthLine, Math.Max(Title.GetColumns(), Math.Max(textWidth + 2, buttonWidth))), Application.Driver.Cols);
9696
Height = msgboxHeight;
97-
}
98-
99-
/// <inheritdoc/>
100-
protected override void OnDrawComplete()
101-
{
102-
base.OnDrawComplete();
103-
104-
var screenTopLeft = FrameToScreen();
105-
Driver.Move(screenTopLeft.X+2, screenTopLeft.Y);
106-
107-
var padding = ((Viewport.Width - _title.EnumerateRunes().Sum(v=>v.GetColumns())) / 2) - 1;
108-
109-
Driver.SetAttribute(
110-
new Attribute(ColorScheme.Normal.Foreground, ColorScheme.Normal.Background));
111-
112-
Driver.AddStr(string.Join("",Enumerable.Repeat(Glyphs.HLineHv, padding)));
113-
114-
Driver.SetAttribute(
115-
new Attribute(ColorScheme.Normal.Background, ColorScheme.Normal.Foreground));
116-
Driver.AddStr(_title);
117-
118-
Driver.SetAttribute(
119-
new Attribute(ColorScheme.Normal.Foreground, ColorScheme.Normal.Background));
120-
121-
StringBuilder sb = new StringBuilder();
122-
sb.Append(Glyphs.HLineHv);
12397

124-
Driver.AddStr(string.Join("", Enumerable.Repeat(Glyphs.HLineHv.ToString(), padding)));
98+
btn1.FocusDeepest(NavigationDirection.Forward, TabBehavior.TabGroup);
12599
}
126100

127101
internal static int Query(string title, string message, params string[] options)

src/UI/Windows/Modals.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,14 +136,14 @@ internal static bool GetString(string windowTitle, string entryLabel, string? in
136136
return false;
137137
}
138138

139-
internal static bool Get<T>(string prompt, string okText, T[] collection, T? currentSelection, out T? selected)
139+
internal static bool Get<T>(string prompt, string okText, T[] collection, T? currentSelection, out T? selected, bool sort = true)
140140
{
141-
return Get(prompt, okText, true, collection, o => o is Type t ? t.Name : o?.ToString() ?? "Null", false, currentSelection, out selected);
141+
return Get(prompt, okText, true, collection, o => o is Type t ? t.Name : o?.ToString() ?? "Null", false, currentSelection, out selected,sort);
142142
}
143143

144-
internal static bool Get<T>( string prompt, string okText, in bool addSearch, T[] collection, Func<T?, string> displayMember, bool addNull, [NotNullWhen( true )]T? currentSelection, [NotNullWhen( true )] out T? selected )
144+
internal static bool Get<T>( string prompt, string okText, in bool addSearch, T[] collection, Func<T?, string> displayMember, bool addNull, [NotNullWhen( true )]T? currentSelection, [NotNullWhen( true )] out T? selected, bool sort=true )
145145
{
146-
var pick = new BigListBox<T>( prompt, okText, in addSearch, collection, displayMember, addNull, currentSelection );
146+
var pick = new BigListBox<T>( prompt, okText, in addSearch, collection, displayMember, addNull, currentSelection,sort );
147147
bool toReturn = pick.ShowDialog( );
148148
selected = pick.Selected;
149149
return toReturn;

0 commit comments

Comments
 (0)