Skip to content

Commit 2184386

Browse files
committed
Merge branch 'master' of tig:PowerShell/GraphicalTools
2 parents a2c0238 + 72803b9 commit 2184386

File tree

2 files changed

+38
-37
lines changed

2 files changed

+38
-37
lines changed

src/Microsoft.PowerShell.ConsoleGuiTools/ConsoleGui.cs

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ namespace OutGridView.Cmdlet
1414
internal class ConsoleGui : IDisposable
1515
{
1616
private const string FILTER_LABEL = "Filter";
17-
private const string APPLY_LABEL = "Apply";
1817
private bool _cancelled;
1918
private GridViewDataSource _itemSource;
2019
private ListView _listView;
@@ -27,12 +26,13 @@ public HashSet<int> Start(ApplicationData applicationData)
2726
_applicationData = applicationData;
2827
_gridViewDetails = new GridViewDetails
2928
{
30-
// Have a 8 character addition of a checkbox (" [ ]") that we have to factor in.
31-
ListViewOffset = 8
29+
// If we have an OutputMode, then we want to make them selectable. If we make them selectable,
30+
// they have a 8 character addition of a checkbox (" [ ]") that we have to factor in.
31+
ListViewOffset = _applicationData.OutputMode != OutputModeOption.None ? 8 : 4
3232
};
3333

34-
AddMenu();
3534
Window win = AddTopLevelWindow();
35+
AddStatusBar();
3636

3737
// GridView header logic
3838
List<string> gridHeaders = _applicationData.DataTable.DataColumns.Select((c) => c.Label).ToList();
@@ -44,7 +44,7 @@ public HashSet<int> Start(ApplicationData applicationData)
4444
// GridView row logic
4545
LoadData();
4646
AddRows(win);
47-
47+
4848
// Run the GUI.
4949
Application.Run();
5050

@@ -66,13 +66,22 @@ public HashSet<int> Start(ApplicationData applicationData)
6666
return selectedIndexes;
6767
}
6868

69+
private void Accept(){
70+
Application.RequestStop();
71+
}
72+
73+
private void Close(){
74+
_cancelled = true;
75+
Application.RequestStop();
76+
}
77+
6978
private Window AddTopLevelWindow()
7079
{
7180
// Creates the top-level window to show
7281
var win = new Window(_applicationData.Title)
7382
{
7483
X = 0,
75-
Y = 1, // Leave one row for the toplevel menu
84+
Y = 0,
7685
// By using Dim.Fill(), it will automatically resize without manual intervention
7786
Width = Dim.Fill(),
7887
Height = Dim.Fill()
@@ -82,19 +91,25 @@ private Window AddTopLevelWindow()
8291
return win;
8392
}
8493

85-
private void AddMenu()
94+
private void AddStatusBar()
8695
{
87-
var menu = new MenuBar(new MenuBarItem []
88-
{
89-
new MenuBarItem("_Actions (F9)",
90-
new MenuItem []
96+
var statusBar = new StatusBar(
97+
_applicationData.OutputMode != OutputModeOption.None
98+
? new StatusItem []
99+
{
100+
// Use Key.Unknown for SPACE with no delegate because ListView already
101+
// handles SPACE
102+
new StatusItem(Key.Unknown, "~SPACE~ Mark Item", null),
103+
new StatusItem(Key.Enter, "~ENTER~ Accept", () => Accept()),
104+
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
105+
}
106+
: new StatusItem []
91107
{
92-
new MenuItem("_Accept", string.Empty, () => { Application.RequestStop(); }),
93-
new MenuItem("_Cancel", string.Empty, () =>{ _cancelled = true; Application.RequestStop(); })
94-
})
95-
});
108+
new StatusItem(Key.Esc, "~ESC~ Close", () => Close())
109+
}
110+
);
96111

97-
Application.Top.Add(menu);
112+
Application.Top.Add(statusBar);
98113
}
99114

100115
private void CalculateColumnWidths(List<string> gridHeaders)
@@ -120,7 +135,7 @@ private void CalculateColumnWidths(List<string> gridHeaders)
120135
{
121136
listViewColumnWidths[index] = len;
122137
}
123-
138+
124139
index++;
125140
}
126141
}
@@ -154,28 +169,25 @@ private void AddFilter(Window win)
154169
X = 2
155170
};
156171

157-
// 1 is for space between filterField and applyButton
158-
// 2 is for the square brackets added to buttons
159-
var filterLabelAndApplyButtonWidth = filterLabel.Text.Length + 1 + APPLY_LABEL.Length;
172+
var filterLabelWidth = filterLabel.Text.Length + 1;
160173
var filterField = new TextField(string.Empty)
161174
{
162175
X = Pos.Right(filterLabel) + 1,
163176
Y = Pos.Top(filterLabel),
164177
CanFocus = true,
165-
Width = Dim.Fill() - filterLabelAndApplyButtonWidth
178+
Width = Dim.Fill() - filterLabelWidth
166179
};
167180

168181
var filterErrorLabel = new Label(string.Empty)
169182
{
170183
X = Pos.Right(filterLabel) + 1,
171184
Y = Pos.Top(filterLabel) + 1,
172185
ColorScheme = Colors.Base,
173-
Width = Dim.Fill() - filterLabelAndApplyButtonWidth
186+
Width = Dim.Fill() - filterLabelWidth
174187
};
175188

176189
EventHandler<ustring> filterChanged = (object sender, ustring e) =>
177190
{
178-
// TODO: remove Apply button and code when this starts working
179191
try
180192
{
181193
filterErrorLabel.Text = " ";
@@ -196,18 +208,7 @@ private void AddFilter(Window win)
196208

197209
filterField.Changed += filterChanged;
198210

199-
var filterApplyButton = new Button(APPLY_LABEL)
200-
{
201-
// Pos.Right(filterField) returns 0
202-
X = Pos.Right(filterField) + 1,
203-
Y = Pos.Top(filterLabel),
204-
Clicked = () =>
205-
{
206-
filterChanged.Invoke(null, filterField.Text);
207-
}
208-
};
209-
210-
win.Add(filterLabel, filterField, filterErrorLabel, filterApplyButton);
211+
win.Add(filterLabel, filterField, filterErrorLabel);
211212
}
212213

213214
private void AddHeaders(Window win, List<string> gridHeaders)
@@ -283,7 +284,7 @@ private void AddRows(Window win)
283284
Y = 4,
284285
Width = Dim.Fill(2),
285286
Height = Dim.Fill(2),
286-
AllowsMarking = true
287+
AllowsMarking = _applicationData.OutputMode != OutputModeOption.None,
287288
};
288289

289290
win.Add(_listView);

src/Microsoft.PowerShell.ConsoleGuiTools/OutConsoleGridviewCmdletCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class OutConsoleGridViewCmdletCommand : PSCmdlet, IDisposable
4747
/// and if it should be possible to select multiple or single list items.
4848
/// </summary>
4949
[Parameter()]
50-
public OutputModeOption OutputMode { set; get; }
50+
public OutputModeOption OutputMode { set; get; } = OutputModeOption.Multiple;
5151

5252
#endregion Input Parameters
5353

0 commit comments

Comments
 (0)