Skip to content

Commit 627ae55

Browse files
committed
Tons of fixes. Code cleanup. 99% working.
1 parent 55f693f commit 627ae55

8 files changed

Lines changed: 111 additions & 177 deletions

File tree

Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<PackageVersion Include="Microsoft.PowerShell.SDK" Version="7.4.7" />
44
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
55
<PackageVersion Include="System.Management.Automation" Version="7.4.7" />
6-
<PackageVersion Include="Terminal.Gui" Version="2.0.0-alpha.3390" />
6+
<!--<PackageVersion Include="Terminal.Gui" Version="2.0.0-develop.4947" />-->
77
</ItemGroup>
88
</Project>

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewDataSource.cs

Lines changed: 27 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections;
66
using System.Collections.Generic;
77
using System.Collections.Specialized;
8+
using System.Linq;
89
using Terminal.Gui.App;
910
using Terminal.Gui.Views;
1011

@@ -20,25 +21,17 @@ internal sealed class GridViewDataSource : IListDataSource
2021
/// </summary>
2122
public List<GridViewRow> GridViewRowList { get; set; }
2223

23-
/// <summary>
24-
/// Gets the number of rows in the data source.
25-
/// </summary>
24+
/// <inheritdoc/>
2625
public int Count => GridViewRowList.Count;
2726

28-
/// <summary>
29-
/// Gets the number of rows in the data source.
30-
/// </summary>
31-
public int Length => GridViewRowList.Count;
27+
/// <inheritdoc/>
28+
public int MaxItemLength { get; set; }
3229

33-
/// <summary>
34-
/// Gets or sets a value indicating whether to suspend raising the <see cref="CollectionChanged" /> event.
35-
/// </summary>
30+
/// <inheritdoc/>
3631
public bool SuspendCollectionChangedEvent { get; set; }
3732

3833
#pragma warning disable CS0067
39-
/// <summary>
40-
/// Occurs when the collection changes.
41-
/// </summary>
34+
/// <inheritdoc/>
4235
public event NotifyCollectionChangedEventHandler? CollectionChanged;
4336
#pragma warning restore CS0067
4437

@@ -51,24 +44,21 @@ public GridViewDataSource(List<GridViewRow> itemList)
5144
GridViewRowList = itemList;
5245
}
5346

