mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
* Partial fix - probably breaks stuff Refactored `FileDialog.cs` by replacing `treeViewContainer` with `_treeView`, adjusting UI component positions, and adding style properties to `_tableView`. Improved user interaction with new event handlers and key bindings. Rearranged `base.Add` calls to reflect the updated UI hierarchy. * Tweaked Dialog and FileDialog attribute handling Removed setting of _tableView.Style.InvertSelectedCellFirstCharacter = true; Commented out custom attribute handling in Dialog.cs for VisualRole.Normal and VisualRole.Focus, reverting to base method. Removed InvertSelectedCellFirstCharacter setting in FileDialog.cs. * Add tree view toggle to FileDialog Introduced a new `_btnTreeToggle` button in `FileDialog.cs` to manage the visibility of a tree view within the file dialog interface. Added a new localized string `fdTree` in `Strings.Designer.cs` and `Strings.resx` for UI elements related to the tree view. Adjusted the layout and visibility of the tree and table views to accommodate the toggle functionality. Implemented methods `ToggleTreeVisibility`, `SetTreeVisible`, and `GetTreeToggleText` to handle tree view visibility logic. Cleaned up code and comments for clarity. * Update localization and test logic for FileDialog Updated `fdSearchCaption` localization from "Enter search string" to "Find" in `Strings.Designer.cs` and `Strings.resx`. Modified `FileDialogFluentTests.cs` to reflect UI changes by updating button text and removing skip conditions. Adjusted `FileDialogTests.cs` to change `TextField` caption and commented out certain test logic related to path confirmation. * Moved Search view to be inside the table view container for better usability. Refactor FileDialog to use nullable reference types Updated the `FileDialog` class to adopt nullable reference types for improved null safety, marking fields, properties, and methods as nullable where appropriate. Simplified UI component initialization, including repositioning `_tbFind` and `_spinnerView` into `_tableViewContainer` and assigning `Id` properties to `_tableViewContainer` and `_tableView`. Refactored methods like `TryAcceptMulti` and `GetFocusedFiles` to handle nullability. Simplified `Task.Run` calls and removed unused code, such as the `GetTextField` method and `FileDialogPart` enum, in `FileDialogTests.cs`. Updated tests to directly access subviews using `Id` properties. Minor layout and property adjustments were made to improve maintainability. * Refactor Dialog class and improve null safety - Enabled nullable reference types in `Dialog.cs` for better null safety. - Removed and reintroduced static configuration properties with `[ConfigurationProperty]` attributes for configurability. - Refactored `Dialog` constructor to use `base.ShadowStyle` and improved button management with alignment logic. - Updated `Canceled` property with a private backing field and debug assertions. - Added null-forgiving operators (`!`) across the codebase for nullable reference type compatibility. - Introduced new test cases to verify `Dialog` behavior, including modal mouse capture and `Canceled` property access. - Refactored and modernized existing test cases for consistency and readability. - Removed redundant test cases and performed general code cleanup. - Improved code comments and debug assertions for clarity and robustness. * Refactor DialogTests to replace null with empty array Updated the `BeginButtonTestDialog` method call in `DialogTests.cs` to replace the `null!` argument with an empty array `[]`. This improves type safety and ensures explicit handling of the argument.
This commit is contained in:
@@ -74,7 +74,7 @@ public class FileDialogFluentTests
|
||||
using var c = With.A (() => NewSaveDialog (out sd,modal:false), 100, 20, d)
|
||||
.ScreenShot ("Save dialog", _out)
|
||||
.Focus<Button> (b => b.Text == "_Cancel")
|
||||
.AssertTrue (sd.Canceled)
|
||||
.AssertTrue (sd!.Canceled)
|
||||
.Enter ()
|
||||
.Stop ();
|
||||
}
|
||||
@@ -88,7 +88,7 @@ public class FileDialogFluentTests
|
||||
.ScreenShot ("Save dialog", _out)
|
||||
.LeftClick<Button> (b => b.Text == "_Cancel")
|
||||
.WriteOutLogs (_out)
|
||||
.AssertTrue (sd.Canceled)
|
||||
.AssertTrue (sd!.Canceled)
|
||||
.Stop ();
|
||||
}
|
||||
[Theory]
|
||||
@@ -100,7 +100,7 @@ public class FileDialogFluentTests
|
||||
.ScreenShot ("Save dialog", _out)
|
||||
.Send (Key.C.WithAlt)
|
||||
.WriteOutLogs (_out)
|
||||
.AssertTrue (sd.Canceled)
|
||||
.AssertTrue (sd!.Canceled)
|
||||
.Stop ();
|
||||
}
|
||||
|
||||
@@ -115,8 +115,8 @@ public class FileDialogFluentTests
|
||||
.LeftClick<Button> (b => b.Text == "_Save")
|
||||
.WaitIteration ()
|
||||
.WriteOutLogs (_out)
|
||||
.AssertFalse(sd.Canceled)
|
||||
.AssertEqual (GetFileSystemRoot (fs), sd.FileName)
|
||||
.AssertFalse(sd!.Canceled)
|
||||
.AssertEqual (GetFileSystemRoot (fs!), sd!.FileName)
|
||||
.Stop ();
|
||||
}
|
||||
|
||||
@@ -130,8 +130,8 @@ public class FileDialogFluentTests
|
||||
.ScreenShot ("Save dialog", _out)
|
||||
.Send (Key.S.WithAlt)
|
||||
.WriteOutLogs (_out)
|
||||
.AssertFalse (sd.Canceled)
|
||||
.AssertEqual (GetFileSystemRoot (fs), sd.FileName)
|
||||
.AssertFalse (sd!.Canceled)
|
||||
.AssertEqual (GetFileSystemRoot (fs!), sd!.FileName)
|
||||
.Stop ();
|
||||
|
||||
}
|
||||
@@ -147,8 +147,8 @@ public class FileDialogFluentTests
|
||||
.Focus<Button> (b => b.Text == "_Save")
|
||||
.Enter ()
|
||||
.WriteOutLogs (_out)
|
||||
.AssertFalse(sd.Canceled)
|
||||
.AssertEqual (GetFileSystemRoot(fs), sd.FileName)
|
||||
.AssertFalse(sd!.Canceled)
|
||||
.AssertEqual (GetFileSystemRoot(fs!), sd!.FileName)
|
||||
.Stop ();
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ public class FileDialogFluentTests
|
||||
"/";
|
||||
}
|
||||
|
||||
[Theory (Skip = "New splitter design removes expand button.")]
|
||||
[Theory]
|
||||
[ClassData (typeof (TestDrivers))]
|
||||
public void SaveFileDialog_PressingPopTree_ShouldNotChangeCancel (TestDriver d)
|
||||
{
|
||||
@@ -167,17 +167,17 @@ public class FileDialogFluentTests
|
||||
MockFileSystem? fs = null;
|
||||
using var c = With.A (() => NewSaveDialog (out sd, out fs,modal:false), 100, 20, d)
|
||||
.ScreenShot ("Save dialog", _out)
|
||||
.AssertTrue (sd.Canceled)
|
||||
.Focus<Button> (b => b.Text == "►►")
|
||||
.AssertTrue (sd!.Canceled)
|
||||
.Focus<Button> (b => b.Text == "►_Tree")
|
||||
.Enter ()
|
||||
.ScreenShot ("After pop tree", _out)
|
||||
.WriteOutLogs (_out)
|
||||
.AssertTrue (sd.Canceled)
|
||||
.AssertTrue (sd!.Canceled)
|
||||
.Stop ();
|
||||
|
||||
}
|
||||
|
||||
[Theory (Skip = "New splitter design removes expand button.")]
|
||||
[Theory]
|
||||
[ClassData (typeof (TestDrivers))]
|
||||
public void SaveFileDialog_PopTree_AndNavigate (TestDriver d)
|
||||
{
|
||||
@@ -185,8 +185,8 @@ public class FileDialogFluentTests
|
||||
MockFileSystem? fs = null;
|
||||
using var c = With.A (() => NewSaveDialog (out sd, out fs, modal: false), 100, 20, d)
|
||||
.ScreenShot ("Save dialog", _out)
|
||||
.AssertTrue (sd.Canceled)
|
||||
.LeftClick<Button> (b => b.Text == "►►")
|
||||
.AssertTrue (sd!.Canceled)
|
||||
.LeftClick<Button> (b => b.Text == "►_Tree")
|
||||
.ScreenShot ("After pop tree", _out)
|
||||
.Focus<TreeView<IFileSystemInfo>> (_ => true)
|
||||
.Right ()
|
||||
@@ -195,8 +195,8 @@ public class FileDialogFluentTests
|
||||
.ScreenShot ("After navigate down in tree", _out)
|
||||
.Enter ()
|
||||
.WaitIteration ()
|
||||
.AssertFalse (sd.Canceled)
|
||||
.AssertContains ("empty-dir", sd.FileName)
|
||||
.AssertFalse (sd!.Canceled)
|
||||
.AssertContains ("empty-dir", sd!.FileName)
|
||||
.WriteOutLogs (_out)
|
||||
.Stop ();
|
||||
}
|
||||
@@ -208,13 +208,13 @@ public class FileDialogFluentTests
|
||||
SaveDialog? sd = null;
|
||||
MockFileSystem? fs = null;
|
||||
using var c = With.A (() => NewSaveDialog (out sd, out fs, modal: false), 100, 20, d)
|
||||
.Then (()=>sd.Style.PreserveFilenameOnDirectoryChanges=true)
|
||||
.Then (()=>sd!.Style.PreserveFilenameOnDirectoryChanges=true)
|
||||
.ScreenShot ("Save dialog", _out)
|
||||
.AssertTrue (sd.Canceled)
|
||||
.AssertTrue (sd!.Canceled)
|
||||
.Focus<TextField> (_=>true)
|
||||
// Clear selection by pressing right in 'file path' text box
|
||||
.RaiseKeyDownEvent (Key.CursorRight)
|
||||
.AssertIsType <TextField>(sd.Focused)
|
||||
.AssertIsType <TextField>(sd!.Focused)
|
||||
// Type a filename into the dialog
|
||||
.RaiseKeyDownEvent (Key.H)
|
||||
.RaiseKeyDownEvent (Key.E)
|
||||
@@ -223,23 +223,23 @@ public class FileDialogFluentTests
|
||||
.RaiseKeyDownEvent (Key.O)
|
||||
.WaitIteration ()
|
||||
.ScreenShot ("After typing filename 'hello'", _out)
|
||||
.AssertEndsWith ("hello", sd.Path)
|
||||
//.LeftClick<Button> (b => b.Text == "►►")
|
||||
//.ScreenShot ("After pop tree", _out)
|
||||
.AssertEndsWith ("hello", sd!.Path)
|
||||
.LeftClick<Button> (b => b.Text == "►_Tree")
|
||||
.ScreenShot ("After pop tree", _out)
|
||||
.Focus<TreeView<IFileSystemInfo>> (_ => true)
|
||||
.Right ()
|
||||
.ScreenShot ("After expand tree", _out)
|
||||
// Because of PreserveFilenameOnDirectoryChanges we should select the new dir but keep the filename
|
||||
.AssertEndsWith ("hello", sd.Path)
|
||||
.AssertEndsWith ("hello", sd!.Path)
|
||||
.Down ()
|
||||
.ScreenShot ("After navigate down in tree", _out)
|
||||
// Because of PreserveFilenameOnDirectoryChanges we should select the new dir but keep the filename
|
||||
.AssertContains ("empty-dir",sd.Path)
|
||||
.AssertEndsWith ("hello", sd.Path)
|
||||
.AssertContains ("empty-dir",sd!.Path)
|
||||
.AssertEndsWith ("hello", sd!.Path)
|
||||
.Enter ()
|
||||
.WaitIteration ()
|
||||
.AssertFalse (sd.Canceled)
|
||||
.AssertContains ("empty-dir", sd.FileName)
|
||||
.AssertFalse (sd!.Canceled)
|
||||
.AssertContains ("empty-dir", sd!.FileName)
|
||||
.WriteOutLogs (_out)
|
||||
.Stop ();
|
||||
}
|
||||
@@ -251,13 +251,13 @@ public class FileDialogFluentTests
|
||||
SaveDialog? sd = null;
|
||||
MockFileSystem? fs = null;
|
||||
using var c = With.A (() => NewSaveDialog (out sd, out fs, modal: false), 100, 20, d)
|
||||
.Then (()=> sd.Style.PreserveFilenameOnDirectoryChanges = false)
|
||||
.Then (()=> sd!.Style.PreserveFilenameOnDirectoryChanges = false)
|
||||
.ScreenShot ("Save dialog", _out)
|
||||
.AssertTrue (sd.Canceled)
|
||||
.AssertTrue (sd!.Canceled)
|
||||
.Focus<TextField> (_ => true)
|
||||
// Clear selection by pressing right in 'file path' text box
|
||||
.RaiseKeyDownEvent (Key.CursorRight)
|
||||
.AssertIsType<TextField> (sd.Focused)
|
||||
.AssertIsType<TextField> (sd!.Focused)
|
||||
// Type a filename into the dialog
|
||||
.RaiseKeyDownEvent (Key.H)
|
||||
.RaiseKeyDownEvent (Key.E)
|
||||
@@ -266,21 +266,21 @@ public class FileDialogFluentTests
|
||||
.RaiseKeyDownEvent (Key.O)
|
||||
.WaitIteration ()
|
||||
.ScreenShot ("After typing filename 'hello'", _out)
|
||||
.AssertEndsWith ("hello", sd.Path)
|
||||
//.LeftClick<Button> (b => b.Text == "►►")
|
||||
//.ScreenShot ("After pop tree", _out)
|
||||
.AssertEndsWith ("hello", sd!.Path)
|
||||
.LeftClick<Button> (b => b.Text == "►_Tree")
|
||||
.ScreenShot ("After pop tree", _out)
|
||||
.Focus<TreeView<IFileSystemInfo>> (_ => true)
|
||||
.Right ()
|
||||
.ScreenShot ("After expand tree", _out)
|
||||
.Down ()
|
||||
.ScreenShot ("After navigate down in tree", _out)
|
||||
// PreserveFilenameOnDirectoryChanges is false so just select new path
|
||||
.AssertEndsWith ("empty-dir", sd.Path)
|
||||
.AssertDoesNotContain ("hello", sd.Path)
|
||||
.AssertEndsWith ("empty-dir", sd!.Path)
|
||||
.AssertDoesNotContain ("hello", sd!.Path)
|
||||
.Enter ()
|
||||
.WaitIteration ()
|
||||
.AssertFalse (sd.Canceled)
|
||||
.AssertContains ("empty-dir", sd.FileName)
|
||||
.AssertFalse (sd!.Canceled)
|
||||
.AssertContains ("empty-dir", sd!.FileName)
|
||||
.WriteOutLogs (_out)
|
||||
.Stop ();
|
||||
}
|
||||
@@ -292,13 +292,13 @@ public class FileDialogFluentTests
|
||||
SaveDialog? sd = null;
|
||||
MockFileSystem? fs = null;
|
||||
using var c = With.A (() => NewSaveDialog (out sd, out fs, modal: false), 100, 20, d)
|
||||
.Then (() => sd.Style.PreserveFilenameOnDirectoryChanges = preserve)
|
||||
.Then (() => sd!.Style.PreserveFilenameOnDirectoryChanges = preserve)
|
||||
.ScreenShot ("Save dialog", _out)
|
||||
.AssertTrue (sd.Canceled)
|
||||
.AssertTrue (sd!.Canceled)
|
||||
.Focus<TextField> (_ => true)
|
||||
// Clear selection by pressing right in 'file path' text box
|
||||
.RaiseKeyDownEvent (Key.CursorRight)
|
||||
.AssertIsType<TextField> (sd.Focused)
|
||||
.AssertIsType<TextField> (sd!.Focused)
|
||||
// Type a filename into the dialog
|
||||
.RaiseKeyDownEvent (Key.H)
|
||||
.RaiseKeyDownEvent (Key.E)
|
||||
@@ -307,7 +307,7 @@ public class FileDialogFluentTests
|
||||
.RaiseKeyDownEvent (Key.O)
|
||||
.WaitIteration ()
|
||||
.ScreenShot ("After typing filename 'hello'", _out)
|
||||
.AssertEndsWith ("hello", sd.Path)
|
||||
.AssertEndsWith ("hello", sd!.Path)
|
||||
.Focus<TableView> (_ => true)
|
||||
.ScreenShot ("After focus table", _out)
|
||||
.Down ()
|
||||
@@ -315,13 +315,13 @@ public class FileDialogFluentTests
|
||||
|
||||
if (preserve)
|
||||
{
|
||||
c.AssertContains ("logs", sd.Path)
|
||||
.AssertEndsWith ("hello", sd.Path);
|
||||
c.AssertContains ("logs", sd!.Path)
|
||||
.AssertEndsWith ("hello", sd!.Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.AssertContains ("logs", sd.Path)
|
||||
.AssertDoesNotContain ("hello", sd.Path);
|
||||
c.AssertContains ("logs", sd!.Path)
|
||||
.AssertDoesNotContain ("hello", sd!.Path);
|
||||
}
|
||||
|
||||
c.Up ()
|
||||
@@ -329,13 +329,13 @@ public class FileDialogFluentTests
|
||||
|
||||
if (preserve)
|
||||
{
|
||||
c.AssertContains ("empty-dir", sd.Path)
|
||||
.AssertEndsWith ("hello", sd.Path);
|
||||
c.AssertContains ("empty-dir", sd!.Path)
|
||||
.AssertEndsWith ("hello", sd!.Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.AssertContains ("empty-dir", sd.Path)
|
||||
.AssertDoesNotContain ("hello", sd.Path);
|
||||
c.AssertContains ("empty-dir", sd!.Path)
|
||||
.AssertDoesNotContain ("hello", sd!.Path);
|
||||
}
|
||||
|
||||
c.Enter ()
|
||||
@@ -344,28 +344,28 @@ public class FileDialogFluentTests
|
||||
|
||||
if (preserve)
|
||||
{
|
||||
c.AssertContains ("empty-dir", sd.Path)
|
||||
.AssertEndsWith ("hello", sd.Path);
|
||||
c.AssertContains ("empty-dir", sd!.Path)
|
||||
.AssertEndsWith ("hello", sd!.Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.AssertContains ("empty-dir", sd.Path)
|
||||
.AssertDoesNotContain ("hello", sd.Path);
|
||||
c.AssertContains ("empty-dir", sd!.Path)
|
||||
.AssertDoesNotContain ("hello", sd!.Path);
|
||||
}
|
||||
|
||||
c.LeftClick<Button> (b => b.Text == "_Save");
|
||||
c.WaitIteration ();
|
||||
c.AssertFalse (sd.Canceled);
|
||||
c.AssertFalse (sd!.Canceled);
|
||||
|
||||
if (preserve)
|
||||
{
|
||||
c.AssertContains ("empty-dir", sd.Path)
|
||||
.AssertEndsWith ("hello", sd.Path);
|
||||
c.AssertContains ("empty-dir", sd!.Path)
|
||||
.AssertEndsWith ("hello", sd!.Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
c.AssertContains ("empty-dir", sd.Path)
|
||||
.AssertDoesNotContain ("hello", sd.Path);
|
||||
c.AssertContains ("empty-dir", sd!.Path)
|
||||
.AssertDoesNotContain ("hello", sd!.Path);
|
||||
}
|
||||
|
||||
c.WriteOutLogs (_out);
|
||||
|
||||
Reference in New Issue
Block a user