Skip to content

Commit 53b1203

Browse files
committed
Merge branch 'master' of tig:PowerShell/GraphicalTools into master
2 parents 4175dc0 + c43c923 commit 53b1203

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

Build.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Invoke-Build Build
2-
pwsh -noprofile -command "Import-Module '$PSScriptRoot/module/Microsoft.PowerShell.GraphicalTools'; Get-Process | Out-GridView -PassThru"
2+
pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.GraphicalTools'; Get-Process | Out-GridView -PassThru"
3+
pwsh -noprofile -command "Import-Module -verbose '$PSScriptRoot/module/Microsoft.PowerShell.ConsoleGuiTools'; Get-Process | Out-ConsoleGridView -OutputMode Single"

docs/Microsoft.PowerShell.ConsoleGuiTools/Out-ConsoleGridView.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ $parameters = @{
127127
LongDescription = 'Show History using Out-ConsoleGridView'
128128
ScriptBlock = {
129129
param($key, $arg) # The arguments are ignored in this example
130-
$history = Get-History -Count 100 | Out-ConsoleGridView -Title "Select Command" -OutputMode Single
130+
$history = Get-History -Count 100 | Sort-Object -Property Id -Descending | Out-ConsoleGridView -Title "Select Command" -OutputMode Single
131131
if (-Not [string]::IsNullOrWhiteSpace($history)){
132132
[Microsoft.PowerShell.PSConsoleReadLine]::Insert($history)
133133
}

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ public HashSet<int> Start(ApplicationData applicationData)
2727
_applicationData = applicationData;
2828
_gridViewDetails = new GridViewDetails
2929
{
30-
// If we have an OutputMode, then we want to make them selectable. If we make them selectable,
31-
// they have a 8 character addition of a checkbox (" [ ]") that we have to factor in.
30+
// If OutputMode is Single or Multiple, then we make items selectable. If we make them selectable,
31+
// they have a 8 character addition of a checkbox (".....[ ]" or ".....( )")
32+
// that we have to factor in.
3233
ListViewOffset = _applicationData.OutputMode != OutputModeOption.None ? 8 : 4
3334
};
3435

@@ -68,11 +69,13 @@ public HashSet<int> Start(ApplicationData applicationData)
6869
return selectedIndexes;
6970
}
7071

71-
private void Accept(){
72+
private void Accept()
73+
{
7274
Application.RequestStop();
7375
}
7476

75-
private void Close(){
77+
private void Close()
78+
{
7679
_cancelled = true;
7780
Application.RequestStop();
7881
}
@@ -97,22 +100,33 @@ private void AddStatusBar()
97100
{
98101
var statusBar = new StatusBar(
99102
_applicationData.OutputMode != OutputModeOption.None
100-
? new StatusItem []
103+
? new StatusItem[]
101104
{
102105
// Use Key.Unknown for SPACE with no delegate because ListView already
103106
// handles SPACE
104107
new StatusItem(Key.Unknown, "~SPACE~ Mark Item", null),
105-
new StatusItem(Key.Enter, "~ENTER~ Accept", () => {
106-
if (Application.Top.MostFocused == _listView){
108+
new StatusItem(Key.Enter, "~ENTER~ Accept", () =>
109+
{
110+
if (Application.Top.MostFocused == _listView)
111+
{
112+
// If nothing was explicitly marked, we return the item that was selected
113+
// when ENTER is pressed in Single mode. If something was previously selected
114+
// (using SPACE) then honor that as the single item to return
115+
if (_applicationData.OutputMode == OutputModeOption.Single &&
116+
_itemSource.GridViewRowList.Find(i => i.IsMarked) == null)
117+
{
118+
_listView.MarkUnmarkRow();
119+
}
107120
Accept();
108121
}
109-
else if (Application.Top.MostFocused == _filterField){
122+
else if (Application.Top.MostFocused == _filterField)
123+
{
110124
_listView.SetFocus();
111125
}
112126
}),
113127
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
114128
}
115-
: new StatusItem []
129+
: new StatusItem[]
116130
{
117131
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
118132
}
@@ -293,6 +307,7 @@ private void AddRows(Window win)
293307
Width = Dim.Fill(2),
294308
Height = Dim.Fill(2),
295309
AllowsMarking = _applicationData.OutputMode != OutputModeOption.None,
310+
AllowsMultipleSelection = _applicationData.OutputMode == OutputModeOption.Multiple,
296311
};
297312

298313
win.Add(_listView);

src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
RootModule = 'Microsoft.PowerShell.ConsoleGuiTools.dll'
1010

1111
# Version number of this module.
12-
ModuleVersion = '0.4.1'
12+
ModuleVersion = '0.5.0'
1313

1414
# Supported PSEditions
1515
CompatiblePSEditions = @( 'Core' )
@@ -106,6 +106,15 @@ PrivateData = @{
106106
# ReleaseNotes of this module
107107
ReleaseNotes = '# Release Notes
108108
109+
## v0.5.0
110+
111+
`Out-ConsoleGridView` has been totally refactored!
112+
113+
First off, no more silly F9 menu to accept!
114+
All you have to do is hit `ENTER` to accept your selection or `ESC` to cancel.
115+
116+
Also, `-OutputMode` works as expected now. `Single` lets you only select one item. `Multiple` is the default.
117+
109118
## v0.4.1
110119
111120
* Fix filter indexing to return correct selected objects

src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,9 @@
77
using System.Management.Automation;
88
using System.Management.Automation.Internal;
99
using OutGridView.Models;
10-
using System.Runtime.InteropServices;
1110

1211
namespace OutGridView.Cmdlet
1312
{
14-
/// Enum for SelectionMode parameter.
15-
/// </summary>
1613
[Cmdlet(VerbsData.Out, "ConsoleGridView")]
1714
[Alias("ocgv")]
1815
public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable
@@ -62,7 +59,7 @@ protected override void BeginProcessing()
6259
ErrorCategory.NotImplemented,
6360
null);
6461

65-
this.ThrowTerminatingError(error);
62+
ThrowTerminatingError(error);
6663
}
6764
}
6865

@@ -74,8 +71,7 @@ protected override void ProcessRecord()
7471
return;
7572
}
7673

77-
IDictionary dictionary = InputObject.BaseObject as IDictionary;
78-
if (dictionary != null)
74+
if (InputObject.BaseObject is IDictionary dictionary)
7975
{
8076
// Dictionaries should be enumerated through because the pipeline does not enumerate through them.
8177
foreach (DictionaryEntry entry in dictionary)
@@ -106,7 +102,7 @@ baseObject is PSReference ||
106102
ErrorCategory.InvalidType,
107103
null);
108104

109-
this.ThrowTerminatingError(error);
105+
ThrowTerminatingError(error);
110106
}
111107

112108
_psObjects.Add(input);
@@ -135,15 +131,14 @@ protected override void EndProcessing()
135131

136132

137133
var selectedIndexes = _consoleGui.Start(applicationData);
138-
139134
foreach (int idx in selectedIndexes)
140135
{
141136
var selectedObject = _psObjects[idx];
142137
if (selectedObject == null)
143138
{
144139
continue;
145140
}
146-
this.WriteObject(selectedObject, false);
141+
WriteObject(selectedObject, false);
147142
}
148143
}
149144

0 commit comments

Comments
 (0)