FileDialog2 improvements

- Expose table/tree style properties
- Rename Monochrome to UseColors and default to false
- IconGetter no longer forces space
- On Windows in Scenario just use a backslash for folder icon (i.e. not unicode)
-
This commit is contained in:
tznind
2023-03-17 21:37:37 +00:00
parent 2512c21018
commit be4e3ab5ff
2 changed files with 31 additions and 12 deletions

View File

@@ -35,6 +35,16 @@ namespace Terminal.Gui {
public string FileMustExistFeedback { get; internal set; } = Strings.fdFileMustExistFeedback;
public string DirectoryAlreadyExistsFeedback { get; internal set; } = Strings.fdDirectoryAlreadyExistsFeedback;
public string FileOrDirectoryMustExistFeedback { get; internal set; } = Strings.fdFileOrDirectoryMustExistFeedback;
/// <summary>
/// Gets the style settings for the table of files (in currently selected directory).
/// </summary>
public TableView.TableStyle TableStyle { get; internal set; }
/// <summary>
/// Gets the style settings for the collapse-able directory/places tree
/// </summary>
public TreeStyle TreeStyle { get; internal set; }
}
/// <summary>
@@ -199,6 +209,7 @@ namespace Terminal.Gui {
FullRowSelect = true,
};
this.tableView.AddKeyBinding (Key.Space, Command.ToggleChecked);
Style.TableStyle = tableView.Style;
this.tableView.KeyPress += (k) => {
if (this.tableView.SelectedRow <= 0) {
this.NavigateIf (k, Key.CursorUp, this.tbPath);
@@ -224,7 +235,7 @@ namespace Terminal.Gui {
this.treeView.TreeBuilder = new FileDialogTreeBuilder ();
this.treeView.AspectGetter = (m) => m is DirectoryInfo d ? d.Name : m.ToString ();
this.Style.TreeStyle = treeView.Style;
try {
this.treeView.AddObjects (
@@ -512,9 +523,10 @@ namespace Terminal.Gui {
/// <summary>
/// Gets or Sets a value indicating whether different colors
/// should be used for different file types/directories.
/// should be used for different file types/directories. Defaults
/// to false.
/// </summary>
public bool Monochrome { get; set; }
public bool UseColors { get; set; }
/// <summary>
/// Gets or Sets a collection of file types that the user can/must select. Only applies
@@ -940,7 +952,7 @@ namespace Terminal.Gui {
var icon = stats.IsParent ? null : IconGetter?.Invoke (stats.FileSystemInfo);
if (icon != null) {
return icon + " " + stats.Name;
return icon + stats.Name;
}
return stats.Name;
};
@@ -1155,7 +1167,7 @@ namespace Terminal.Gui {
{
var stats = this.RowToStats (args.RowIndex);
if (Monochrome) {
if (!UseColors) {
return ColorSchemeDefault;
}

View File

@@ -2,6 +2,7 @@
using System.Collections;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using Terminal.Gui;
using Terminal.Gui.Graphs;
using static Terminal.Gui.OpenDialog;
@@ -12,7 +13,7 @@ namespace UICatalog.Scenarios {
public class FileDialog2Examples : Scenario {
private CheckBox cbMustExist;
private CheckBox cbIcons;
private CheckBox cbMonochrome;
private CheckBox cbUseColors;
private CheckBox cbCaseSensitive;
private CheckBox cbAllowMultipleSelection;
@@ -32,8 +33,8 @@ namespace UICatalog.Scenarios {
cbIcons = new CheckBox ("Icons") { Checked = true, Y = y++, X=x };
Win.Add (cbIcons);
cbMonochrome = new CheckBox ("Monochrome") { Checked = false, Y = y++, X=x};
Win.Add (cbMonochrome);
cbUseColors = new CheckBox ("Use Colors") { Checked = false, Y = y++, X=x};
Win.Add (cbUseColors);
cbCaseSensitive = new CheckBox ("Case Sensitive Search") { Checked = false, Y = y++, X=x };
Win.Add (cbCaseSensitive);
@@ -114,7 +115,7 @@ namespace UICatalog.Scenarios {
fd.SearchMatcher = new CaseSensitiveSearchMatcher ();
}
fd.Monochrome = cbMonochrome.Checked ?? false;
fd.UseColors = cbUseColors.Checked ?? false;
if (rgAllowedTypes.SelectedItem > 0) {
fd.AllowedTypes.Add (new FileDialog2.AllowedType ("Data File", ".csv", ".tsv"));
@@ -159,11 +160,17 @@ namespace UICatalog.Scenarios {
private string GetIcon (FileSystemInfo arg)
{
if (arg is DirectoryInfo) {
return "\ua909";
// Typically most windows terminals will not have these unicode characters installed
// so for the demo lets not bother having any icons on windows
if (RuntimeInformation.IsOSPlatform (OSPlatform.Windows)) {
return arg is DirectoryInfo ? "\\" : null;
}
return "\u2630";
if (arg is DirectoryInfo) {
return "\ua909 ";
}
return "\u2630 ";
}
}
}