Skip to content

Commit 8d3d039

Browse files
authored
Fixes #4022 file dialog tests and bugfix for cancellation (#4024)
* Add class for detecting information about console in extensible way * WIP - Create test for reordering * Change Dictionary to List and preserve TreeBuilder order * Add test to ensure branch expansion/status remains consistent despite reorder * Cleanup code * Fix regression when removed child was the selected one * Revert "Add class for detecting information about console in extensible way" This reverts commit 7e4253c. * Code cleanup and enable nullable on Branch * Remove color scheme and driver from Branch draw * Add xunit context extensions * Investigate codegen for xunit * Getting closer to something that works * Fix code generation * Further explore code gen * Generate all methods in single class for easier extensibility * Simplify code gen by moving parameter creation to its own method * Implement asserts A-I * Add remaining assert calls that are not obsolete * Fix unit test * Roll back versions to be compatible with CI version of csharp * Handle params and ref etc * Fix null warning * WIP - start to add integration tests for FileDialog * Add ability to tab focus to specific control with simple one line delegate * Clarify test criteria * Add unit tests for Ok and other ways of canceling dialog * Fix other buttons also triggering save * Fix for linux environment tests * Fix for linux again * Fix application null race condition - add better way of knowing if stuff is finished * Better fix for shutdown detection * Add test that shows #4026 is not an issue * Switch to `_fileSystem.Directory.GetLogicalDrives ()` * Don't show duplicate MyDocuments etc
1 parent e02d576 commit 8d3d039

File tree

14 files changed

+946
-101
lines changed

14 files changed

+946
-101
lines changed

Directory.Packages.props

