Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public HashSet<int> Start(ApplicationData applicationData)
_gridViewDetails = new GridViewDetails
{
// If OutputMode is Single or Multiple, then we make items selectable. If we make them selectable,
// they have a 8 character addition of a checkbox (" [ ]" or ".....( )")
// they have a 8 character addition of a checkbox (".....[ ]" or ".....( )")
// that we have to factor in.
ListViewOffset = _applicationData.OutputMode != OutputModeOption.None ? 8 : 4
};
Expand Down Expand Up @@ -69,11 +69,13 @@ public HashSet<int> Start(ApplicationData applicationData)
return selectedIndexes;
}

private void Accept(){
private void Accept()
{
Application.RequestStop();
}

private void Close(){
private void Close()
{
_cancelled = true;
Application.RequestStop();
}
Expand All @@ -98,29 +100,33 @@ private void AddStatusBar()
{
var statusBar = new StatusBar(
_applicationData.OutputMode != OutputModeOption.None
? new StatusItem []
? new StatusItem[]
{
// Use Key.Unknown for SPACE with no delegate because ListView already
// handles SPACE
new StatusItem(Key.Unknown, "~SPACE~ Mark Item", null),
new StatusItem(Key.Enter, "~ENTER~ Accept", () => {
if (Application.Top.MostFocused == _listView){
new StatusItem(Key.Enter, "~ENTER~ Accept", () =>
{
if (Application.Top.MostFocused == _listView)
{
// If nothing was explicitly marked, we return the item that was selected
// when ENTER is pressed in Single mode. If something was previously selected
// (using SPACE) then honor that as the single item to return
if (_applicationData.OutputMode == OutputModeOption.Single &&
_itemSource.GridViewRowList.Find(i => i.IsMarked) == null) {
_itemSource.GridViewRowList.Find(i => i.IsMarked) == null)
{
_listView.MarkUnmarkRow();
}
Accept();
}
else if (Application.Top.MostFocused == _filterField){
else if (Application.Top.MostFocused == _filterField)
{
_listView.SetFocus();
}
}),
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
}
: new StatusItem []
: new StatusItem[]
{
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
RootModule = 'Microsoft.PowerShell.ConsoleGuiTools.dll'

# Version number of this module.
ModuleVersion = '0.4.1'
ModuleVersion = '0.5.0'

# Supported PSEditions
CompatiblePSEditions = @( 'Core' )
Expand Down Expand Up @@ -106,6 +106,15 @@ PrivateData = @{
# ReleaseNotes of this module
ReleaseNotes = '# Release Notes

## v0.5.0

`Out-ConsoleGridView` has been totally refactored!

First off, no more silly F9 menu to accept!
All you have to do is hit `ENTER` to accept your selection or `ESC` to cancel.

Also, `-OutputMode` works as expected now. `Single` lets you only select one item. `Multiple` is the default.

## v0.4.1

* Fix filter indexing to return correct selected objects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
using System.Management.Automation;
using System.Management.Automation.Internal;
using OutGridView.Models;
using System.Runtime.InteropServices;

namespace OutGridView.Cmdlet
{
/// Enum for SelectionMode parameter.
/// </summary>
[Cmdlet(VerbsData.Out, "ConsoleGridView")]
[Alias("ocgv")]
public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable
Expand Down Expand Up @@ -62,7 +59,7 @@ protected override void BeginProcessing()
ErrorCategory.NotImplemented,
null);

this.ThrowTerminatingError(error);
ThrowTerminatingError(error);
}
}

Expand All @@ -74,8 +71,7 @@ protected override void ProcessRecord()
return;
}

IDictionary dictionary = InputObject.BaseObject as IDictionary;
if (dictionary != null)
if (InputObject.BaseObject is IDictionary dictionary)
{
// Dictionaries should be enumerated through because the pipeline does not enumerate through them.
foreach (DictionaryEntry entry in dictionary)
Expand Down Expand Up @@ -106,7 +102,7 @@ baseObject is PSReference ||
ErrorCategory.InvalidType,
null);

this.ThrowTerminatingError(error);
ThrowTerminatingError(error);
}

_psObjects.Add(input);
Expand Down Expand Up @@ -135,15 +131,14 @@ protected override void EndProcessing()


var selectedIndexes = _consoleGui.Start(applicationData);

foreach (int idx in selectedIndexes)
{
var selectedObject = _psObjects[idx];
if (selectedObject == null)
{
continue;
}
this.WriteObject(selectedObject, false);
WriteObject(selectedObject, false);
}
}

Expand Down