mirror of
https://github.com/gui-cs/Terminal.Gui.git
synced 2025-12-26 15:57:56 +01:00
Fixes bug related with allowed type files filter in FileDialog.
This commit is contained in:
@@ -749,7 +749,7 @@ namespace Terminal.Gui {
|
||||
}
|
||||
|
||||
SetValue (searchset [listview.SelectedItem]);
|
||||
search.CursorPosition = search.Text.RuneCount;
|
||||
search.CursorPosition = search.Text.ConsoleWidth;
|
||||
Search_Changed (search.Text);
|
||||
OnOpenSelectedItem ();
|
||||
Reset (keepSearchText: true);
|
||||
@@ -825,7 +825,12 @@ namespace Terminal.Gui {
|
||||
}
|
||||
}
|
||||
|
||||
ShowList ();
|
||||
if (HasFocus) {
|
||||
ShowList ();
|
||||
} else if (autoHide) {
|
||||
isShow = false;
|
||||
HideList ();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -656,12 +656,17 @@ namespace Terminal.Gui {
|
||||
X = Pos.Right (nameEntry) + 2,
|
||||
Y = Pos.Top (nameEntry),
|
||||
Width = Dim.Fill (1),
|
||||
Height = allowedTypes != null ? allowedTypes.Count + 1 : 1,
|
||||
Height = SetComboBoxHeight (allowedTypes),
|
||||
Text = allowedTypes?.Count > 0 ? allowedTypes [0] : string.Empty,
|
||||
ReadOnly = true
|
||||
SelectedItem = allowedTypes?.Count > 0 ? 0 : -1,
|
||||
ReadOnly = true,
|
||||
HideDropdownListOnClick = true
|
||||
};
|
||||
cmbAllowedTypes.SetSource (allowedTypes ?? new List<string> ());
|
||||
cmbAllowedTypes.OpenSelectedItem += (e) => AllowedFileTypes = cmbAllowedTypes.Text.ToString ().Split (';');
|
||||
cmbAllowedTypes.OpenSelectedItem += (e) => {
|
||||
dirListView.AllowedFileTypes = cmbAllowedTypes.Text.ToString ().Split (';');
|
||||
dirListView.Reload ();
|
||||
};
|
||||
Add (cmbAllowedTypes);
|
||||
|
||||
dirListView = new DirListView (this) {
|
||||
@@ -673,7 +678,7 @@ namespace Terminal.Gui {
|
||||
DirectoryPath = Path.GetFullPath (Environment.CurrentDirectory);
|
||||
Add (dirListView);
|
||||
|
||||
AllowedFileTypes = cmbAllowedTypes.Text.ToString ().Split (';');
|
||||
AllowedFileTypes = allowedTypes?.Count > 0 ? allowedTypes?.ToArray () : null;
|
||||
dirListView.DirectoryChanged = (dir) => { nameEntry.Text = ustring.Empty; dirEntry.Text = dir; };
|
||||
dirListView.FileChanged = (file) => nameEntry.Text = file == ".." ? "" : file;
|
||||
dirListView.SelectedChanged = (file) => nameEntry.Text = file.Item1 == ".." ? "" : file.Item1;
|
||||
@@ -738,6 +743,11 @@ namespace Terminal.Gui {
|
||||
}
|
||||
}
|
||||
|
||||
private static int SetComboBoxHeight (List<string> allowedTypes)
|
||||
{
|
||||
return allowedTypes != null ? Math.Min (allowedTypes.Count + 1, 8) : 8;
|
||||
}
|
||||
|
||||
internal bool canceled;
|
||||
|
||||
///<inheritdoc/>
|
||||
@@ -821,13 +831,22 @@ namespace Terminal.Gui {
|
||||
}
|
||||
}
|
||||
|
||||
private string [] allowedFileTypes;
|
||||
|
||||
/// <summary>
|
||||
/// The array of filename extensions allowed, or null if all file extensions are allowed.
|
||||
/// </summary>
|
||||
/// <value>The allowed file types.</value>
|
||||
public string [] AllowedFileTypes {
|
||||
get => dirListView.AllowedFileTypes;
|
||||
set => dirListView.AllowedFileTypes = value;
|
||||
get => allowedFileTypes;
|
||||
set {
|
||||
allowedFileTypes = value;
|
||||
var selected = cmbAllowedTypes.SelectedItem;
|
||||
cmbAllowedTypes.SetSource (value);
|
||||
cmbAllowedTypes.SelectedItem = selected > -1 ? selected : 0;
|
||||
SetComboBoxHeight (value?.ToList ());
|
||||
dirListView.AllowedFileTypes = value [cmbAllowedTypes.SelectedItem].Split (';');
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -385,8 +385,9 @@ namespace UICatalog.Scenarios {
|
||||
|
||||
private void Open ()
|
||||
{
|
||||
var ofd = new FileDialog ("Select File", "Open", "File", "Select a CSV file to open (does not support newlines, escaping etc)");
|
||||
ofd.AllowedFileTypes = new string [] { ".csv" };
|
||||
var ofd = new FileDialog ("Select File", "Open", "File", "Select a CSV file to open (does not support newlines, escaping etc)") {
|
||||
AllowedFileTypes = new string [] { ".csv" }
|
||||
};
|
||||
|
||||
Application.Run (ofd);
|
||||
|
||||
|
||||
@@ -365,7 +365,7 @@ namespace UICatalog.Scenarios {
|
||||
if (!CanCloseFile ()) {
|
||||
return;
|
||||
}
|
||||
var aTypes = new List<string> () { ".txt;.bin;.xml;.json", ".txt", ".bin", ".xml", ".*" };
|
||||
var aTypes = new List<string> () { ".txt;.bin;.xml;.json", ".txt", ".bin", ".xml", ".json", ".*" };
|
||||
var d = new OpenDialog ("Open", "Choose the path where to open the file.", aTypes) { AllowsMultipleSelection = false };
|
||||
Application.Run (d);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user