Skip to content

Commit fa17dff

Browse files
committed
Update ListView API usage and improve marking logic
- Replace deprecated ListView properties with ShowMarks/MarkMultiple and update scrollbar config for Terminal.Gui 2.0.0-beta.11. - Add bounds checking to IsMarked; remove Length property in favor of MaxItemLength. - Simplify Enter key handling and ListView.Accepted event logic. - Use Value instead of CheckedState for "All Properties" checkbox. - Update launch profile to use -OutputMode: Single. - Minor: ignore exception variable in TypeGetter.
1 parent 8ee4bc1 commit fa17dff

5 files changed

Lines changed: 20 additions & 26 deletions

File tree

src/Microsoft.PowerShell.ConsoleGuiTools/GridViewDataSource.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ internal sealed class GridViewDataSource : IListDataSource
2525
/// </summary>
2626
public int Count => GridViewRowList.Count;
2727

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

3331
/// <summary>
3432
/// Gets or sets a value indicating whether to suspend raising the <see cref="CollectionChanged" /> event.
@@ -85,7 +83,14 @@ public void Render(ListView listView, bool selected, int item, int col, int line
8583
/// </summary>
8684
/// <param name="item">The index of the item to check.</param>
8785
/// <returns><see langword="true" /> if the item is marked; otherwise, <see langword="false" />.</returns>
88-
public bool IsMarked(int item) => GridViewRowList[item].IsMarked;
86+
public bool IsMarked(int item)
87+
{
88+
if (item < 0 || item >= GridViewRowList.Count)
89+
{
90+
return false;
91+
}
92+
return GridViewRowList[item].IsMarked;
93+
}
8994

9095
/// <summary>
9196
/// Sets the marked state of the specified item and raises the <see cref="MarkChanged" /> event.

src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<!-- Using local Terminal.Gui build for debugging -->
2121
<!--<ProjectReference Include="..\..\..\gui-cs\Terminal.Gui\Terminal.Gui\Terminal.Gui.csproj" />-->
2222
<PackageReference Include="Microsoft.PowerShell.SDK" Version="7.5.4" />
23-
<PackageReference Include="Terminal.Gui" Version="2.0.0-develop.4827" />
23+
<PackageReference Include="Terminal.Gui" Version="2.0.0-beta.11" />
2424
</ItemGroup>
2525

2626
<ItemGroup>

src/Microsoft.PowerShell.ConsoleGuiTools/OutGridViewWindow.cs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -368,17 +368,18 @@ private void AddListView()
368368
Y = _filterErrorView is not null ? Pos.Bottom(_filterErrorView) : 1,
369369
Width = Dim.Fill(),
370370
Height = Dim.Fill(1),
371-
AllowsMarking = _applicationData.OutputMode != OutputModeOption.None,
372-
AllowsMultipleSelection = _applicationData.OutputMode == OutputModeOption.Multiple,
371+
ShowMarks = _applicationData.OutputMode != OutputModeOption.None,
372+
MarkMultiple = _applicationData.OutputMode == OutputModeOption.Multiple,
373373
SelectedItem = 0,
374-
VerticalScrollBar = { AutoShow = true },
375-
HorizontalScrollBar = { AutoShow = true }
374+
ViewportSettings = ViewportSettingsFlags.HasScrollBars
376375
};
377376

378377
_listView.KeyBindings.Remove(Key.A.WithCtrl);
379378

380379
if (!_applicationData.MinUI) AddHeader();
381380

381+
_listView.Accepted += (sender, args) => Accept();
382+
382383
Add(_listView);
383384
return;
384385

@@ -424,19 +425,7 @@ private void AddStatusBar()
424425
if (_applicationData.OutputMode != OutputModeOption.None)
425426
shortcuts.Add(new Shortcut(Key.Enter, "Accept", () =>
426427
{
427-
if (MostFocused == _listView)
428-
{
429-
if (_applicationData.OutputMode == OutputModeOption.Single &&
430-
_inputSource!.GridViewRowList.Find(i => i.IsMarked) == null)
431-
if (_listView!.SelectedItem is not null && _listView.SelectedItem < _listViewSource!.Count)
432-
{
433-
var item = _listViewSource.GridViewRowList[_listView.SelectedItem.Value];
434-
item.IsMarked = !item.IsMarked;
435-
}
436-
437-
Accept();
438-
}
439-
else if (MostFocused == _filterField)
428+
if (MostFocused == _filterField)
440429
{
441430
_listView!.SetFocus();
442431
}
@@ -449,7 +438,7 @@ private void AddStatusBar()
449438
CommandView = new CheckBox
450439
{
451440
Title = "A_ll Properties",
452-
CheckedState = _applicationData.AllProperties ? CheckState.Checked : CheckState.UnChecked,
441+
Value = _applicationData.AllProperties ? CheckState.Checked : CheckState.UnChecked,
453442
CanFocus = false,
454443
MouseHighlightStates = MouseState.None
455444
},

src/Microsoft.PowerShell.ConsoleGuiTools/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"gci | OCGV ": {
3939
"commandName": "Executable",
4040
"executablePath": "C:\\Program Files\\PowerShell\\7-preview\\pwsh.exe",
41-
"commandLineArgs": "-NoProfile -NoLogo -NoExit -Command \"& { Import-Module '$(TargetPath)'; gci | Out-ConsoleGridView}\"",
41+
"commandLineArgs": "-NoProfile -NoLogo -NoExit -Command \"& { Import-Module '$(TargetPath)'; gci | Out-ConsoleGridView -OutputMode: Single}\"",
4242
"workingDirectory": "$(TargetDir)"
4343
},
4444
"OCGV -AllProperties": {

src/Microsoft.PowerShell.ConsoleGuiTools/TypeGetter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ public static DataTableRow CastObjectToDataTableRow(PSObject psObject, List<Data
321321
}
322322
}
323323
}
324-
catch (Exception ex)
324+
catch (Exception _)
325325
{
326326
// If evaluation fails, use null
327327
result = null;

0 commit comments

Comments
 (0)