Skip to content

Commit

Permalink
Fixes #2582 - Refactors FileDialog for cleaner data model (#2583)
Browse files Browse the repository at this point in the history
* WIP: Add ITableDataSource

* WIP: Refactor TableView

* WIP: Port CSVEditor

* WIP: Port TableEditor

* WIP: Port MultiColouredTable scenario

* Fix bug of adding duplicate column styles

* Update tests to use DataTableSource

* Tidy up

* Add EnumerableTableDataSource<T>

* Add test for EnumerableTableDataSource

* Add test for EnumerableTableDataSource

* Add code example to xmldoc

* Add ProcessTable scenario

* Rename ITableDataSource to ITableSource and update docs

* Rename EnumerableTableDataSource to EnumerableTableSource

* Fixed Frame != Bounds; changed UICat Scenarios list to use tableview!

* Fix scroll resetting in ProcessTable scenario

* Fix unit tests by setting Frame to same as Bounds

* Document why we have to measure our data for use with TableView

* WIP: Simplify FileDialogs use of TableView

* WIP start migrating sorter

* WIP new filedialog table source mostly working

* WIP remove sorter class

* Refactor GetOrderByValue to be adjacent to GetColumnValue

* Fix collection navigator back so it ignores icon

* Fix unit tests

* Tidy up

* Fix UseColors

* Add test for UseColors

---------

Co-authored-by: Tig Kindel <[email protected]>
  • Loading branch information
tznind and tig authored Apr 29, 2023
1 parent 038cf8a commit 130fc57
Show file tree
Hide file tree
Showing 7 changed files with 397 additions and 428 deletions.
2 changes: 1 addition & 1 deletion Terminal.Gui/FileServices/FileDialogState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public FileDialogState (IDirectoryInfo dir, FileDialog parent)

public IDirectoryInfo Directory { get; }

public FileSystemInfoStats [] Children { get; protected set; }
public FileSystemInfoStats [] Children { get; internal set; }

internal virtual void RefreshChildren ()
{
Expand Down
2 changes: 1 addition & 1 deletion Terminal.Gui/FileServices/FileDialogStyle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class FileDialogStyle {
/// <summary>
/// Gets or sets the culture to use (e.g. for number formatting).
/// Defaults to <see cref="CultureInfo.CurrentUICulture"/>.
/// <summary>
/// </summary>
public CultureInfo Culture {get;set;} = CultureInfo.CurrentUICulture;

/// <summary>
Expand Down
30 changes: 2 additions & 28 deletions Terminal.Gui/FileServices/FileSystemInfoStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public bool IsDir ()

public bool IsImage ()
{
return this.FileSystemInfo is FileSystemInfo f &&
return this.FileSystemInfo is IFileSystemInfo f &&
ImageExtensions.Contains (
f.Extension,
StringComparer.InvariantCultureIgnoreCase);
Expand All @@ -82,38 +82,12 @@ public bool IsImage ()
public bool IsExecutable ()
{
// TODO: handle linux executable status
return this.FileSystemInfo is FileSystemInfo f &&
return this.FileSystemInfo is IFileSystemInfo f &&
ExecutableExtensions.Contains (
f.Extension,
StringComparer.InvariantCultureIgnoreCase);
}

internal object GetOrderByValue (FileDialog dlg, string columnName)
{
if (dlg.Style.FilenameColumnName == columnName)
return this.FileSystemInfo.Name;

if (dlg.Style.SizeColumnName == columnName)
return this.MachineReadableLength;

if (dlg.Style.ModifiedColumnName == columnName)
return this.LastWriteTime;

if (dlg.Style.TypeColumnName == columnName)
return this.Type;

throw new ArgumentOutOfRangeException ("Unknown column " + nameof (columnName));
}

internal object GetOrderByDefault ()
{
if (this.IsDir ()) {
return -1;
}

return 100;
}

private static string GetHumanReadableFileSize (long value, CultureInfo culture)
{

Expand Down
Loading

0 comments on commit 130fc57

Please sign in to comment.