Lines changed: 43 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,45 @@
11
<Project>
2-
<PropertyGroup>
3-
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4-
</PropertyGroup>
5-
<ItemGroup>
6-
<!-- Enable Nuget Source Link for github -->
7-
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="[8,9)" />
8-
9-
<PackageVersion Include="ColorHelper" Version="[1.8.1,2)" />
10-
<PackageVersion Include="JetBrains.Annotations" Version="[2024.3.0,)" />
11-
<PackageVersion Include="Microsoft.CodeAnalysis" Version="[4.13,5)" />
12-
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="[4.13,5)" />
13-
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="[4.13,5)" />
14-
<PackageVersion Include="Microsoft.Extensions.Logging" Version="[9.0.2,10)" />
15-
<PackageVersion Include="System.IO.Abstractions" Version="[22.0.11,23)" />
16-
<PackageVersion Include="System.Text.Json" Version="[8.0.5,9)" />
17-
<PackageVersion Include="Wcwidth" Version="[2,3)" />
18-
19-
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="[1.21.2,2)" />
20-
<PackageVersion Include="Serilog" Version="4.2.0" />
21-
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.0" />
22-
<PackageVersion Include="Serilog.Sinks.Debug" Version="3.0.0" />
23-
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
24-
<PackageVersion Include="SixLabors.ImageSharp" Version="[3.1.7,4)" />
25-
<PackageVersion Include="CsvHelper" Version="[33.0.1,34)" />
26-
<PackageVersion Include="Microsoft.DotNet.PlatformAbstractions" Version="[3.1.6,4)" />
27-
<PackageVersion Include="System.CommandLine" Version="[2.0.0-beta4.22272.1,3)" />
28-
29-
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
30-
31-
<PackageVersion Include="CommunityToolkit.Mvvm" Version="[8.4.0,9)" />
32-
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="[9.0.2,10)" />
33-
<PackageVersion Include="ReactiveUI" Version="[20.1.63,21)" />
34-
<PackageVersion Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="[1.3.1,2)" />
35-
<PackageVersion Include="ReactiveUI.SourceGenerators" Version="[2.1.8,3)"/>
36-
37-
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="[17.13,18)" />
38-
<PackageVersion Include="Moq" Version="[4.20.72,5)" />
39-
<PackageVersion Include="ReportGenerator" Version="[5.4.4,6)" />
40-
<PackageVersion Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="[22.0.11,23)" />
41-
<PackageVersion Include="xunit" Version="[2.9.3,3)" />
42-
<PackageVersion Include="Xunit.Combinatorial" Version="[1.6.24,2)" />
43-
<PackageVersion Include="xunit.runner.visualstudio" Version="[2.8.2,3)"/>
44-
<PackageVersion Include="coverlet.collector" Version="[6.0.4,7)" />
45-
46-
</ItemGroup>
47-
48-
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
49-
<PackageVersion Include="Terminal.Gui" Version="2.0.0" />
50-
</ItemGroup>
51-
2+
<PropertyGroup>
3+
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<!-- Enable Nuget Source Link for github -->
7+
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0" />
8+
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="[8,9)" />
9+
<PackageVersion Include="ColorHelper" Version="[1.8.1,2)" />
10+
<PackageVersion Include="JetBrains.Annotations" Version="[2024.3.0,)" />
11+
<PackageVersion Include="Microsoft.CodeAnalysis" Version="[4.11,4.12)" />
12+
<PackageVersion Include="Microsoft.CodeAnalysis.Common" Version="[4.11,4.12)" />
13+
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.11.0" />
14+
<PackageVersion Include="Microsoft.Extensions.Logging" Version="[9.0.2,10)" />
15+
<PackageVersion Include="System.IO.Abstractions" Version="[22.0.11,23)" />
16+
<PackageVersion Include="System.Text.Json" Version="[8.0.5,9)" />
17+
<PackageVersion Include="Wcwidth" Version="[2,3)" />
18+
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="[1.21.2,2)" />
19+
<PackageVersion Include="Serilog" Version="4.2.0" />
20+
<PackageVersion Include="Serilog.Extensions.Logging" Version="9.0.0" />
21+
<PackageVersion Include="Serilog.Sinks.Debug" Version="3.0.0" />
22+
<PackageVersion Include="Serilog.Sinks.File" Version="6.0.0" />
23+
<PackageVersion Include="SixLabors.ImageSharp" Version="[3.1.7,4)" />
24+
<PackageVersion Include="CsvHelper" Version="[33.0.1,34)" />
25+
<PackageVersion Include="Microsoft.DotNet.PlatformAbstractions" Version="[3.1.6,4)" />
26+
<PackageVersion Include="System.CommandLine" Version="[2.0.0-beta4.22272.1,3)" />
27+
<PackageVersion Include="BenchmarkDotNet" Version="0.14.0" />
28+
<PackageVersion Include="CommunityToolkit.Mvvm" Version="[8.4.0,9)" />
29+
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="[9.0.2,10)" />
30+
<PackageVersion Include="ReactiveUI" Version="[20.1.63,21)" />
31+
<PackageVersion Include="ReactiveMarbles.ObservableEvents.SourceGenerator" Version="[1.3.1,2)" />
32+
<PackageVersion Include="ReactiveUI.SourceGenerators" Version="[2.1.8,3)" />
33+
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="[17.13,18)" />
34+
<PackageVersion Include="Moq" Version="[4.20.72,5)" />
35+
<PackageVersion Include="ReportGenerator" Version="[5.4.4,6)" />
36+
<PackageVersion Include="TestableIO.System.IO.Abstractions.TestingHelpers" Version="[22.0.11,23)" />
37+
<PackageVersion Include="xunit" Version="[2.9.3,3)" />
38+
<PackageVersion Include="Xunit.Combinatorial" Version="[1.6.24,2)" />
39+
<PackageVersion Include="xunit.runner.visualstudio" Version="[2.8.2,3)" />
40+
<PackageVersion Include="coverlet.collector" Version="[6.0.4,7)" />
41+
</ItemGroup>
42+
<ItemGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
43+
<PackageVersion Include="Terminal.Gui" Version="2.0.0" />
44+
</ItemGroup>
5245
</Project>

Terminal.Gui/FileServices/FileDialogStyle.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,14 +151,11 @@ private Dictionary<IDirectoryInfo, string> DefaultTreeRootGetter ()
151151