54-
/// <summary>
55-
/// Renders a specific item in the list view at the specified position.
56-
/// </summary>
57-
/// <param name="listView">The list view to render into.</param>
58-
/// <param name="selected">A value indicating whether the item is selected.</param>
59-
/// <param name="item">The index of the item to render.</param>
60-
/// <param name="col">The column position to start rendering.</param>
61-
/// <param name="line">The line position to render on.</param>
62-
/// <param name="width">The width available for rendering.</param>
63-
/// <param name="start">The starting position within the item's display string.</param>
64-
public void Render(ListView listView, bool selected, int item, int col, int line, int width, int start = 0)
47+
/// <inheritdoc/>
48+
public void Render(ListView listView, bool selected, int item, int col, int line, int width, int viewportX)
6549
{
66-
listView.Move(col - start, line);
50+
GridViewRow? row = GridViewRowList[item];
51+
string displayString = row?.DisplayString ?? string.Empty;
6752

68-
var driver = listView.App?.Driver;
69-
var row = GridViewRowList[item];
70-
string displayString = row.DisplayString ?? string.Empty;
71-
// Pad right of display string with spaces to fill width
53+
displayString = viewportX switch
54+
{
55+
// Truncate the start of the string to skip characters scrolled out of view
56+
> 0 when displayString.Length > viewportX => displayString[viewportX..],
57+
> 0 when displayString.Length <= viewportX => string.Empty,
58+
_ => displayString
59+
};
60+
61+
// Pad right of display string with spaces to fill width, or truncate if too long
7262
if (displayString.Length < width)
7363
{
7464
displayString = displayString.PadRight(width);
@@ -77,21 +67,17 @@ public void Render(ListView listView, bool selected, int item, int col, int line
7767
{
7868
displayString = displayString[..width];
7969
}
80-
driver!.AddStr(displayString);
70+
71+
listView.AddStr(displayString);
8172
}
8273

83-
/// <summary>
84-
/// Determines whether the specified item is marked.
85-
/// </summary>
86-
/// <param name="item">The index of the item to check.</param>
87-
/// <returns><see langword="true" /> if the item is marked; otherwise, <see langword="false" />.</returns>
88-
public bool IsMarked(int item) => GridViewRowList[item].IsMarked;
74+
/// <inheritdoc/>
75+
public bool IsMarked(int item)
76+
{
77+
return item < GridViewRowList.Count && GridViewRowList[item].IsMarked;
78+
}
8979

90-
/// <summary>
91-
/// Sets the marked state of the specified item and raises the <see cref="MarkChanged" /> event.
92-
/// </summary>
93-
/// <param name="item">The index of the item to mark or unmark.</param>
94-
/// <param name="value"><see langword="true" /> to mark the item; <see langword="false" /> to unmark it.</param>
80+
/// <inheritdoc/>
9581
public void SetMark(int item, bool value)
9682
{
9783
var oldValue = GridViewRowList[item].IsMarked;

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewDetails.cs

Lines changed: 0 additions & 26 deletions
This file was deleted.

src/Microsoft.PowerShell.ConsoleGuiTools/Header.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,15 @@
22
// Licensed under the MIT License.
33

44
using System.Collections.Generic;
5-
using System.Reflection;
6-
using System.Reflection.PortableExecutable;
75
using Terminal.Gui.Drawing;
86
using Terminal.Gui.ViewBase;
97
using Terminal.Gui.Views;
108

119
namespace Microsoft.PowerShell.ConsoleGuiTools;
1210

1311
/// <summary>
14-
/// A specialized view for displaying grid column headers with individual subviews for each column.
12+
/// A specialized view for displaying grid column headers with individual subviews for each column. This is added to
13+
/// the top of the Padding of the ListView.
1514
/// </summary>
1615
internal sealed class Header : View
1716
{
@@ -28,21 +27,20 @@ public override void EndInit()
2827

2928

3029
// We are a subview of the ListView.Padding.
31-
if (SuperView is Padding padding)
32-
{
33-
padding.Parent?.ViewportChanged += ListViewOnViewportChanged;
34-
}
30+
if (SuperView is Padding padding) padding.Parent?.ViewportChanged += ListViewOnViewportChanged;
31+
32+
return;
3533

3634
void ListViewOnViewportChanged(object? sender, DrawEventArgs e)
3735
{
38-
if (sender is ListView listView)
36+
if (sender is ListView listView)
3937
Viewport = Viewport with { X = listView.Viewport.X };
4038
}
4139
}
4240

4341
protected override void OnSubViewLayout(LayoutEventArgs args)
4442
{
45-
if (SuperView is Padding { Parent: ListView listView })
43+
if (SuperView is Padding { Parent: ListView listView })
4644
SetContentSize(GetContentSize() with { Width = listView.GetContentSize().Width });
4745

4846
base.OnSubViewLayout(args);
Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,43 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<Import Project="..\..\ConsoleGuiTools.Common.props" />
3-
<PropertyGroup>
4-
<TargetFramework>net10.0</TargetFramework>
5-
<LangVersion>preview</LangVersion>
6-
<Nullable>enable</Nullable>
7-
</PropertyGroup>
2+
<Import Project="..\..\ConsoleGuiTools.Common.props" />
3+
<PropertyGroup>
4+
<TargetFramework>net10.0</TargetFramework>
5+
<LangVersion>preview</LangVersion>
6+
<Nullable>enable</Nullable>
7+
</PropertyGroup>
88

9-
<PropertyGroup>
10-
<!-- To pull Terminal.Gui from a local nuget source:
9+
<PropertyGroup>
10+
<!-- To pull Terminal.Gui from a local nuget source:
1111
- Build Terminal.Gui locally in ../../gui-cs/Terminal.Gui
1212
- Change Terminal.Gui Version= to "major.minor.patch-*"
1313
- Add ';https://api.nuget.org/v3/index.json' to the end of the RestoreSources property group below
1414
- Uncomment the RestoreSources property group below
1515
-->
16-
<!--<RestoreSources>https://api.nuget.org/v3/index.json;$(RestoreSources);../../../gui-cs/Terminal.Gui/Terminal.Gui/bin/Debug</RestoreSources>-->
17-
</PropertyGroup>
16+
<!--<RestoreSources>https://api.nuget.org/v3/index.json;$(RestoreSources);../../../gui-cs/Terminal.Gui/Terminal.Gui/bin/Debug</RestoreSources>-->
17+
</PropertyGroup>
1818

19-
<ItemGroup>
20-
<!-- Using local Terminal.Gui build for debugging -->
21-
<!--<ProjectReference Include="..\..\..\gui-cs\Terminal.Gui\Terminal.Gui\Terminal.Gui.csproj" />-->
22-
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.4" />
23-
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4827" />
24-
</ItemGroup>
19+
<ItemGroup>
20+
<!-- Using local Terminal.Gui build for debugging -->
21+
<!--<ProjectReference Include="..\..\..\gui-cs\Terminal.Gui\Terminal.Gui\Terminal.Gui.csproj" />-->
22+
<!--<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.4" />-->
23+
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4947" />
24+
</ItemGroup>
2525

26-
<ItemGroup>
27-
<ProjectReference Include="../Microsoft.PowerShell.OutGridView.Models/Microsoft.PowerShell.OutGridView.Models.csproj" />
28-
</ItemGroup>
26+
<ItemGroup>
27+
<ProjectReference Include="../Microsoft.PowerShell.OutGridView.Models/Microsoft.PowerShell.OutGridView.Models.csproj" />
28+
</ItemGroup>
2929

30-
<ItemGroup>
31-
<None Update="Microsoft.PowerShell.ConsoleGuiTools.psd1" CopyToOutputDirectory="PreserveNewest" />
32-
</ItemGroup>
30+
<ItemGroup>
31+
<None Update="Microsoft.PowerShell.ConsoleGuiTools.psd1" CopyToOutputDirectory="PreserveNewest" />
32+
</ItemGroup>
3333

34-
<PropertyGroup>
35-
<EnableNETAnalyzers>true</EnableNETAnalyzers>
36-
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
37-
<AnalysisMode>Recommended</AnalysisMode>
38-
</PropertyGroup>
34+
<PropertyGroup>
35+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
36+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
37+
<AnalysisMode>Recommended</AnalysisMode>
38+
</PropertyGroup>
3939

40-
<PropertyGroup>
41-
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
42-
</PropertyGroup>
43-
</Project>
40+
<PropertyGroup>
41+
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
42+
</PropertyGroup>
43+
</Project>

0 commit comments

Comments
 (0)