Skip to content

Commit aac40e6

Browse files
committed
Moved header into ListView's Padding.
Refactored the AddHeaders method to be an inline local function within AddListView, improving modularity and encapsulation. Removed the original AddHeaders implementation and its call from the constructor. The new AddHeaders method is conditionally invoked when _applicationData.MinUI is false. Updated the Y positioning of _listView to use _filterErrorView instead of _filterLabel. Adjusted _listView padding and scrollbar position to integrate the header. Changed MARGIN_LEFT constant from 1 to 0 to refine UI layout.
1 parent f8eec62 commit aac40e6

File tree

1 file changed

+42
-28
lines changed

1 file changed

+42
-28
lines changed

src/Microsoft.PowerShell.ConsoleGuiTools/OutGridViewWindow.cs

Lines changed: 42 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace Microsoft.PowerShell.ConsoleGuiTools;
2323
internal sealed class OutGridViewWindow : Window
2424
{
2525
private const string FILTER_LABEL = "_Filter";
26-
private const int MARGIN_LEFT = 1;
26+
private const int MARGIN_LEFT = 0;
2727
private const int CHECK_WIDTH = 2;
2828

2929
private Label? _filterLabel;
@@ -71,7 +71,6 @@ public OutGridViewWindow(ApplicationData applicationData)
7171
if (!_applicationData.MinUI)
7272
{
7373
AddFilter();
74-
AddHeaders();
7574
}
7675

7776
AddListView();
@@ -368,31 +367,6 @@ private void AddFilter()
368367
_filterField.CursorPosition = _filterField.Text.Length;
369368
}
370369

371-
/// <summary>
372-
/// Adds the column header label and separator line to the window.
373-
/// </summary>
374-
private void AddHeaders()
375-
{
376-
_header = new View
377-
{
378-
Y = _applicationData.MinUI ? 0 : Pos.Bottom(_filterErrorView!),
379-
Height = 1,
380-
Width = Dim.Auto(DimAutoStyle.Text)
381-
};
382-
Add(_header);
383-
384-
if (!_applicationData.MinUI)
385-
{
386-
var headerLine = new Line
387-
{
388-
X = MARGIN_LEFT,
389-
Y = Pos.Bottom(_header),
390-
Width = Dim.Fill(MARGIN_LEFT)
391-
};
392-
Add(headerLine);
393-
}
394-
}
395-
396370
/// <summary>
397371
/// Adds the main list view control to the window with configured selection behavior.
398372
/// </summary>
@@ -402,7 +376,7 @@ private void AddListView()
402376
{
403377
Source = _inputSource,
404378
X = MARGIN_LEFT,
405-
Y = !_applicationData.MinUI ? Pos.Bottom(_filterLabel!) + 2 : 1,
379+
Y = !_applicationData.MinUI ? Pos.Bottom(_filterErrorView!) : 1,
406380
Width = Dim.Fill(),
407381
Height = Dim.Fill(1),
408382
AllowsMarking = _applicationData.OutputMode != OutputModeOption.None,
@@ -414,9 +388,49 @@ private void AddListView()
414388

415389
_listView.KeyBindings.Remove(Key.A.WithCtrl);
416390

391+
if (!_applicationData.MinUI)
392+
{
393+
AddHeaders();
394+
}
395+
417396
Add(_listView);
397+
return;
398+
399+
void AddHeaders()
400+
{
401+
_header = new View
402+
{
403+
//Y = _applicationData.MinUI ? 0 : Pos.Bottom(_filterErrorView!),
404+
Height = 1,
405+
Width = Dim.Auto(DimAutoStyle.Text)
406+
};
407+
_header.GettingAttributeForRole += HeaderOnGettingAttributeForRole;
408+
409+
_listView.ViewportChanged += ListViewOnViewportChanged;
410+
411+
_listView.Padding!.Thickness = _listView.Padding.Thickness with { Top = 1 };
412+
_listView!.Padding!.Add(_header);
413+
_listView.VerticalScrollBar.Y = 1;
414+
return;
415+
416+
void ListViewOnViewportChanged(object? sender, DrawEventArgs e)
417+
{
418+
_header.Viewport = _header.Viewport with { X = _listView.Viewport.X };
419+
}
420+
421+
void HeaderOnGettingAttributeForRole(object? sender, VisualRoleEventArgs e)
422+
{
423+
if (e.Role == VisualRole.Normal)
424+
{
425+
e.Result = e.Result!.Value with { Style = TextStyle.Underline };
426+
e.Handled = true;
427+
}
428+
}
429+
}
418430
}
419431

432+
433+
420434
/// <summary>
421435
/// Adds the status bar with keyboard shortcuts to the window.
422436
/// </summary>

0 commit comments

Comments
 (0)