152152
try
153153
{
154-
foreach (string d in GetLogicalDrives ())
154+
foreach (string d in _fileSystem.Directory.GetLogicalDrives ())
155155
{
156156
IDirectoryInfo dir = _fileSystem.DirectoryInfo.New (d);
157157

158-
if (!roots.ContainsKey (dir))
159-
{
160-
roots.Add (dir, d);
161-
}
158+
roots.TryAdd (dir, d);
162159
}
163160
}
164161
catch (Exception)
@@ -181,7 +178,7 @@ private Dictionary<IDirectoryInfo, string> DefaultTreeRootGetter ()
181178

182179
IDirectoryInfo dir = _fileSystem.DirectoryInfo.New (path);
183180

184-
if (!roots.ContainsKey (dir) && dir.Exists)
181+
if (!roots.ContainsKey (dir) && !roots.ContainsValue (special.ToString ()) && dir.Exists)
185182
{
186183
roots.Add (dir, special.ToString ());
187184
}

Terminal.Gui/Views/FileDialog.cs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ internal FileDialog (IFileSystem fileSystem)
103103
return;
104104
}
105105

106+
e.Cancel = true;
107+
106108
if (Modal)
107109
{
108110
Application.RequestStop ();
@@ -111,15 +113,27 @@ internal FileDialog (IFileSystem fileSystem)
111113

112114
_btnUp = new() { X = 0, Y = 1, NoPadding = true };
113115
_btnUp.Text = GetUpButtonText ();
114-
_btnUp.Accepting += (s, e) => _history.Up ();
116+
_btnUp.Accepting += (s, e) =>
117+
{
118+
_history.Up ();
119+
e.Cancel = true;
120+
};
115121

116122
_btnBack = new() { X = Pos.Right (_btnUp) + 1, Y = 1, NoPadding = true };
117123
_btnBack.Text = GetBackButtonText ();
118-
_btnBack.Accepting += (s, e) => _history.Back ();
124+
_btnBack.Accepting += (s, e) =>
125+
{
126+
_history.Back ();
127+
e.Cancel = true;
128+
};
119129

120130
_btnForward = new() { X = Pos.Right (_btnBack) + 1, Y = 1, NoPadding = true };
121131
_btnForward.Text = GetForwardButtonText ();
122-
_btnForward.Accepting += (s, e) => _history.Forward ();
132+
_btnForward.Accepting += (s, e) =>
133+
{
134+
_history.Forward();
135+
e.Cancel = true;
136+
};
123137

124138
_tbPath = new() { Width = Dim.Fill (), CaptionColor = new (Color.Black) };
125139

@@ -199,6 +213,8 @@ internal FileDialog (IFileSystem fileSystem)
199213

200214
_btnToggleSplitterCollapse.Accepting += (s, e) =>
201215
{
216+
// Required otherwise the Save button clicks itself
217+
e.Cancel = true;
202218
Tile tile = _splitContainer.Tiles.ElementAt (0);
203219

204220
bool newState = !tile.ContentView.Visible;
@@ -490,7 +506,7 @@ public override void OnLoaded ()
490506
// if no path has been provided
491507
if (_tbPath.Text.Length <= 0)
492508
{
493-
Path = Environment.CurrentDirectory;
509+
Path = _fileSystem.Directory.GetCurrentDirectory ();
494510
}
495511

496512
// to streamline user experience and allow direct typing of paths
@@ -1288,7 +1304,7 @@ private IDirectoryInfo StringToDirectoryInfo (string path)
12881304
// really not what most users would expect
12891305
if (Regex.IsMatch (path, "^\\w:$"))
12901306
{
1291-
return _fileSystem.DirectoryInfo.New (path + System.IO.Path.DirectorySeparatorChar);
1307+
return _fileSystem.DirectoryInfo.New (path + _fileSystem.Path.DirectorySeparatorChar);
12921308
}
12931309

12941310
return _fileSystem.DirectoryInfo.New (path);

Terminal.Gui/Views/SaveDialog.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// * Use a line separator to show the file listing, so we can use same colors as the rest
1010
// * DirListView: Add mouse support
1111

12+
using System.IO.Abstractions;
1213
using Terminal.Gui.Resources;
1314

1415
namespace Terminal.Gui;
@@ -24,8 +25,15 @@ namespace Terminal.Gui;
2425
public class SaveDialog : FileDialog
2526
{
2627
/// <summary>Initializes a new <see cref="SaveDialog"/>.</summary>
27-
public SaveDialog () { Style.OkButtonText = Strings.btnSave; }
28+
public SaveDialog ()
29+
{
30+
Style.OkButtonText = Strings.btnSave;
31+
}
2832

33+
internal SaveDialog (IFileSystem fileSystem) : base (fileSystem)
34+
{
35+
Style.OkButtonText = Strings.btnSave;
36+
}
2937
/// <summary>
3038
/// Gets the name of the file the user selected for saving, or null if the user canceled the
3139
/// <see cref="SaveDialog"/>.

Terminal.sln

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests.Parallelizable",
6565
EndProject
6666
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerminalGuiFluentTesting", "TerminalGuiFluentTesting\TerminalGuiFluentTesting.csproj", "{2DBA7BDC-17AE-474B-A507-00807D087607}"
6767
EndProject
68-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerminalGuiFluentTesting.Xunit", "TerminalGuiFluentTesting.Xunit\TerminalGuiFluentTesting.Xunit.csproj", "{231B9723-10F3-46DB-8EAE-50C0C0375AD3}"
68+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerminalGuiFluentTestingXunit", "TerminalGuiFluentTestingXunit\TerminalGuiFluentTestingXunit.csproj", "{F56BAFFD-F227-4B0A-96F0-C800FAEF2036}"
69+
EndProject
70+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TerminalGuiFluentTestingXunit.Generator", "TerminalGuiFluentTestingXunit.Generator\TerminalGuiFluentTestingXunit.Generator.csproj", "{199F27D8-A905-4DDC-82CA-1FE1A90B1788}"
6971
EndProject
7072
Global
7173
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -125,10 +127,14 @@ Global
125127
{2DBA7BDC-17AE-474B-A507-00807D087607}.Debug|Any CPU.Build.0 = Debug|Any CPU
126128
{2DBA7BDC-17AE-474B-A507-00807D087607}.Release|Any CPU.ActiveCfg = Release|Any CPU
127129
{2DBA7BDC-17AE-474B-A507-00807D087607}.Release|Any CPU.Build.0 = Release|Any CPU
128-
{231B9723-10F3-46DB-8EAE-50C0C0375AD3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
129-
{231B9723-10F3-46DB-8EAE-50C0C0375AD3}.Debug|Any CPU.Build.0 = Debug|Any CPU
130-
{231B9723-10F3-46DB-8EAE-50C0C0375AD3}.Release|Any CPU.ActiveCfg = Release|Any CPU
131-
{231B9723-10F3-46DB-8EAE-50C0C0375AD3}.Release|Any CPU.Build.0 = Release|Any CPU
130+
{F56BAFFD-F227-4B0A-96F0-C800FAEF2036}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
131+
{F56BAFFD-F227-4B0A-96F0-C800FAEF2036}.Debug|Any CPU.Build.0 = Debug|Any CPU
132+
{F56BAFFD-F227-4B0A-96F0-C800FAEF2036}.Release|Any CPU.ActiveCfg = Release|Any CPU
133+
{F56BAFFD-F227-4B0A-96F0-C800FAEF2036}.Release|Any CPU.Build.0 = Release|Any CPU
134+
{199F27D8-A905-4DDC-82CA-1FE1A90B1788}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
135+
{199F27D8-A905-4DDC-82CA-1FE1A90B1788}.Debug|Any CPU.Build.0 = Debug|Any CPU
136+
{199F27D8-A905-4DDC-82CA-1FE1A90B1788}.Release|Any CPU.ActiveCfg = Release|Any CPU
137+
{199F27D8-A905-4DDC-82CA-1FE1A90B1788}.Release|Any CPU.Build.0 = Release|Any CPU
132138
EndGlobalSection
133139
GlobalSection(SolutionProperties) = preSolution
134140
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)