diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs index c8543b3..8f3ec34 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs @@ -28,7 +28,7 @@ public HashSet 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 }; @@ -69,11 +69,13 @@ public HashSet Start(ApplicationData applicationData) return selectedIndexes; } - private void Accept(){ + private void Accept() + { Application.RequestStop(); } - private void Close(){ + private void Close() + { _cancelled = true; Application.RequestStop(); } @@ -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()) } diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 index 583c3af..9536d0c 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/Microsoft.PowerShell.ConsoleGuiTools.psd1 @@ -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' ) @@ -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 diff --git a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs index 7eaeb59..8d7152e 100644 --- a/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs +++ b/src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs @@ -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. - /// [Cmdlet(VerbsData.Out, "ConsoleGridView")] [Alias("ocgv")] public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable @@ -62,7 +59,7 @@ protected override void BeginProcessing() ErrorCategory.NotImplemented, null); - this.ThrowTerminatingError(error); + ThrowTerminatingError(error); } } @@ -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) @@ -106,7 +102,7 @@ baseObject is PSReference || ErrorCategory.InvalidType, null); - this.ThrowTerminatingError(error); + ThrowTerminatingError(error); } _psObjects.Add(input); @@ -135,7 +131,6 @@ protected override void EndProcessing() var selectedIndexes = _consoleGui.Start(applicationData); - foreach (int idx in selectedIndexes) { var selectedObject = _psObjects[idx]; @@ -143,7 +138,7 @@ protected override void EndProcessing() { continue; } - this.WriteObject(selectedObject, false); + WriteObject(selectedObject, false); } }