Skip to content

Commit d21f8c5

Browse files
committed
Merge branch 'fix_121_filter_input' into merge_tig
2 parents 241e3d9 + e544340 commit d21f8c5

File tree

5 files changed

+103
-100
lines changed

5 files changed

+103
-100
lines changed

.vscode/launch.json

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,20 @@
66
"configurations": [
77
{
88
"name": ".NET Core Launch (console)",
9+
"preLaunchTask": "build ConsoleGuiTools",
910
"type": "coreclr",
1011
"request": "launch",
11-
"preLaunchTask": "build",
12-
"program": "${workspaceFolder}/Cmdlet/bin/Debug/net6.0/win10-x64/OutGridViewCmdlet.dll",
13-
"args": [],
14-
"cwd": "${workspaceFolder}/Cmdlet",
15-
"console": "internalConsole",
16-
"stopAtEntry": false
17-
},
18-
{
19-
"name": ".NET Core Launch (application)",
20-
"type": "coreclr",
21-
"request": "launch",
22-
"preLaunchTask": "build",
23-
"program": "${workspaceFolder}/Application/bin/Debug/net6.0/win10-x64/OutGridViewApplication.dll",
24-
"args": [],
25-
"cwd": "${workspaceFolder}/Application",
26-
"console": "internalConsole",
27-
"stopAtEntry": false
12+
"program": "pwsh",
13+
"args": [
14+
"-NoExit",
15+
"-NoProfile",
16+
"-Command",
17+
"Import-Module ${workspaceFolder}/module/Microsoft.PowerShell.ConsoleGuiTools"
18+
],
19+
"cwd": "${workspaceFolder}",
20+
"console": "integratedTerminal",
21+
"stopAtEntry": false,
22+
"justMyCode": false
2823
},
2924
{
3025
"name": ".NET Core Attach",

.vscode/settings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"files.associations": {
3-
"**/.vsts-ci/**/*.yml":"azure-pipelines"
3+
"**/.vsts-ci/**/*.yml":"azure-pipelines",
44
}
55
}

.vscode/tasks.json

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1-
{
1+
// See https://go.microsoft.com/fwlink/?LinkId=733558
2+
// for the documentation about the tasks.json format
3+
{
24
"version": "2.0.0",
35
"tasks": [
46
{
5-
"label": "build",
6-
"osx": {
7-
"command": "/usr/local/bin/pwsh"
8-
},
9-
"windows": {
10-
"command": "pwsh.exe"
11-
},
12-
"linux": {
13-
"command": "/usr/local/bin/pwsh"
14-
},
15-
"type": "process",
7+
"label": "build ConsoleGuiTools",
8+
"command": "Invoke-Build",
9+
"type": "shell",
1610
"args": [
17-
"-c",
18-
"Invoke-Build",
19-
// Build both modules
20-
//"Build -ModuleName Microsoft.PowerShell.GraphicalTools, Microsoft.PowerShell.ConsoleGuiTools",
21-
// Build only Out-GridView
22-
//"Build -ModuleName Microsoft.PowerShell.GraphicalTools",
23-
// Build only Out-ConsoleGridView
24-
"Build -ModuleName Microsoft.PowerShell.ConsoleGuiTools",
11+
"Build",
12+
"-Module",
13+
"Microsoft.PowerShell.ConsoleGuiTools"
2514
],
26-
"problemMatcher": "$msCompile",
27-
"group": {
28-
"kind": "build",
29-
"isDefault": true
30-
}
15+
"group": "build",
16+
"presentation": {
17+
"reveal": "silent"
18+
},
19+
"problemMatcher": "$msCompile"
3120
}
3221
]
3322
}

README.md

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ to view and filter objects graphically.
2525

2626
## Development
2727

28-
### 1. Install PowerShell 7.1+
28+
### 1. Install PowerShell 7.2+
2929

30-
Install PowerShell 7.1+ with [these instructions](https://github.com/PowerShell/PowerShell#get-powershell).
30+
Install PowerShell 7.2+ with [these instructions](https://github.com/PowerShell/PowerShell#get-powershell).
3131

3232
### 2. Clone the GitHub repository
3333

@@ -72,29 +72,15 @@ PS ./GraphicalTools> code .
7272

7373
Build by hitting `Ctrl-Shift-B` in VS Code.
7474

75-
To debug:
75+
Set a breakpoint and hit `F5` to start the debugger.
7676

77-
In a PowerShell session in the `./GraphicalTools` directory, run `pwsh` (thus
78-
nesting PowerShell).
79-
80-
Then do the folowing:
77+
Click on the VS Code "TERMINAL" tab and type your command that starts `Out-ConsoleGridView`, e.g.
8178

8279
```powershell
83-
Import-Module ./module/Microsoft.PowerShell.ConsoleGuiTools
84-
$pid
80+
ls | ocgv
8581
```
8682

87-
This will import the latest built DLL and output the process ID you'll need
88-
for debugging. Copy this ID to the clipboard.
89-
90-
In VScode, set your breakpoints, etc. Then hit `F5`. In the VScode search
91-
box, paste the value printed by `$pid`. You'll see something like `pwsh.exe
92-
18328`. Click that and the debug session will start.
93-
94-
In the PowerShell session run your commands; breakpoints will be hit, etc.
95-
96-
When done, run `exit` to exit the nested PowerShell and run `pwsh` again.
97-
This unloads the DLL. Repeat.
83+
Your breakpoint should be hit.
9884

9985
## Contributions Welcome
10086

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 70 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,10 @@ public HashSet<int> Start(ApplicationData applicationData)
8383
return selectedIndexes;
8484
}
8585

86-
foreach (GridViewRow gvr in _itemSource.GridViewRowList)
86+
// Ensure that only items that are marked AND not filtered out
87+
// get returned (See Issue #121)
88+
List<GridViewRow> itemList = GridViewHelpers.FilterData(_itemSource.GridViewRowList, _filterField.Text.ToString());
89+
foreach (GridViewRow gvr in itemList)
8790
{
8891
if (gvr.IsMarked)
8992
{
@@ -122,7 +125,8 @@ private GridViewDataSource LoadData()
122125
return new GridViewDataSource(items);
123126
}
124127

125-
private void ApplyFilter(){
128+
private void ApplyFilter()
129+
{
126130
List<GridViewRow> itemList = GridViewHelpers.FilterData(_itemSource.GridViewRowList, _applicationData.Filter ?? string.Empty);
127131
// Set the ListView to show only the subset defined by the filter
128132
_listView.Source = new GridViewDataSource(itemList);
@@ -151,50 +155,72 @@ private Window CreateTopLevelWindow()
151155
Width = Dim.Fill(_applicationData.MinUI ? -1 : 0),
152156
Height = Dim.Fill(_applicationData.MinUI ? -1 : 1)
153157
};
154-
155-
if (_applicationData.MinUI) {
158+
159+
if (_applicationData.MinUI)
160+
{
156161
win.Border.BorderStyle = BorderStyle.None;
157-
}
158-
162+
}
163+
159164
Application.Top.Add(win);
160165
return win;
161166
}
162167

163168
private void AddStatusBar(bool visible)
164169
{
165-
var statusBar = new StatusBar(
166-
_applicationData.OutputMode != OutputModeOption.None
167-
? new StatusItem[]
170+
var statusItems = new List<StatusItem>();
171+
if (_applicationData.OutputMode != OutputModeOption.None)
172+
{
173+
// Use Key.Unknown for SPACE with no delegate because ListView already
174+
// handles SPACE
175+
statusItems.Add(new StatusItem(Key.Unknown, "~SPACE~ Select Item", null));
176+
}
177+
178+
if (_applicationData.OutputMode == OutputModeOption.Multiple)
179+
{
180+
statusItems.Add(new StatusItem(Key.A | Key.CtrlMask, "~CTRL-A~ Select All", () =>
181+
{
182+
// This selects only the items that match the Filter
183+
var gvds = _listView.Source as GridViewDataSource;
184+
gvds.GridViewRowList.ForEach(i => i.IsMarked = true);
185+
_listView.SetNeedsDisplay();
186+
}));
187+
188+
// Ctrl-D is commonly used in GUIs for select-none
189+
statusItems.Add(new StatusItem(Key.D | Key.CtrlMask, "~CTRL-D~ Select None", () =>
190+
{
191+
// This un-selects only the items that match the Filter
192+
var gvds = _listView.Source as GridViewDataSource;
193+
gvds.GridViewRowList.ForEach(i => i.IsMarked = false);
194+
_listView.SetNeedsDisplay();
195+
}));
196+
}
197+
198+
if (_applicationData.OutputMode != OutputModeOption.None)
199+
{
200+
statusItems.Add(new StatusItem(Key.Enter, "~ENTER~ Accept", () =>
201+
{
202+
if (Application.Top.MostFocused == _listView)
168203
{
169-
// Use Key.Unknown for SPACE with no delegate because ListView already
170-
// handles SPACE
171-
new StatusItem(Key.Unknown, "~SPACE~ Mark Item", null),
172-
new StatusItem(Key.Enter, "~ENTER~ Accept", () =>
204+
// If nothing was explicitly marked, we return the item that was selected
205+
// when ENTER is pressed in Single mode. If something was previously selected
206+
// (using SPACE) then honor that as the single item to return
207+
if (_applicationData.OutputMode == OutputModeOption.Single &&
208+
_itemSource.GridViewRowList.Find(i => i.IsMarked) == null)
173209
{
174-
if (Application.Top.MostFocused == _listView)
175-
{
176-
// If nothing was explicitly marked, we return the item that was selected
177-
// when ENTER is pressed in Single mode. If something was previously selected
178-
// (using SPACE) then honor that as the single item to return
179-
if (_applicationData.OutputMode == OutputModeOption.Single &&
180-
_itemSource.GridViewRowList.Find(i => i.IsMarked) == null)
181-
{
182-
_listView.MarkUnmarkRow();
183-
}
184-
Accept();
185-
}
186-
else if (Application.Top.MostFocused == _filterField)
187-
{
188-
_listView.SetFocus();
189-
}
190-
}),
191-
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
210+
_listView.MarkUnmarkRow();
211+
}
212+
Accept();
192213
}
193-
: new StatusItem[]
214+
else if (Application.Top.MostFocused == _filterField)
194215
{
195-
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
216+
_listView.SetFocus();
196217
}
197-
);
218+
}));
219+
}
220+
221+
statusItems.Add(new StatusItem(Key.Esc, "~ESC~ Close", () => Close()));
222+
223+
var statusBar = new StatusBar(statusItems.ToArray());
198224
statusBar.Visible = visible;
199225
Application.Top.Add(statusBar);
200226
}
@@ -222,7 +248,6 @@ private void CalculateColumnWidths(List<string> gridHeaders)
222248
{
223249
listViewColumnWidths[index] = len;
224250
}
225-
226251
index++;
227252
}
228253
}
@@ -264,6 +289,13 @@ private void AddFilter(Window win)
264289
Width = Dim.Fill() - _filterLabel.Text.Length
265290
};
266291

292+
// TextField captures Ctrl-A (select all text) and Ctrl-D (delete backwards)
293+
// In OCGV these are used for select-all/none of items. Selecting items is more
294+
// common than editing the filter field so we turn them off in the filter textview.
295+
// BACKSPACE still works for delete backwards
296+
_filterField.ClearKeybinding(Key.A | Key.CtrlMask);
297+
_filterField.ClearKeybinding(Key.D | Key.CtrlMask);
298+
267299
var filterErrorLabel = new Label(string.Empty)
268300
{
269301
X = Pos.Right(_filterLabel) + 1,
@@ -329,7 +361,8 @@ private void AddHeaders(Window win, List<string> gridHeaders)
329361
}
330362
}
331363

332-
if (!_applicationData.MinUI){
364+
if (!_applicationData.MinUI)
365+
{
333366
var headerLine = new Label(headerLineText.ToString())
334367
{
335368
X = 0,
@@ -346,7 +379,7 @@ private void AddListView(Window win)
346379
if (!_applicationData.MinUI)
347380
{
348381
_listView.Y = Pos.Bottom(_filterLabel) + 3; // 1 for space, 1 for header, 1 for header underline
349-
}
382+
}
350383
else
351384
{
352385
_listView.Y = 1; // 1 for space, 1 for header, 1 for header underline

0 commit comments

Comments
 (0)